From 51c5fe6bfb098a677f9705894de1f02785c6a601 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Thu, 30 May 2024 09:54:23 -0400 Subject: [PATCH] tests: fix flakey tests #### What type of PR is this? /kind cleanup #### What this PR does / why we need it: Fixes the two flakey tests. One which is returning them in random orders.. The other which is not available to run on mac due to not being able "access" the folders. #### Which issue(s) this PR fixes: N/A #### Special notes for your reviewer: N/A Signed-off-by: Charlie Drage --- pkg/transformer/kubernetes/k8sutils_test.go | 43 +++++++-------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/pkg/transformer/kubernetes/k8sutils_test.go b/pkg/transformer/kubernetes/k8sutils_test.go index 8619192e4..6392338e3 100644 --- a/pkg/transformer/kubernetes/k8sutils_test.go +++ b/pkg/transformer/kubernetes/k8sutils_test.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" "reflect" + "sort" "strconv" "testing" @@ -2348,33 +2349,6 @@ func Test_isConfigFile(t *testing.T) { wantReadonly: false, wantSkip: true, }, - { - name: "dir sys", - args: args{ - filePath: "/sys", - }, - wantUseConfigMap: false, - wantReadonly: false, - wantSkip: true, - }, - { - name: "dir root", - args: args{ - filePath: "/root", - }, - wantUseConfigMap: false, - wantReadonly: false, - wantSkip: true, - }, - { - name: "docker var lib", - args: args{ - filePath: "/var/lib/docker", - }, - wantUseConfigMap: false, - wantReadonly: false, - wantSkip: true, - }, { name: "file from 3 levels", args: args{ @@ -2884,7 +2858,20 @@ func Test_searchNetworkModeToService(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if gotDeploymentMappings := searchNetworkModeToService(tt.services); !reflect.DeepEqual(gotDeploymentMappings, tt.want) { + gotDeploymentMappings := searchNetworkModeToService(tt.services) + sort.Slice(gotDeploymentMappings, func(i, j int) bool { + if gotDeploymentMappings[i].SourceDeploymentName != gotDeploymentMappings[j].SourceDeploymentName { + return gotDeploymentMappings[i].SourceDeploymentName < gotDeploymentMappings[j].SourceDeploymentName + } + return gotDeploymentMappings[i].TargetDeploymentName < gotDeploymentMappings[j].TargetDeploymentName + }) + sort.Slice(tt.want, func(i, j int) bool { + if tt.want[i].SourceDeploymentName != tt.want[j].SourceDeploymentName { + return tt.want[i].SourceDeploymentName < tt.want[j].SourceDeploymentName + } + return tt.want[i].TargetDeploymentName < tt.want[j].TargetDeploymentName + }) + if !reflect.DeepEqual(gotDeploymentMappings, tt.want) { t.Errorf("searchNetworkModeToService() = %v, want %v", gotDeploymentMappings, tt.want) } })