DockerCLI/cli/command/context_test.go

27 lines
587 B
Go
Raw Normal View History

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")
}