|
4 | 4 | "bytes"
|
5 | 5 | "context"
|
6 | 6 | "encoding/json"
|
| 7 | + "fmt" |
7 | 8 | "net/http"
|
8 | 9 | "net/http/httptest"
|
9 | 10 | "strings"
|
@@ -122,22 +123,35 @@ func TestRead(t *testing.T) {
|
122 | 123 | })
|
123 | 124 | }
|
124 | 125 |
|
125 |
| -func WebsocketCloseMsg(t *testing.T) { |
| 126 | +func TestWebsocketCloseMsg(t *testing.T) { |
126 | 127 | t.Parallel()
|
127 | 128 |
|
| 129 | + t.Run("Sprintf", func(t *testing.T) { |
| 130 | + t.Parallel() |
| 131 | + |
| 132 | + var ( |
| 133 | + msg = "this is my message %q %q" |
| 134 | + opts = []any{"colin", "kyle"} |
| 135 | + ) |
| 136 | + |
| 137 | + expected := fmt.Sprintf(msg, opts...) |
| 138 | + got := httpapi.WebsocketCloseSprintf(msg, opts...) |
| 139 | + assert.Equal(t, expected, got) |
| 140 | + }) |
| 141 | + |
128 | 142 | t.Run("TruncateSingleByteCharacters", func(t *testing.T) {
|
129 | 143 | t.Parallel()
|
130 | 144 |
|
131 | 145 | msg := strings.Repeat("d", 255)
|
132 | 146 | trunc := httpapi.WebsocketCloseSprintf(msg)
|
133 |
| - assert.LessOrEqual(t, len(trunc), 123) |
| 147 | + assert.Equal(t, len(trunc), 123) |
134 | 148 | })
|
135 | 149 |
|
136 | 150 | t.Run("TruncateMultiByteCharacters", func(t *testing.T) {
|
137 | 151 | t.Parallel()
|
138 | 152 |
|
139 | 153 | msg := strings.Repeat("こんにちは", 10)
|
140 | 154 | trunc := httpapi.WebsocketCloseSprintf(msg)
|
141 |
| - assert.LessOrEqual(t, len(trunc), 123) |
| 155 | + assert.Equal(t, len(trunc), 123) |
142 | 156 | })
|
143 | 157 | }
|
0 commit comments