Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
39 changes: 39 additions & 0 deletions types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package types

import (
"bytes"
"encoding/json"
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -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))
}