Skip to content

Commit

Permalink
fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
djeebus committed Jul 24, 2023
1 parent 3a27ec6 commit adb75c0
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions pkg/affected_apps/best_effort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zapier/kubechecks/pkg/app_directory"
)

Expand Down Expand Up @@ -158,13 +159,40 @@ func TestBestEffortMatcher(t *testing.T) {

matcher := NewBestEffortMatcher(tt.args.repoName, testRepoFiles)
got, err = matcher.AffectedApps(context.TODO(), tt.args.fileList)
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, tt.want, got, "GenerateListOfAffectedApps not equal")
assert.Equal(t, len(tt.want.Applications), len(got.Applications))
assert.Equal(t, len(tt.want.ApplicationSets), len(got.ApplicationSets))

// ordering doesn't matter, we just want to make sure the items all exist
wantAppsMap := listToMap(tt.want.Applications, appStubKey)
gotAppsMap := listToMap(got.Applications, appStubKey)
assert.Equal(t, wantAppsMap, gotAppsMap, "Applications not equal")

wantAppSetsMap := listToMap(tt.want.ApplicationSets, appSetKey)
gotAppSetsMap := listToMap(got.ApplicationSets, appSetKey)
assert.Equal(t, wantAppSetsMap, gotAppSetsMap, "ApplicationSets not equal")
})
}
}

func appSetKey(item ApplicationSet) string {
return item.Name
}

func appStubKey(stub app_directory.ApplicationStub) string {
return stub.Name
}

func listToMap[T any](items []T, makeKey func(T) string) map[string]T {
result := make(map[string]T)
for _, item := range items {
key := makeKey(item)
result[key] = item
}
return result
}

var testRepoFiles = []string{
"apps/echo-server/foo-eks-01/Chart.yaml",
"apps/echo-server/foo-eks-01/values.yaml",
Expand Down

0 comments on commit adb75c0

Please sign in to comment.