Skip to content

Commit

Permalink
compare string slices, complexity o(n^2) is enough for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkady Emelyanov committed Aug 23, 2017
1 parent 3ba71c9 commit ed07e89
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions pkg/kubectl/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@ package kubectl

import (
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)

func CompareStringSlices(l, r []string) bool {
if len(l) != len(r) {
return false
}

for _, leftItem := range l {
found := false
for _, rightItem := range r {
if leftItem == rightItem {
found = true
}
}

if !found {
return false
}
}

return true
}

func TestNamespace_Type(t *testing.T) {
ns := Namespace{
Kind: "Namespace",
Expand Down Expand Up @@ -88,8 +108,8 @@ func TestDeployment_Type(t *testing.T) {
assert.Equal(t, "test-deployment", d.GetName())
assert.Equal(t, "3eb259fc-bc6f-11e6-a342-005056ba5444", d.GetUUID())
assert.Equal(t, "default/test-deployment", d.GetKey())
assert.True(t, reflect.DeepEqual([]string{"sample-label1=example1"}, d.GetSelector()))
assert.True(t, reflect.DeepEqual([]string{"project=test-project-2", "project_build=12"}, d.GetPodSelector()))
assert.True(t, CompareStringSlices([]string{"sample-label1=example1"}, d.GetSelector()))
assert.True(t, CompareStringSlices([]string{"project=test-project-2", "project_build=12"}, d.GetPodSelector()))
assert.False(t, d.IsReady())
assert.Equal(t, "Ready: false, Generation: meta=12 observed=0, Replicas: s=1, u=0, a=0, na=1", d.GetStatusString())

Expand Down

0 comments on commit ed07e89

Please sign in to comment.