tests: fix flakey tests (#1886)

#### What type of PR is this?

<!--
Add one of the following kinds:
/kind bug
/kind documentation
/kind feature
-->
/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:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

N/A

#### Special notes for your reviewer:

N/A

Signed-off-by: Charlie Drage <charlie@charliedrage.com>
This commit is contained in:
Charlie Drage 2024-05-30 11:51:02 -04:00 committed by GitHub
parent b08a83ccbb
commit 50ec43d1e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"sort"
"strconv" "strconv"
"testing" "testing"
@ -2348,33 +2349,6 @@ func Test_isConfigFile(t *testing.T) {
wantReadonly: false, wantReadonly: false,
wantSkip: true, 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", name: "file from 3 levels",
args: args{ args: args{
@ -2884,7 +2858,20 @@ func Test_searchNetworkModeToService(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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) t.Errorf("searchNetworkModeToService() = %v, want %v", gotDeploymentMappings, tt.want)
} }
}) })