This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/dagger/spec_test.go
Solomon Hykes 612a25fb9f Simplify code by moving polyfill cue compiler to sub-package cc
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
2021-02-08 15:10:32 -08:00

60 lines
1.0 KiB
Go

package dagger
import (
"testing"
"dagger.cloud/go/dagger/cc"
)
func TestMatch(t *testing.T) {
var data = []struct {
Src string
Def string
}{
{
Src: `do: "exec", args: ["echo", "hello"]`,
Def: "#Exec",
},
{
Src: `do: "fetch-git", remote: "github.com/shykes/tests"`,
Def: "#FetchGit",
},
}
for _, d := range data {
testMatch(t, d.Src, d.Def)
}
}
// Test an example op for false positives and negatives
func testMatch(t *testing.T, src interface{}, def string) {
op := compile(t, src)
if def != "" {
if err := spec.Validate(op, def); err != nil {
t.Errorf("false negative: %s: %q: %s", def, src, err)
}
}
for _, cmpDef := range []string{
"#Exec",
"#FetchGit",
"#FetchContainer",
"#Export",
"#Copy",
"#Local",
} {
if cmpDef == def {
continue
}
if err := spec.Validate(op, cmpDef); err == nil {
t.Errorf("false positive: %s: %q", cmpDef, src)
}
}
}
func compile(t *testing.T, src interface{}) *cc.Value {
v, err := cc.Compile("", src)
if err != nil {
t.Fatal(err)
}
return v
}