|
1 | 1 | import { logger } from "@coder/logger"
|
2 | 2 | import * as http from "http"
|
3 |
| -import { createApp, ensureAddress, handleServerError } from "../../../src/node/app" |
| 3 | +import { createApp, ensureAddress, handleArgsSocketCatchError, handleServerError } from "../../../src/node/app" |
4 | 4 | import { setDefaults } from "../../../src/node/cli"
|
5 | 5 | import { getAvailablePort } from "../../utils/helpers"
|
6 | 6 |
|
@@ -167,10 +167,75 @@ describe("handleServerError", () => {
|
167 | 167 |
|
168 | 168 | // make the socket on the file path and i'll get that..
|
169 | 169 |
|
170 |
| -// pass in / into |
171 | 170 | // create a directory and pass that in as the socket
|
172 | 171 | // with one file and use the directory as the socket path
|
173 | 172 |
|
174 | 173 | // The other thing I can do is mock fs.unlink
|
175 | 174 | // and make it throw an error
|
176 |
| -// Stopped |
| 175 | +// Stopped |
| 176 | + |
| 177 | +describe("handleArgsSocketCatchError", () => { |
| 178 | + let spy: jest.SpyInstance |
| 179 | + |
| 180 | + beforeEach(() => { |
| 181 | + spy = jest.spyOn(logger, "error") |
| 182 | + }) |
| 183 | + |
| 184 | + afterEach(() => { |
| 185 | + jest.clearAllMocks() |
| 186 | + }) |
| 187 | + |
| 188 | + afterAll(() => { |
| 189 | + jest.restoreAllMocks() |
| 190 | + }) |
| 191 | + |
| 192 | + it("should log an error if its not an isNodeJSErrnoException", () => { |
| 193 | + const error = new Error() |
| 194 | + |
| 195 | + handleArgsSocketCatchError(error) |
| 196 | + |
| 197 | + expect(spy).toHaveBeenCalledTimes(1) |
| 198 | + expect(spy).toHaveBeenCalledWith(error) |
| 199 | + }) |
| 200 | + |
| 201 | + it("should log an error if its not an isNodeJSErrnoException (and the error has a message)", () => { |
| 202 | + const errorMessage = "handleArgsSocketCatchError Error" |
| 203 | + const error = new Error(errorMessage) |
| 204 | + |
| 205 | + handleArgsSocketCatchError(error) |
| 206 | + |
| 207 | + expect(spy).toHaveBeenCalledTimes(1) |
| 208 | + expect(spy).toHaveBeenCalledWith(errorMessage) |
| 209 | + }) |
| 210 | + |
| 211 | + it("should not log an error if its a isNodeJSErrnoException", () => { |
| 212 | + const error: NodeJS.ErrnoException = new Error() |
| 213 | + error.code = "ENOENT" |
| 214 | + |
| 215 | + handleArgsSocketCatchError(error) |
| 216 | + |
| 217 | + expect(spy).toHaveBeenCalledTimes(0) |
| 218 | + }) |
| 219 | + |
| 220 | + it("should log an error if the code is not ENOENT (and the error has a message)", () => { |
| 221 | + const errorMessage = "no access" |
| 222 | + const error: NodeJS.ErrnoException = new Error() |
| 223 | + error.code = "EACCESS" |
| 224 | + error.message = errorMessage |
| 225 | + |
| 226 | + handleArgsSocketCatchError(error) |
| 227 | + |
| 228 | + expect(spy).toHaveBeenCalledTimes(1) |
| 229 | + expect(spy).toHaveBeenCalledWith(errorMessage) |
| 230 | + }) |
| 231 | + |
| 232 | + it("should log an error if the code is not ENOENT", () => { |
| 233 | + const error: NodeJS.ErrnoException = new Error() |
| 234 | + error.code = "EACCESS" |
| 235 | + |
| 236 | + handleArgsSocketCatchError(error) |
| 237 | + |
| 238 | + expect(spy).toHaveBeenCalledTimes(1) |
| 239 | + expect(spy).toHaveBeenCalledWith(error) |
| 240 | + }) |
| 241 | +}) |
0 commit comments