Unit tests to reproduce issue #19 and narrow down root cause.

Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
Solomon Hykes 2021-01-21 11:50:45 -08:00
parent 007b10f455
commit 91654ba786
3 changed files with 95 additions and 0 deletions

View File

@ -5,6 +5,48 @@ import (
"testing" "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) { func TestValidateEmptyComponent(t *testing.T) {
cc := &Compiler{} cc := &Compiler{}
v, err := cc.Compile("", "#dagger: compute: _") v, err := cc.Compile("", "#dagger: compute: _")

View File

@ -6,6 +6,44 @@ import (
"testing" "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) { func TestValidateEmptyValue(t *testing.T) {
cc := &Compiler{} cc := &Compiler{}
v, err := cc.Compile("", "#dagger: compute: _") v, err := cc.Compile("", "#dagger: compute: _")

View File

@ -0,0 +1,15 @@
package test
#dagger: compute: [
{
do: "fetch-container"
ref: "busybox"
},
{
do: "exec"
args: ["sh", "-c", """
echo hello > /tmp/out
"""]
// dir: "/"
},
]