github.com/dnephin/dobi@v0.15.0/config/unmarshal_test.go (about) 1 package config 2 3 import ( 4 "testing" 5 6 "github.com/google/go-cmp/cmp" 7 "github.com/renstrom/dedent" 8 "gotest.tools/v3/assert" 9 is "gotest.tools/v3/assert/cmp" 10 ) 11 12 func TestLoadFromBytes(t *testing.T) { 13 conf := dedent.Dedent(` 14 meta: 15 default: alias-def 16 17 image=image-def: 18 image: imagename 19 dockerfile: what 20 args: 21 VERSION: "3.3.3" 22 DEBUG: 'true' 23 24 mount=vol-def: 25 bind: dist/ 26 path: /target 27 28 job=cmd-def: 29 use: image-def 30 mounts: [vol-def] 31 32 alias=alias-def: 33 tasks: [vol-def, cmd-def] 34 35 compose=compose-def: 36 files: ['foo.yml'] 37 `) 38 39 config, err := LoadFromBytes([]byte(conf)) 40 assert.NilError(t, err) 41 42 expected := &Config{ 43 Meta: &MetaConfig{ 44 Default: "alias-def", 45 }, 46 Resources: map[string]Resource{ 47 "image-def": &ImageConfig{ 48 Dockerfile: "what", 49 Args: map[string]string{ 50 "VERSION": "3.3.3", 51 "DEBUG": "true", 52 }, 53 Image: "imagename", 54 }, 55 "vol-def": &MountConfig{ 56 Bind: "dist/", 57 Path: "/target", 58 }, 59 "cmd-def": &JobConfig{ 60 Use: "image-def", 61 Mounts: []string{"vol-def"}, 62 }, 63 "alias-def": &AliasConfig{ 64 Tasks: []string{"vol-def", "cmd-def"}, 65 }, 66 "compose-def": &ComposeConfig{ 67 Files: []string{"foo.yml"}, 68 StopGrace: 5, 69 Project: "{unique}", 70 }, 71 }, 72 } 73 assert.DeepEqual(t, config, expected, cmpConfigOpt) 74 } 75 76 var cmpConfigOpt = cmp.AllowUnexported(PathGlobs{}, pull{}, ShlexSlice{}) 77 78 func TestLoadFromBytesWithReservedName(t *testing.T) { 79 conf := dedent.Dedent(` 80 image=image-def: 81 image: imagename 82 dockerfile: what 83 84 mount=autoclean: 85 path: dist/ 86 mount: /target 87 `) 88 89 _, err := LoadFromBytes([]byte(conf)) 90 assert.Check(t, is.ErrorContains(err, `"autoclean" is reserved`)) 91 } 92 93 func TestLoadFromBytesWithInvalidName(t *testing.T) { 94 conf := dedent.Dedent(` 95 image=image:latest: 96 image: imagename 97 dockerfile: what 98 `) 99 100 _, err := LoadFromBytes([]byte(conf)) 101 assert.Check(t, is.ErrorContains(err, `invalid character ":"`)) 102 }