docker-cli/cli/command/context_test.go
Sebastiaan van Stijn 7c80e4f938
update go:build tags to use go1.22
commit 4a7b04d4127c6082a9e8de95cfce6f34744d8fc1 configured golangci-lint
to use go1.23 semantics, which enabled the copyloopvar linter.

go1.22 now creates a copy of variables when assigned in a loop; make sure we
don't have files that may downgrade semantics to go1.21 in case that also means
disabling that feature; https://go.dev/ref/spec#Go_1.22

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 12:38:18 +01:00

30 lines
736 B
Go

// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.22
package command
import (
"encoding/json"
"testing"
"gotest.tools/v3/assert"
)
func TestDockerContextMetadataKeepAdditionalFields(t *testing.T) {
c := DockerContext{
Description: "test",
AdditionalFields: map[string]any{
"foo": "bar",
},
}
jsonBytes, err := json.Marshal(c)
assert.NilError(t, err)
const expected = `{"Description":"test","foo":"bar"}`
assert.Equal(t, string(jsonBytes), expected)
var c2 DockerContext
assert.NilError(t, json.Unmarshal(jsonBytes, &c2))
assert.Equal(t, c2.AdditionalFields["foo"], "bar")
assert.Equal(t, c2.Description, "test")
}