github.com/panekj/cli@v0.0.0-20230304125325-467dd2f3797e/cli/command/context_test.go (about)

     1  package command
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"gotest.tools/v3/assert"
     8  )
     9  
    10  func TestDockerContextMetadataKeepAdditionalFields(t *testing.T) {
    11  	c := DockerContext{
    12  		Description: "test",
    13  		AdditionalFields: map[string]interface{}{
    14  			"foo": "bar",
    15  		},
    16  	}
    17  	jsonBytes, err := json.Marshal(c)
    18  	assert.NilError(t, err)
    19  	const expected = `{"Description":"test","foo":"bar"}`
    20  	assert.Equal(t, string(jsonBytes), expected)
    21  
    22  	var c2 DockerContext
    23  	assert.NilError(t, json.Unmarshal(jsonBytes, &c2))
    24  	assert.Equal(t, c2.AdditionalFields["foo"], "bar")
    25  	assert.Equal(t, c2.Description, "test")
    26  }