image/label: print more characters of label keys
Like stargz and nydus remote snapshotter, some snapshots lables are introduced and passed to snapshotter from containerd automatically. The label keys' length are all longer than 10. The limitation of 10 characters makes it harder to debug what label is not appropriate. So we'd better to print more of the wrong label. Signed-off-by: Changwei Ge <gechangwei@bytedance.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestValidLabels(t *testing.T) {
|
||||
@@ -51,3 +52,29 @@ func TestInvalidLabels(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLongKey(t *testing.T) {
|
||||
key := strings.Repeat("s", keyMaxLen+1)
|
||||
value := strings.Repeat("v", maxSize-len(key))
|
||||
|
||||
err := Validate(key, value)
|
||||
assert.Equal(t, err, nil)
|
||||
|
||||
key = strings.Repeat("s", keyMaxLen+12)
|
||||
value = strings.Repeat("v", maxSize-len(key)+1)
|
||||
|
||||
err = Validate(key, value)
|
||||
assert.ErrorIs(t, err, errdefs.ErrInvalidArgument)
|
||||
|
||||
key = strings.Repeat("s", keyMaxLen-1)
|
||||
value = strings.Repeat("v", maxSize-len(key))
|
||||
|
||||
err = Validate(key, value)
|
||||
assert.Equal(t, err, nil)
|
||||
|
||||
key = strings.Repeat("s", keyMaxLen-1)
|
||||
value = strings.Repeat("v", maxSize-len(key)-1)
|
||||
|
||||
err = Validate(key, value)
|
||||
assert.Equal(t, err, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user