Skip to content

Commit e241f7c

Browse files
committed
fix: json_converter_test now use a consistent assertion style
1 parent f7f079a commit e241f7c

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

listener/apischema/json_converter_test.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"errors"
66
"strings"
77
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
811
)
912

1013
// TestConvertJSON_InvalidInput tests the ConvertJSON function with invalid input.
@@ -77,34 +80,27 @@ func TestConvertJSON(t *testing.T) {
7780
raw = []byte(in)
7881
default:
7982
raw, err = json.Marshal(in)
80-
if err != nil {
81-
t.Fatalf("failed to marshal input %s: %v", tc.name, err)
82-
}
83+
require.NoError(t, err, "failed to marshal input %s", tc.name)
8384
}
8485
out, err := ConvertJSON(raw)
8586
if tc.wantErr != nil {
86-
if err == nil || !errors.Is(err, tc.wantErr) {
87-
t.Fatalf("%s: expected error %v, got %v", tc.name, tc.wantErr, err)
88-
}
87+
assert.ErrorIs(t, err, tc.wantErr, "error mismatch")
8988
return
9089
}
91-
if err != nil {
92-
t.Fatalf("%s: unexpected error: %v", tc.name, err)
93-
}
90+
assert.NoError(t, err, "unexpected error")
9491
var w v2RootWrapper
95-
if err := json.Unmarshal(out, &w); err != nil {
96-
t.Fatalf("%s: failed to unmarshal output: %v", tc.name, err)
97-
}
92+
err = json.Unmarshal(out, &w)
93+
require.NoErrorf(t, err, "%s: failed to unmarshal output", tc.name)
94+
9895
if tc.check != nil {
9996
defs := map[string]map[string]any{}
10097
for k, v := range w.Definitions {
10198
if m, ok := v.(map[string]any); ok {
10299
defs[k] = m
103100
}
104101
}
105-
if err := tc.check(defs); err != nil {
106-
t.Errorf("%s: check failed: %v", tc.name, err)
107-
}
102+
err := tc.check(defs)
103+
assert.NoErrorf(t, err, "%s: check failed", tc.name)
108104
}
109105
})
110106
}

0 commit comments

Comments
 (0)