|
8 | 8 | "strings" |
9 | 9 | "testing" |
10 | 10 |
|
11 | | - "cdr.dev/slog/sloggers/slogtest/assert" |
| 11 | + "nhooyr.io/websocket/internal/test/cmp" |
12 | 12 | ) |
13 | 13 |
|
14 | 14 | func TestCloseError(t *testing.T) { |
@@ -51,13 +51,23 @@ func TestCloseError(t *testing.T) { |
51 | 51 | t.Parallel() |
52 | 52 |
|
53 | 53 | _, err := tc.ce.bytesErr() |
54 | | - if tc.success { |
55 | | - assert.Success(t, "CloseError.bytesErr", err) |
56 | | - } else { |
57 | | - assert.Error(t, "CloseError.bytesErr", err) |
| 54 | + if tc.success != (err == nil) { |
| 55 | + t.Fatalf("unexpected error value (wanted err == nil == %v): %v", tc.success, err) |
58 | 56 | } |
59 | 57 | }) |
60 | 58 | } |
| 59 | + |
| 60 | + t.Run("Error", func(t *testing.T) { |
| 61 | + exp := `status = StatusInternalError and reason = "meow"` |
| 62 | + act := CloseError{ |
| 63 | + Code: StatusInternalError, |
| 64 | + Reason: "meow", |
| 65 | + }.Error() |
| 66 | + |
| 67 | + if (act) != exp { |
| 68 | + t.Fatal(cmp.Diff(exp, act)) |
| 69 | + } |
| 70 | + }) |
61 | 71 | } |
62 | 72 |
|
63 | 73 | func Test_parseClosePayload(t *testing.T) { |
@@ -104,10 +114,14 @@ func Test_parseClosePayload(t *testing.T) { |
104 | 114 |
|
105 | 115 | ce, err := parseClosePayload(tc.p) |
106 | 116 | if tc.success { |
107 | | - assert.Success(t, "parse err", err) |
108 | | - assert.Equal(t, "ce", tc.ce, ce) |
109 | | - } else { |
110 | | - assert.Error(t, "parse err", err) |
| 117 | + if err != nil { |
| 118 | + t.Fatal(err) |
| 119 | + } |
| 120 | + if !cmp.Equal(tc.ce, ce) { |
| 121 | + t.Fatalf("expected %v but got %v", tc.ce, ce) |
| 122 | + } |
| 123 | + } else if err == nil { |
| 124 | + t.Errorf("expected error: %v %v", ce, err) |
111 | 125 | } |
112 | 126 | }) |
113 | 127 | } |
@@ -153,7 +167,10 @@ func Test_validWireCloseCode(t *testing.T) { |
153 | 167 | t.Run(tc.name, func(t *testing.T) { |
154 | 168 | t.Parallel() |
155 | 169 |
|
156 | | - assert.Equal(t, "valid", tc.valid, validWireCloseCode(tc.code)) |
| 170 | + act := validWireCloseCode(tc.code) |
| 171 | + if !cmp.Equal(tc.valid, act) { |
| 172 | + t.Fatalf("unexpected valid: %v", cmp.Diff(tc.valid, act)) |
| 173 | + } |
157 | 174 | }) |
158 | 175 | } |
159 | 176 | } |
@@ -190,7 +207,10 @@ func TestCloseStatus(t *testing.T) { |
190 | 207 | t.Run(tc.name, func(t *testing.T) { |
191 | 208 | t.Parallel() |
192 | 209 |
|
193 | | - assert.Equal(t, "closeStatus", tc.exp, CloseStatus(tc.in)) |
| 210 | + act := CloseStatus(tc.in) |
| 211 | + if !cmp.Equal(tc.exp, act) { |
| 212 | + t.Fatalf("unexpected closeStatus: %v", cmp.Diff(tc.exp, act)) |
| 213 | + } |
194 | 214 | }) |
195 | 215 | } |
196 | 216 | } |
0 commit comments