(t *testing.T)
| 130 | } |
| 131 | |
| 132 | func TestWebsocketCloseMsg(t *testing.T) { |
| 133 | t.Parallel() |
| 134 | |
| 135 | t.Run("Sprintf", func(t *testing.T) { |
| 136 | t.Parallel() |
| 137 | |
| 138 | var ( |
| 139 | msg = "this is my message %q %q" |
| 140 | opts = []any{"colin", "kyle"} |
| 141 | ) |
| 142 | |
| 143 | expected := fmt.Sprintf(msg, opts...) |
| 144 | got := httpapi.WebsocketCloseSprintf(msg, opts...) |
| 145 | assert.Equal(t, expected, got) |
| 146 | }) |
| 147 | |
| 148 | t.Run("TruncateSingleByteCharacters", func(t *testing.T) { |
| 149 | t.Parallel() |
| 150 | |
| 151 | msg := strings.Repeat("d", 255) |
| 152 | trunc := httpapi.WebsocketCloseSprintf("%s", msg) |
| 153 | assert.Equal(t, len(trunc), 123) |
| 154 | }) |
| 155 | |
| 156 | t.Run("TruncateMultiByteCharacters", func(t *testing.T) { |
| 157 | t.Parallel() |
| 158 | |
| 159 | msg := strings.Repeat("こんにちは", 10) |
| 160 | trunc := httpapi.WebsocketCloseSprintf("%s", msg) |
| 161 | assert.Equal(t, len(trunc), 123) |
| 162 | }) |
| 163 | } |
| 164 | |
| 165 | // Our WebSocket library accepts any arbitrary ResponseWriter at the type level, |
| 166 | // but the writer must also implement http.Hijacker for long-lived connections. |
nothing calls this directly
no test coverage detected