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 {
296
296
type BuildConfig struct {
297
297
Context string `yaml:",omitempty" json:"context,omitempty"`
298
298
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"`
300
300
Args MappingWithEquals `yaml:",omitempty" json:"args,omitempty"`
301
301
SSH SSHConfig `yaml:"ssh,omitempty" json:"ssh,omitempty"`
302
302
Labels Labels `yaml:",omitempty" json:"labels,omitempty"`
Original file line number Diff line number Diff line change 17
17
package types
18
18
19
19
import (
20
+ "bytes"
20
21
"encoding/json"
22
+ "fmt"
21
23
"strings"
22
24
"testing"
23
25
@@ -329,3 +331,40 @@ func TestMarshalServiceEntrypoint(t *testing.T) {
329
331
}
330
332
331
333
}
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