package operator import ( "path/filepath" "strings" "testing" ) func fixture(t *testing.T, name string) string { t.Helper() return filepath.Join("..", "..", "testdata", "operator", name) } func TestLoadScenarioValidatesExample(t *testing.T) { sc, err := LoadScenario(fixture(t, "api_connection_smoke.yaml")) if err != nil { t.Fatalf("LoadScenario returned error: %v", err) } if sc.Name != "api_connection_smoke" { t.Errorf("name = %q, want api_connection_smoke", sc.Name) } if len(sc.Steps) != 1 { t.Fatalf("steps = %d, want 1", len(sc.Steps)) } if sc.Steps[0].Action != ActionHello { t.Errorf("step action = %q, want %q", sc.Steps[0].Action, ActionHello) } } func TestLoadScenarioRejectsUnknownAction(t *testing.T) { _, err := LoadScenario(fixture(t, "invalid_request_matrix.yaml")) if err == nil { t.Fatal("expected error for unknown action, got nil") } if !strings.Contains(err.Error(), "unknown action") { t.Errorf("error = %v, want it to mention unknown action", err) } } func TestLoadScenarioRejectsMissingStepID(t *testing.T) { data := []byte("name: missing_id\ntimeout: 1s\nsteps:\n - action: hello\n") _, err := ParseScenario(data) if err == nil { t.Fatal("expected error for missing step id, got nil") } if !strings.Contains(err.Error(), "id is required") { t.Errorf("error = %v, want it to mention id is required", err) } } func TestParseScenarioRejectsInvalidDuration(t *testing.T) { data := []byte("name: invalid_timeout\ntimeout: not-a-duration\nsteps:\n - id: hello\n action: hello\n") _, err := ParseScenario(data) if err == nil { t.Fatal("expected error for invalid timeout, got nil") } if !strings.Contains(err.Error(), "invalid timeout") { t.Errorf("error = %v, want it to mention invalid timeout", err) } }