From 2f3245fe6d8f535faeee55b29fe22b92c8437bd3 Mon Sep 17 00:00:00 2001 From: Ivan Milchev Date: Wed, 3 May 2023 10:09:55 +0200 Subject: [PATCH] fix flaky k8s test Signed-off-by: Ivan Milchev --- motor/discovery/k8s/resolver_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/motor/discovery/k8s/resolver_test.go b/motor/discovery/k8s/resolver_test.go index 48e9f50e6a..ae17b07ce6 100644 --- a/motor/discovery/k8s/resolver_test.go +++ b/motor/discovery/k8s/resolver_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/base64" "os" + "sort" "testing" "github.com/stretchr/testify/assert" @@ -194,16 +195,19 @@ func TestManifestResolverMultiPodDiscovery(t *testing.T) { // When this check fails locally, check your kubeconfig. // context has to reference the default namespace assert.Equal(t, 2, len(assetList)) + sort.Slice(assetList, func(i, j int) bool { + return assetList[i].Name < assetList[j].Name + }) assert.Contains(t, assetList[0].Platform.Family, "k8s-workload") assert.Contains(t, assetList[0].Platform.Family, "k8s") assert.Equal(t, "k8s-manifest", assetList[0].Platform.Runtime) assert.Equal(t, "k8s-pod", assetList[0].Platform.Name) - assert.Equal(t, "default/mondoo", assetList[0].Name) + assert.Equal(t, "default/hello-pod-2", assetList[0].Name) assert.Contains(t, assetList[1].Platform.Family, "k8s-workload") assert.Contains(t, assetList[1].Platform.Family, "k8s") assert.Equal(t, "k8s-manifest", assetList[1].Platform.Runtime) assert.Equal(t, "k8s-pod", assetList[1].Platform.Name) - assert.Equal(t, "default/hello-pod-2", assetList[1].Name) + assert.Equal(t, "default/mondoo", assetList[1].Name) } func TestManifestResolverWrongDiscovery(t *testing.T) {