File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -296,7 +296,7 @@ func (s set) toSlice() []string {
296296type BuildConfig struct {
297297 Context string `yaml:",omitempty" json:"context,omitempty"`
298298 Dockerfile string `yaml:",omitempty" json:"dockerfile,omitempty"`
299- DockerfileInline string `yaml:",omitempty" json:"dockerfile_inline,omitempty"`
299+ DockerfileInline string `yaml:"dockerfile_inline ,omitempty" json:"dockerfile_inline,omitempty"`
300300 Args MappingWithEquals `yaml:",omitempty" json:"args,omitempty"`
301301 SSH SSHConfig `yaml:"ssh,omitempty" json:"ssh,omitempty"`
302302 Labels Labels `yaml:",omitempty" json:"labels,omitempty"`
Original file line number Diff line number Diff line change 1717package types
1818
1919import (
20+ "bytes"
2021 "encoding/json"
22+ "fmt"
2123 "strings"
2224 "testing"
2325
@@ -329,3 +331,40 @@ func TestMarshalServiceEntrypoint(t *testing.T) {
329331 }
330332
331333}
334+
335+ func TestMarshalBuild_DockerfileInline (t * testing.T ) {
336+ b := BuildConfig {
337+ DockerfileInline : "FROM alpine\n \n # echo the env\n RUN env\n \n ENTRYPOINT /bin/echo\n " ,
338+ }
339+ out , err := yaml .Marshal (b )
340+ assert .NilError (t , err )
341+
342+ const expected = `
343+ dockerfile_inline: |
344+ FROM alpine
345+
346+ # echo the env
347+ RUN env
348+
349+ ENTRYPOINT /bin/echo
350+ `
351+ assert .Check (t , equalTrimSpace (out , expected ))
352+
353+ // round-trip
354+ var b2 BuildConfig
355+ assert .NilError (t , yaml .Unmarshal (out , & b2 ))
356+ assert .Check (t , equalTrimSpace (b .DockerfileInline , b2 .DockerfileInline ))
357+ }
358+
359+ func equalTrimSpace (x interface {}, y interface {}) is.Comparison {
360+ trim := func (v interface {}) interface {} {
361+ switch vv := v .(type ) {
362+ case string :
363+ return strings .TrimSpace (vv )
364+ case []byte :
365+ return string (bytes .TrimSpace (vv ))
366+ }
367+ panic (fmt .Errorf ("invalid type %T (value: %+v)" , v , v ))
368+ }
369+ return is .DeepEqual (trim (x ), trim (y ))
370+ }
You can’t perform that action at this time.
0 commit comments