Don't loose additional metadata fields
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
This commit is contained in:
27
cli/command/context_test.go
Normal file
27
cli/command/context_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func TestDockerContextMetadataKeepAdditionalFields(t *testing.T) {
|
||||
c := DockerContext{
|
||||
Description: "test",
|
||||
StackOrchestrator: OrchestratorSwarm,
|
||||
AdditionalFields: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
},
|
||||
}
|
||||
jsonBytes, err := json.Marshal(c)
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, `{"Description":"test","StackOrchestrator":"swarm","foo":"bar"}`, string(jsonBytes))
|
||||
|
||||
var c2 DockerContext
|
||||
assert.NilError(t, json.Unmarshal(jsonBytes, &c2))
|
||||
assert.Equal(t, c2.AdditionalFields["foo"], "bar")
|
||||
assert.Equal(t, c2.StackOrchestrator, OrchestratorSwarm)
|
||||
assert.Equal(t, c2.Description, "test")
|
||||
}
|
||||
Reference in New Issue
Block a user