mirror of https://github.com/docker/buildx.git
Style fixes to test
Signed-off-by: Eli Treuherz <et@arenko.group>
This commit is contained in:
parent
b00001d8ac
commit
bcd04d5a64
2
go.mod
2
go.mod
|
@ -21,7 +21,6 @@ require (
|
||||||
github.com/gofrs/flock v0.8.1
|
github.com/gofrs/flock v0.8.1
|
||||||
github.com/gogo/protobuf v1.3.2
|
github.com/gogo/protobuf v1.3.2
|
||||||
github.com/golang/protobuf v1.5.4
|
github.com/golang/protobuf v1.5.4
|
||||||
github.com/google/go-cmp v0.6.0
|
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/hashicorp/go-cty-funcs v0.0.0-20230405223818-a090f58aa992
|
github.com/hashicorp/go-cty-funcs v0.0.0-20230405223818-a090f58aa992
|
||||||
|
@ -99,6 +98,7 @@ require (
|
||||||
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
|
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
|
||||||
github.com/gogo/googleapis v1.4.1 // indirect
|
github.com/gogo/googleapis v1.4.1 // indirect
|
||||||
github.com/google/gnostic-models v0.6.8 // indirect
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/gofuzz v1.2.0 // indirect
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
github.com/gorilla/mux v1.8.0 // indirect
|
github.com/gorilla/mux v1.8.0 // indirect
|
||||||
github.com/gorilla/websocket v1.5.0 // indirect
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"slices"
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
gocmp "github.com/google/go-cmp/cmp"
|
|
||||||
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
"github.com/moby/buildkit/exporter/containerimage/exptypes"
|
||||||
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -86,33 +85,35 @@ func TestParseAnnotations(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
got, gotErr := ParseAnnotations(test.in)
|
got, err := ParseAnnotations(test.in)
|
||||||
if test.wantErr != "" {
|
if test.wantErr != "" {
|
||||||
require.ErrorContains(t, gotErr, test.wantErr)
|
require.ErrorContains(t, err, test.wantErr)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(t, gotErr)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't compare maps with pointer in their keys, need to extract and sort the map entries
|
// Can't compare maps with pointer in their keys, need to extract and sort the map entries
|
||||||
type kv struct {
|
wantKVs := entries(test.want)
|
||||||
Key exptypes.AnnotationKey
|
gotKVs := entries(got)
|
||||||
Val string
|
|
||||||
}
|
|
||||||
var wantKVs, gotKVs []kv
|
|
||||||
for k, v := range test.want {
|
|
||||||
wantKVs = append(wantKVs, kv{k, v})
|
|
||||||
}
|
|
||||||
for k, v := range got {
|
|
||||||
gotKVs = append(gotKVs, kv{k, v})
|
|
||||||
}
|
|
||||||
|
|
||||||
sortFunc := func(a, b kv) int { return cmp.Compare(a.Key.String(), b.Key.String()) }
|
assert.Equal(t, wantKVs, gotKVs)
|
||||||
slices.SortFunc(wantKVs, sortFunc)
|
|
||||||
slices.SortFunc(gotKVs, sortFunc)
|
|
||||||
|
|
||||||
if diff := gocmp.Diff(wantKVs, gotKVs); diff != "" {
|
|
||||||
t.Error(diff)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type kv struct {
|
||||||
|
Key exptypes.AnnotationKey
|
||||||
|
Val string
|
||||||
|
}
|
||||||
|
|
||||||
|
func entries(in map[exptypes.AnnotationKey]string) []kv {
|
||||||
|
var out []kv
|
||||||
|
for k, v := range in {
|
||||||
|
out = append(out, kv{k, v})
|
||||||
|
}
|
||||||
|
|
||||||
|
sortFunc := func(a, b kv) int { return cmp.Compare(a.Key.String(), b.Key.String()) }
|
||||||
|
slices.SortFunc(out, sortFunc)
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue