Skip to content

Commit

Permalink
Merge pull request #53 from BinSquare/flaky-unit-test-fix
Browse files Browse the repository at this point in the history
BugFix: Fix flaky unit test that conducts ordered check on unordered map -> slice conversion.
  • Loading branch information
BinSquare authored Jul 13, 2023
2 parents e1ce0e6 + 66b3305 commit 60b8ebb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 14 additions & 2 deletions args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

//go:build unit
// +build unit

package main
Expand Down Expand Up @@ -274,9 +275,20 @@ func testGetDockerConfigsNoError(t *testing.T) {
assert.Equal(t, testContainerImageName, args.ContainerImageName)
assert.Equal(t, testContainerImageID, args.ContainerImageID)
assert.Equal(t, true, reflect.DeepEqual(args.ContainerLabels, testContainerLabelsMap))
for i := range args.ContainerEnv {
assert.Equal(t, testContainerEnvSlice[i], args.ContainerEnv[i])
// Docker logging use a slice to store the environment variables
// Each item is in the format of "key=value" the unit test should
// convert it back to a map to guarantee content exists but disregard
// the order.
// ref: https://github.com/moby/moby/blob/c833222d54c00d64a0fc44c561a5973ecd414053/daemon/logger/loginfo.go#L60
testContainerEnvMap := make(map[string]struct{})
for _, v := range testContainerEnvSlice {
testContainerEnvMap[v] = struct{}{}
}
argsContainerEnvMap := make(map[string]struct{})
for _, v := range args.ContainerEnv {
argsContainerEnvMap[v] = struct{}{}
}
assert.Equal(t, true, reflect.DeepEqual(testContainerEnvMap, argsContainerEnvMap))
}

// testGetDockerConfigsEmpty tests that empty docker config input parameter generates no error
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.7.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
gotest.tools v2.2.0+incompatible
)

Expand Down Expand Up @@ -55,10 +55,12 @@ require (
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/tinylib/msgp v1.1.1 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a // indirect
google.golang.org/grpc v1.33.2 // indirect
google.golang.org/protobuf v1.27.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -870,6 +871,7 @@ golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjs
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down

0 comments on commit 60b8ebb

Please sign in to comment.