Add some unit tests for pkg/labels/labels.go (#7358)

This PR is about adding some unit tests for pkg/labels/labels.go.

Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
This commit is contained in:
Hu Shuai 2020-06-08 15:46:21 +08:00 committed by GitHub
parent e963d953ea
commit e5ffa8c9a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -544,3 +544,71 @@ func TestLabels_WithoutLabels(t *testing.T) {
func TestLabels_FromStrings(t *testing.T) {
testutil.Equals(t, Labels{{"aaa", "111"}, {"bbb", "222"}}, FromStrings("aaa", "111", "bbb", "222"))
}
func TestBulider_NewBulider(t *testing.T) {
testutil.Equals(
t,
&Builder{
base: Labels{{"aaa", "111"}},
del: []string{},
add: []Label{},
},
NewBuilder(Labels{{"aaa", "111"}}),
)
}
func TestBuilder_Del(t *testing.T) {
testutil.Equals(
t,
&Builder{
del: []string{"bbb"},
add: []Label{{"aaa", "111"}, {"ccc", "333"}},
},
(&Builder{
del: []string{},
add: []Label{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}},
}).Del("bbb"),
)
}
func TestBuilder_Set(t *testing.T) {
testutil.Equals(
t,
&Builder{
base: Labels{{"aaa", "111"}},
del: []string{},
add: []Label{{"bbb", "222"}},
},
(&Builder{
base: Labels{{"aaa", "111"}},
del: []string{},
add: []Label{},
}).Set("bbb", "222"),
)
testutil.Equals(
t,
&Builder{
base: Labels{{"aaa", "111"}},
del: []string{},
add: []Label{{"bbb", "333"}},
},
(&Builder{
base: Labels{{"aaa", "111"}},
del: []string{},
add: []Label{{"bbb", "222"}},
}).Set("bbb", "333"),
)
}
func TestBuilder_Labels(t *testing.T) {
testutil.Equals(
t,
Labels{{"aaa", "111"}, {"ccc", "333"}, {"ddd", "444"}},
(&Builder{
base: Labels{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}},
del: []string{"bbb"},
add: []Label{{"ddd", "444"}},
}).Labels(),
)
}