Files
orca/internal/jobspec/spec_test.go
T

61 lines
1.2 KiB
Go

package jobspec
import (
"testing"
)
func TestParseValid(t *testing.T) {
hcl := `
job "demo" {
}
task "build" {
command = "/bin/echo"
args = ["hello", "world"]
}
`
spec, err := Parse([]byte(hcl), "test.hcl")
if err != nil {
t.Fatalf("parse: %v", err)
}
if spec.Job.Name != "demo" {
t.Errorf("expected job name 'demo', got %q", spec.Job.Name)
}
if len(spec.Tasks) != 1 {
t.Fatalf("expected 1 task, got %d", len(spec.Tasks))
}
if spec.Tasks[0].Command != "/bin/echo" {
t.Errorf("expected command '/bin/echo', got %q", spec.Tasks[0].Command)
}
if len(spec.Tasks[0].Args) != 2 {
t.Errorf("expected 2 args, got %d", len(spec.Tasks[0].Args))
}
}
func TestParseMissingJob(t *testing.T) {
hcl := `task "x" { command = "/bin/echo" }`
_, err := Parse([]byte(hcl), "test.hcl")
if err == nil {
t.Fatal("expected error for missing job name")
}
}
func TestParseNoTasks(t *testing.T) {
hcl := `job "empty" {}`
_, err := Parse([]byte(hcl), "test.hcl")
if err == nil {
t.Fatal("expected error for no tasks")
}
}
func TestParseTaskMissingCommand(t *testing.T) {
hcl := `
job "x" {}
task "no-cmd" {}
`
_, err := Parse([]byte(hcl), "test.hcl")
if err == nil {
t.Fatal("expected error for missing command")
}
}