|
4 | 4 | package formatter |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "reflect" |
8 | 7 | "testing" |
| 8 | + |
| 9 | + "gotest.tools/v3/assert" |
| 10 | + is "gotest.tools/v3/assert/cmp" |
9 | 11 | ) |
10 | 12 |
|
11 | 13 | type dummy struct{} |
@@ -45,24 +47,18 @@ var dummyExpected = map[string]any{ |
45 | 47 | func TestMarshalMap(t *testing.T) { |
46 | 48 | d := dummy{} |
47 | 49 | m, err := marshalMap(&d) |
48 | | - if err != nil { |
49 | | - t.Fatal(err) |
50 | | - } |
51 | | - if !reflect.DeepEqual(dummyExpected, m) { |
52 | | - t.Fatalf("expected %+v, got %+v", |
53 | | - dummyExpected, m) |
54 | | - } |
| 50 | + assert.NilError(t, err) |
| 51 | + assert.Check(t, is.DeepEqual(m, dummyExpected)) |
55 | 52 | } |
56 | 53 |
|
57 | 54 | func TestMarshalMapBad(t *testing.T) { |
58 | | - if _, err := marshalMap(nil); err == nil { |
59 | | - t.Fatal("expected an error (argument is nil)") |
60 | | - } |
61 | | - if _, err := marshalMap(dummy{}); err == nil { |
62 | | - t.Fatal("expected an error (argument is non-pointer)") |
63 | | - } |
| 55 | + _, err := marshalMap(nil) |
| 56 | + assert.Check(t, is.Error(err, "expected a pointer to a struct, got invalid"), "expected an error (argument is nil)") |
| 57 | + |
| 58 | + _, err = marshalMap(dummy{}) |
| 59 | + assert.Check(t, is.Error(err, "expected a pointer to a struct, got struct"), "expected an error (argument is non-pointer)") |
| 60 | + |
64 | 61 | x := 42 |
65 | | - if _, err := marshalMap(&x); err == nil { |
66 | | - t.Fatal("expected an error (argument is a pointer to non-struct)") |
67 | | - } |
| 62 | + _, err = marshalMap(&x) |
| 63 | + assert.Check(t, is.Error(err, "expected a pointer to a struct, got a pointer to int"), "expected an error (argument is a pointer to non-struct)") |
68 | 64 | } |
0 commit comments