diff --git a/chaoskube/chaoskube_test.go b/chaoskube/chaoskube_test.go index 6fd20887..85c86b92 100644 --- a/chaoskube/chaoskube_test.go +++ b/chaoskube/chaoskube_test.go @@ -949,32 +949,47 @@ func (suite *Suite) TestFilterByOwnerReference() { baz1 := util.NewPod("default", "baz-1", v1.PodRunning) for _, tt := range []struct { + seed int64 name string pods []v1.Pod expected []v1.Pod }{ { - name: "2 pods, same parent", + seed: 1000, + name: "2 pods, same parent, pick first", pods: []v1.Pod{foo, foo1}, expected: []v1.Pod{foo}, }, { + seed: 2000, + name: "2 pods, same parent, pick second", + pods: []v1.Pod{foo, foo1}, + expected: []v1.Pod{foo1}, + }, + { + seed: 1000, name: "2 pods, different parents", pods: []v1.Pod{foo, bar}, expected: []v1.Pod{foo, bar}, }, { + seed: 1000, name: "2 pods, one with/without parent", pods: []v1.Pod{foo, baz}, - expected: []v1.Pod{foo, baz}, + expected: []v1.Pod{baz, foo}, // implementation detail: pods without owner reference appear first in the list }, { + seed: 1000, name: "2 pods, no parents", pods: []v1.Pod{baz, baz1}, expected: []v1.Pod{baz, baz1}, }, } { + rand.Seed(tt.seed) + results := filterByOwnerReference(tt.pods) + suite.Require().Len(results, len(tt.expected)) + for i, result := range results { suite.Assert().Equal(tt.expected[i], result, tt.name) }