diff --git a/types/types.go b/types/types.go index c59b540f..226ddc81 100644 --- a/types/types.go +++ b/types/types.go @@ -296,7 +296,7 @@ func (s set) toSlice() []string { type BuildConfig struct { Context string `yaml:",omitempty" json:"context,omitempty"` Dockerfile string `yaml:",omitempty" json:"dockerfile,omitempty"` - DockerfileInline string `yaml:",omitempty" json:"dockerfile_inline,omitempty"` + DockerfileInline string `yaml:"dockerfile_inline,omitempty" json:"dockerfile_inline,omitempty"` Args MappingWithEquals `yaml:",omitempty" json:"args,omitempty"` SSH SSHConfig `yaml:"ssh,omitempty" json:"ssh,omitempty"` Labels Labels `yaml:",omitempty" json:"labels,omitempty"` diff --git a/types/types_test.go b/types/types_test.go index 2ec54760..e4e7a13a 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -17,7 +17,9 @@ package types import ( + "bytes" "encoding/json" + "fmt" "strings" "testing" @@ -329,3 +331,40 @@ func TestMarshalServiceEntrypoint(t *testing.T) { } } + +func TestMarshalBuild_DockerfileInline(t *testing.T) { + b := BuildConfig{ + DockerfileInline: "FROM alpine\n\n# echo the env\nRUN env\n\nENTRYPOINT /bin/echo\n", + } + out, err := yaml.Marshal(b) + assert.NilError(t, err) + + const expected = ` +dockerfile_inline: | + FROM alpine + + # echo the env + RUN env + + ENTRYPOINT /bin/echo +` + assert.Check(t, equalTrimSpace(out, expected)) + + // round-trip + var b2 BuildConfig + assert.NilError(t, yaml.Unmarshal(out, &b2)) + assert.Check(t, equalTrimSpace(b.DockerfileInline, b2.DockerfileInline)) +} + +func equalTrimSpace(x interface{}, y interface{}) is.Comparison { + trim := func(v interface{}) interface{} { + switch vv := v.(type) { + case string: + return strings.TrimSpace(vv) + case []byte: + return string(bytes.TrimSpace(vv)) + } + panic(fmt.Errorf("invalid type %T (value: %+v)", v, v)) + } + return is.DeepEqual(trim(x), trim(y)) +}