mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Add unit test for StringSet Equal
This commit is contained in:
parent
924350d5f6
commit
cb38b02f2c
@ -129,3 +129,57 @@ func TestStringSetHasAny(t *testing.T) {
|
||||
t.Errorf("expected false, got true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSetEquals(t *testing.T) {
|
||||
// Simple case (order doesn't matter)
|
||||
a := NewStringSet("1", "2")
|
||||
b := NewStringSet("2", "1")
|
||||
if !a.Equal(b) {
|
||||
t.Errorf("Expected to be equal: %v vs %v", a, b)
|
||||
}
|
||||
|
||||
// It is a set; duplicates are ignored
|
||||
b = NewStringSet("2", "2", "1")
|
||||
if !a.Equal(b) {
|
||||
t.Errorf("Expected to be equal: %v vs %v", a, b)
|
||||
}
|
||||
|
||||
// Edge cases around empty sets / empty strings
|
||||
a = NewStringSet()
|
||||
b = NewStringSet()
|
||||
if !a.Equal(b) {
|
||||
t.Errorf("Expected to be equal: %v vs %v", a, b)
|
||||
}
|
||||
|
||||
b = NewStringSet("1", "2", "3")
|
||||
if a.Equal(b) {
|
||||
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
|
||||
}
|
||||
|
||||
b = NewStringSet("1", "2", "")
|
||||
if a.Equal(b) {
|
||||
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
|
||||
}
|
||||
|
||||
// Check for equality after mutation
|
||||
a = NewStringSet()
|
||||
a.Insert("1")
|
||||
if a.Equal(b) {
|
||||
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
|
||||
}
|
||||
|
||||
a.Insert("2")
|
||||
if a.Equal(b) {
|
||||
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
|
||||
}
|
||||
|
||||
a.Insert("")
|
||||
if !a.Equal(b) {
|
||||
t.Errorf("Expected to be equal: %v vs %v", a, b)
|
||||
}
|
||||
|
||||
a.Delete("")
|
||||
if a.Equal(b) {
|
||||
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user