github.com/thajeztah/cli@v0.0.0-20240223162942-dc6bfac81a8b/cli/command/context_test.go (about)

     1  // FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
     2  //go:build go1.19
     3  
     4  package command
     5  
     6  import (
     7  	"encoding/json"
     8  	"testing"
     9  
    10  	"gotest.tools/v3/assert"
    11  )
    12  
    13  func TestDockerContextMetadataKeepAdditionalFields(t *testing.T) {
    14  	c := DockerContext{
    15  		Description: "test",
    16  		AdditionalFields: map[string]any{
    17  			"foo": "bar",
    18  		},
    19  	}
    20  	jsonBytes, err := json.Marshal(c)
    21  	assert.NilError(t, err)
    22  	const expected = `{"Description":"test","foo":"bar"}`
    23  	assert.Equal(t, string(jsonBytes), expected)
    24  
    25  	var c2 DockerContext
    26  	assert.NilError(t, json.Unmarshal(jsonBytes, &c2))
    27  	assert.Equal(t, c2.AdditionalFields["foo"], "bar")
    28  	assert.Equal(t, c2.Description, "test")
    29  }