Files

28 lines
1014 B
Go

package workflow
import "testing"
func TestUsesModel(t *testing.T) {
cases := []struct {
name string
src string
want bool
}{
{"finish only", "id: w\nsteps:\n - type: workflow.finish\n", false},
{"repo and gates", "id: w\nsteps:\n - type: repo.prepare\n - type: gate.repository\n - type: repo.commit\n", false},
{"agent step", "id: w\nsteps:\n - type: agent.run\n", true},
{"agent inside parallel", "id: w\nsteps:\n - parallel:\n a:\n - type: workflow.finish\n b:\n - type: agent.run\n", true},
{"agent inside switch", "id: w\nsteps:\n - switch:\n on: inputs.x\n cases:\n default:\n - type: agent.run\n", true},
{"unknown step", "id: w\nsteps:\n - type: something.new\n", true},
{"no definition", "", true},
{"undecodable", "steps: [", true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := UsesModel(tc.src); got != tc.want {
t.Fatalf("UsesModel = %v, want %v", got, tc.want)
}
})
}
}