Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 08044eb

Browse files
authored
Merge pull request #219 from nkubala/test_flake
Sort maps before diffing to prevent flaky results
2 parents 5866a17 + 80347e5 commit 08044eb

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

pkg/util/image_prep_utils.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"io/ioutil"
2525
"os"
26+
"sort"
2627
"strings"
2728

2829
"github.com/GoogleCloudPlatform/container-diff/cmd/util/output"
@@ -99,9 +100,9 @@ func (c ConfigObject) AsList() []string {
99100
return []string{
100101
fmt.Sprintf("Env: %s", strings.Join(c.Env, ",")),
101102
fmt.Sprintf("Entrypoint: %s", strings.Join(c.Entrypoint, ",")),
102-
fmt.Sprintf("ExposedPorts: %v", c.ExposedPorts),
103+
fmt.Sprintf("ExposedPorts: %v", sortMap(c.ExposedPorts)),
103104
fmt.Sprintf("Cmd: %s", strings.Join(c.Cmd, ",")),
104-
fmt.Sprintf("Volumes: %v", c.Volumes),
105+
fmt.Sprintf("Volumes: %v", sortMap(c.Volumes)),
105106
fmt.Sprintf("Workdir: %s", c.Workdir),
106107
fmt.Sprintf("Labels: %v", c.Labels),
107108
}
@@ -241,3 +242,12 @@ func CleanupImage(image Image) {
241242
}
242243
}
243244
}
245+
246+
func sortMap(m map[string]struct{}) string {
247+
pairs := make([]string, 0)
248+
for key := range m {
249+
pairs = append(pairs, fmt.Sprintf("%s:%s", key, m[key]))
250+
}
251+
sort.Strings(pairs)
252+
return strings.Join(pairs, " ")
253+
}

tests/metadata_diff_expected.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"Diff": {
77
"Adds": [
88
"Entrypoint: /entrypoint",
9-
"ExposedPorts: map[1234/tcp:{}]"
9+
"ExposedPorts: 1234/tcp:{}"
1010
],
1111
"Dels": [
1212
"Entrypoint: ",
13-
"ExposedPorts: map[1234/tcp:{} 4321/tcp:{}]"
13+
"ExposedPorts: 1234/tcp:{} 4321/tcp:{}"
1414
]
1515
}
1616
}

0 commit comments

Comments
 (0)