package ciconfig import ( "strings" "testing" ) func TestRejectsUnsupportedKDLShapesAndDuplicateSingletons(t *testing.T) { base := `job "x" { image "alpine"; run "true"; %s }` cases := map[string]string{ "duplicate image": `image "busybox"`, "image property": `image "alpine" extra=true`, "image child": `image "alpine" { nested }`, "run property": `run "true" extra=true`, "run child": `run "true" { nested }`, "integer image": `image 7`, "duplicate matrix": `matrix { os "linux" } matrix { os "mac" }`, "matrix property": `matrix extra=true { os "linux" }`, "axis property": `matrix { os "linux" extra=true }`, "axis child": `matrix { os "linux" { nested } }`, "secret property": `secret "token" env="TOKEN" unknown="x"`, "secret child": `secret "token" env="TOKEN" { nested }`, "secret integer env": `secret "token" env=7`, "cache property": `cache "deps" extra=true { path "deps"; key { file "lock" } }`, "cache path property": `cache "deps" { path "deps" extra=true; key { file "lock" } }`, "publish property": `publish "site" extra=true { from "dist"; to "docs" }`, "publish child property": `publish "site" { from "dist" extra=true; to "docs" }`, "integer publish path": `publish "site" { from 7; to "docs" }`, "empty command": `run " "`, } for name, body := range cases { t.Run(name, func(t *testing.T) { source := strings.Replace(base, "%s", body, 1) if _, err := ParseFiles(map[string]string{"ci.kdl": source}); err == nil { t.Fatalf("invalid shape accepted: %s", source) } }) } }