github.com/dnephin/dobi@v0.15.0/config/job_test.go (about) 1 package config 2 3 import ( 4 "reflect" 5 "testing" 6 7 pth "github.com/dnephin/configtf/path" 8 "gotest.tools/v3/assert" 9 is "gotest.tools/v3/assert/cmp" 10 ) 11 12 func TestJobConfigString(t *testing.T) { 13 job := &JobConfig{ 14 Use: "builder", 15 Command: ShlexSlice{original: "run"}, 16 Artifact: PathGlobs{globs: []string{"foo"}}, 17 } 18 assert.Equal(t, job.String(), "Run 'run' using the 'builder' image to create 'foo'") 19 } 20 21 func TestJobConfigValidateMissingUse(t *testing.T) { 22 conf := NewConfig() 23 conf.Resources["example"] = &AliasConfig{} 24 job := &JobConfig{Use: "example"} 25 err := job.Validate(pth.NewPath(""), conf) 26 assert.Assert(t, is.ErrorContains(err, "example is not an image resource")) 27 } 28 29 func TestJobConfigValidateMissingMount(t *testing.T) { 30 conf := NewConfig() 31 conf.Resources["one"] = NewImageConfig() 32 conf.Resources["two"] = NewImageConfig() 33 conf.Resources["example"] = NewImageConfig() 34 job := &JobConfig{} 35 job.Use = "example" 36 job.Mounts = []string{"one", "two"} 37 38 err := job.Validate(pth.NewPath(""), conf) 39 assert.Assert(t, is.ErrorContains(err, "one is not a mount resource")) 40 } 41 42 func TestJobConfigRunFromConfig(t *testing.T) { 43 values := map[string]interface{}{ 44 "use": "image-res", 45 "command": "echo foo", 46 "entrypoint": "bash -c", 47 } 48 res, err := jobFromConfig("foo", values) 49 job, ok := res.(*JobConfig) 50 assert.Assert(t, ok) 51 assert.NilError(t, err) 52 // TODO: compare against the entire struct 53 assert.Equal(t, job.Use, "image-res") 54 assert.Assert(t, is.DeepEqual(job.Command.Value(), []string{"echo", "foo"})) 55 assert.Assert(t, is.DeepEqual(job.Entrypoint.Value(), []string{"bash", "-c"})) 56 } 57 58 func TestShlexSliceTransformConfig(t *testing.T) { 59 s := ShlexSlice{} 60 zero := reflect.Value{} 61 err := s.TransformConfig(zero) 62 63 assert.Check(t, is.ErrorContains(err, "must be a string")) 64 }