Skip to content

Commit 7d70992

Browse files
committed
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 <[email protected]> Signed-off-by: Furkan <[email protected]>
1 parent 8c906ff commit 7d70992

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

content/adaptor_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package content
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestAdaptInfo(t *testing.T) {
26+
tests := []struct {
27+
name string
28+
info Info
29+
fieldpath []string
30+
wantValue string
31+
wantPresent bool
32+
}{
33+
{
34+
"empty fieldpath",
35+
Info{},
36+
[]string{},
37+
"",
38+
false,
39+
},
40+
{
41+
"digest fieldpath",
42+
Info{
43+
Digest: "foo",
44+
},
45+
[]string{"digest"},
46+
"foo",
47+
true,
48+
},
49+
{
50+
"size fieldpath",
51+
Info{},
52+
[]string{"size"},
53+
"",
54+
false,
55+
},
56+
{
57+
"labels fieldpath",
58+
Info{
59+
Labels: map[string]string{
60+
"foo": "bar",
61+
},
62+
},
63+
[]string{"labels", "foo"},
64+
"bar",
65+
true,
66+
},
67+
{
68+
"labels join fieldpath",
69+
Info{
70+
Labels: map[string]string{
71+
"foo.bar.qux": "quux",
72+
},
73+
},
74+
[]string{"labels", "foo", "bar", "qux"},
75+
"quux",
76+
true,
77+
},
78+
}
79+
for _, tt := range tests {
80+
t.Run(tt.name, func(t *testing.T) {
81+
adaptInfo := AdaptInfo(tt.info)
82+
83+
value, present := adaptInfo.Field(tt.fieldpath)
84+
85+
assert.Equal(t, tt.wantValue, value)
86+
assert.Equal(t, tt.wantPresent, present)
87+
})
88+
}
89+
}

0 commit comments

Comments
 (0)