feat(server): inline step ref + workflow validation
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mrhid6/vantage/server/internal/models"
|
||||
)
|
||||
|
||||
// ValidateWorkflow checks each step ref sets exactly one of step_id / inline.
|
||||
func ValidateWorkflow(w models.Workflow) error {
|
||||
for i, ref := range w.Steps {
|
||||
hasLib := ref.StepID != ""
|
||||
hasInline := ref.Inline != nil
|
||||
if hasLib == hasInline {
|
||||
return fmt.Errorf("step %d: exactly one of step_id or inline must be set", i)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mrhid6/vantage/server/internal/models"
|
||||
)
|
||||
|
||||
func TestValidateWorkflow(t *testing.T) {
|
||||
inline := &models.WorkflowStep{Name: "x", Interpreter: "bash", Script: "echo hi"}
|
||||
cases := []struct {
|
||||
name string
|
||||
ref models.WorkflowStepRef
|
||||
wantErr bool
|
||||
}{
|
||||
{"library only", models.WorkflowStepRef{StepID: "abc"}, false},
|
||||
{"inline only", models.WorkflowStepRef{Inline: inline}, false},
|
||||
{"both set", models.WorkflowStepRef{StepID: "abc", Inline: inline}, true},
|
||||
{"neither set", models.WorkflowStepRef{}, true},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := ValidateWorkflow(models.Workflow{Steps: []models.WorkflowStepRef{tc.ref}})
|
||||
if (err != nil) != tc.wantErr {
|
||||
t.Fatalf("got err=%v want wantErr=%v", err, tc.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user