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

Commit fcaa080

Browse files
committed
Sort maps before diffing to prevent flaky results
1 parent a086d97 commit fcaa080

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
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+
}

0 commit comments

Comments
 (0)