diff --git a/dagger/component_test.go b/dagger/component_test.go index 02d4bc45..5ed1a6b5 100644 --- a/dagger/component_test.go +++ b/dagger/component_test.go @@ -5,6 +5,48 @@ import ( "testing" ) +// Test that default values in spec are applied at the component level +// See issue #19 +func TestComponentDefaults(t *testing.T) { + t.Skip("FIXME: issue #19") + cc := &Compiler{} + v, err := cc.Compile("", ` +#dagger: compute: [ + { + do: "fetch-container" + ref: "busybox" + }, + { + do: "exec" + args: ["sh", "-c", """ + echo hello > /tmp/out + """] +// dir: "/" + } +] +`) + if err != nil { + t.Fatal(err) + } + c, err := v.Component() + if err != nil { + t.Fatal(err) + } + // Issue #19 is triggered by: + // 1. Compile component + // 2. Get compute script from component + // 3. Walk script + s, err := c.ComputeScript() + if err != nil { + t.Fatal(err) + } + if err := s.Walk(context.TODO(), func(op *Op) error { + return nil + }); err != nil { + t.Fatal(err) + } +} + func TestValidateEmptyComponent(t *testing.T) { cc := &Compiler{} v, err := cc.Compile("", "#dagger: compute: _") diff --git a/dagger/script_test.go b/dagger/script_test.go index b5a2eb65..ccc192cc 100644 --- a/dagger/script_test.go +++ b/dagger/script_test.go @@ -6,6 +6,44 @@ import ( "testing" ) +// Test that default values in spec are applied +func TestScriptDefaults(t *testing.T) { + cc := &Compiler{} + v, err := cc.Compile("", ` + { + do: "exec" + args: ["sh", "-c", """ + echo hello > /tmp/out + """] +// dir: "/" + } +`) + if err != nil { + t.Fatal(err) + } + op, err := v.Op() + if err != nil { + t.Fatal(err) + } + if err := op.Validate(); err != nil { + t.Fatal(err) + } + dir, err := op.Get("dir").String() + if err != nil { + t.Fatal(err) + } + if dir != "/" { + t.Fatal(dir) + } + t.Skip("FIXME: issue #19") + // Walk triggers issue #19 UNLESS optional fields removed from spec.cue + if err := op.Walk(context.TODO(), func(op *Op) error { + return nil + }); err != nil { + t.Fatal(err) + } +} + func TestValidateEmptyValue(t *testing.T) { cc := &Compiler{} v, err := cc.Compile("", "#dagger: compute: _") diff --git a/examples/tests/repro-19/main.cue b/examples/tests/repro-19/main.cue new file mode 100644 index 00000000..3016d7d9 --- /dev/null +++ b/examples/tests/repro-19/main.cue @@ -0,0 +1,15 @@ +package test + +#dagger: compute: [ + { + do: "fetch-container" + ref: "busybox" + }, + { + do: "exec" + args: ["sh", "-c", """ + echo hello > /tmp/out + """] + // dir: "/" + }, +]