tests: add test for adaptor

I noticed AdaptInfo missing test cases. I think this
func a bit important to test since we use this func
in other packages like content, store (walking), etc.

Signed-off-by: Furkan Turkal <furkan.turkal@trendyol.com>
Signed-off-by: Furkan <furkan.turkal@trendyol.com>
This commit is contained in:
Furkan 2021-05-04 22:43:45 +03:00
parent 8c906ff108
commit 7d70992d33
No known key found for this signature in database
GPG Key ID: C26B5EA6BB8709D8

89
content/adaptor_test.go Normal file
View File

@ -0,0 +1,89 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package content
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAdaptInfo(t *testing.T) {
tests := []struct {
name string
info Info
fieldpath []string
wantValue string
wantPresent bool
}{
{
"empty fieldpath",
Info{},
[]string{},
"",
false,
},
{
"digest fieldpath",
Info{
Digest: "foo",
},
[]string{"digest"},
"foo",
true,
},
{
"size fieldpath",
Info{},
[]string{"size"},
"",
false,
},
{
"labels fieldpath",
Info{
Labels: map[string]string{
"foo": "bar",
},
},
[]string{"labels", "foo"},
"bar",
true,
},
{
"labels join fieldpath",
Info{
Labels: map[string]string{
"foo.bar.qux": "quux",
},
},
[]string{"labels", "foo", "bar", "qux"},
"quux",
true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
adaptInfo := AdaptInfo(tt.info)
value, present := adaptInfo.Field(tt.fieldpath)
assert.Equal(t, tt.wantValue, value)
assert.Equal(t, tt.wantPresent, present)
})
}
}