Skip to content

Commit

Permalink
fixup! feat(cmd): log test transform errors to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
shellcromancer committed Oct 30, 2024
1 parent 5230b1f commit f061ca2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions cmd/substation/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func handleTest(w http.ResponseWriter, r *http.Request) {
for _, test := range cfg.Tests {
cnd, err := condition.New(ctx, test.Condition)
if err != nil {
output.WriteString("?\t[test error]\n")
fmt.Fprintf(&output, "test condition error: %v\n", err)
sendJSONResponse(w, map[string]string{"output": output.String()})
return
}
Expand All @@ -202,28 +202,28 @@ func handleTest(w http.ResponseWriter, r *http.Request) {
Transforms: test.Transforms,
})
if err != nil {
output.WriteString("?\t[test error]\n")
fmt.Fprintf(&output, "test config error: %v\n", err)
sendJSONResponse(w, map[string]string{"output": output.String()})
return
}

tester, err := substation.New(ctx, cfg.Config)
if err != nil {
output.WriteString("?\t[config error]\n")
fmt.Fprintf(&output, "config error: %v\n", err)
sendJSONResponse(w, map[string]string{"output": output.String()})
return
}

sMsgs, err := setup.Transform(ctx, message.New().AsControl())
if err != nil {
output.WriteString("?\t[test error]\n")
fmt.Fprintf(&output, "test transform error: %v\n", err)
sendJSONResponse(w, map[string]string{"output": output.String()})
return
}

tMsgs, err := tester.Transform(ctx, sMsgs...)
if err != nil {
output.WriteString("?\t[config error]\n")
fmt.Fprintf(&output, "transform error: %v\n", err)
sendJSONResponse(w, map[string]string{"output": output.String()})
return
}
Expand All @@ -236,7 +236,7 @@ func handleTest(w http.ResponseWriter, r *http.Request) {

ok, err := cnd.Condition(ctx, msg)
if err != nil {
output.WriteString("?\t[test error]\n")
fmt.Fprintf(&output, "test error: %v\n", err)
sendJSONResponse(w, map[string]string{"output": output.String()})
return
}
Expand Down
20 changes: 10 additions & 10 deletions cmd/substation/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func testFile(arg string, extVars map[string]string) error {
mem, err := compileFile(arg, extVars)
if err != nil {
fmt.Printf("?\t%s\t[config error]\n", arg)
fmt.Fprintf(os.Stderr, " %v\n", err)

//nolint:nilerr // errors should not disrupt the test.
return nil
}

Expand Down Expand Up @@ -238,9 +238,9 @@ func testFile(arg string, extVars map[string]string) error {
// cnd asserts that the test is successful.
cnd, err := condition.New(ctx, test.Condition)
if err != nil {
fmt.Printf("FAIL\t%s\t[test error]\n", arg)
fmt.Printf("FAIL\t%s\t[test condition error]\n", arg)
fmt.Fprintf(os.Stderr, " %v\n", err)

//nolint:nilerr // errors should not disrupt the test.
return nil
}

Expand All @@ -249,9 +249,9 @@ func testFile(arg string, extVars map[string]string) error {
Transforms: test.Transforms,
})
if err != nil {
fmt.Printf("?\t%s\t[test error]\n", arg)
fmt.Printf("?\t%s\t[test config error]\n", arg)
fmt.Fprintf(os.Stderr, " %v\n", err)

//nolint:nilerr // errors should not disrupt the test.
return nil
}

Expand All @@ -261,23 +261,23 @@ func testFile(arg string, extVars map[string]string) error {
tester, err := substation.New(ctx, cfg.Config)
if err != nil {
fmt.Printf("?\t%s\t[config error]\n", arg)
fmt.Fprintf(os.Stderr, " %v\n", err)

//nolint:nilerr // errors should not disrupt the test.
return nil
}

sMsgs, err := setup.Transform(ctx, message.New().AsControl())
if err != nil {
fmt.Printf("?\t%s\t[test.transform error]\n", arg)
fmt.Fprintf(os.Stderr, "\t\t%v\n", err)
fmt.Fprintf(os.Stderr, " %v\n", err)

return nil
}

tMsgs, err := tester.Transform(ctx, sMsgs...)
if err != nil {
fmt.Printf("?\t%s\t[transform error]\n", arg)
fmt.Fprintf(os.Stderr, "\t\t%v\n", err)
fmt.Fprintf(os.Stderr, " %v\n", err)

return nil
}
Expand All @@ -290,9 +290,9 @@ func testFile(arg string, extVars map[string]string) error {

ok, err := cnd.Condition(ctx, msg)
if err != nil {
fmt.Printf("?\t%s\t[test error]\n", arg)
fmt.Printf("?\t%s\t[test condition error]\n", arg)
fmt.Fprintf(os.Stderr, " %v\n", err)

//nolint:nilerr // errors should not disrupt the test.
return nil
}

Expand Down

0 comments on commit f061ca2

Please sign in to comment.