Skip to content

Commit

Permalink
tests: add tests for new label functions
Browse files Browse the repository at this point in the history
Signed-off-by: Manik Rana <[email protected]>
  • Loading branch information
Maniktherana committed Jul 10, 2024
1 parent 3aedffa commit 909ef55
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions model/labels/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,3 +889,45 @@ func TestMarshaling(t *testing.T) {
require.NoError(t, err)
require.Equal(t, f, gotFY)
}

func TestExtractNames(t *testing.T) {
tests := []struct {
name string
labels Labels
expected []string
}{
{"Empty slice empty labels", Labels{}, []string{}},
{"Single label", Labels{{"hi", "Value1"}}, []string{"hi"}},
{"Multiple labels", Labels{{"hi", "Value1"}, {"yoyoy", "Value2"}, {"xxxx", "Value3"}}, []string{"hi", "yoyoy", "xxxx"}},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.labels.ExtractNames()
require.Equal(t, tt.expected, got)
})
}
}

func TestContains(t *testing.T) {
tests := []struct {
name string
labels Labels
names []string
expected bool
}{
{"Empty slice", Labels{}, []string{"hi"}, false},
{"Empty slice Empty Labels", Labels{}, []string{}, false},
{"Empty slice non-Labels", Labels{{"hi", "Value1"}, {"yoyoy", "Value2"}}, []string{}, false},
{"Single match", Labels{{"hi", "Value1"}}, []string{"hi"}, true},
{"Multiple matches", Labels{{"hi", "Value1"}, {"yoyoy", "Value2"}, {"xxxx", "Value3"}}, []string{"hi", "bye"}, true},
{"No match", Labels{{"hi", "Value1"}, {"yoyoy", "Value2"}, {"xxxx", "Value3"}}, []string{"bye"}, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.labels.Contains(tt.names...)
require.Equal(t, tt.expected, got)
})
}
}

0 comments on commit 909ef55

Please sign in to comment.