Add PreparedRun model and render formatters (text/json) with tests
This commit is contained in:
41
internal/format/prepared_run_test.go
Normal file
41
internal/format/prepared_run_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package format
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParsePreparedRunOutputFormatRecognizesSupportedNames(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want PreparedRunOutputFormat
|
||||
}{
|
||||
{name: "default empty", input: "", want: DefaultPreparedRunOutputFormat},
|
||||
{name: "text", input: "text", want: PreparedRunFormatText},
|
||||
{name: "json", input: "json", want: PreparedRunFormatJSON},
|
||||
{name: "trim and case", input: " JSON ", want: PreparedRunFormatJSON},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := ParsePreparedRunOutputFormat(tc.input)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
if got != tc.want {
|
||||
t.Fatalf("expected %q, got %q", tc.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePreparedRunOutputFormatUnknownFails(t *testing.T) {
|
||||
_, err := ParsePreparedRunOutputFormat("yaml")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for unknown format")
|
||||
}
|
||||
if !errors.Is(err, ErrUnknownPreparedRunFormat) {
|
||||
t.Fatalf("expected ErrUnknownPreparedRunFormat, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user