|
1 | | -import { ContainerInitialization } from "../src/types/worker"; |
2 | 1 | import JobWorker from "../src/worker"; |
3 | 2 |
|
4 | 3 | describe("Docker initialization test", () => { |
5 | 4 | it("should create a python container", async () => { |
6 | 5 | const worker = new JobWorker("python3", { code: "", functionName: "" }); |
7 | | - worker |
8 | | - .createContainer() |
9 | | - .then(({ error, containerID }) => { |
10 | | - expect(error).toBe(false); |
11 | | - expect(containerID).toBeTruthy; |
12 | | - worker.removeContainer(); |
13 | | - }) |
14 | | - .catch((_) => {}); |
| 6 | + const { error, containerID } = await worker.createContainer() |
| 7 | + expect(error).toBe(false); |
| 8 | + expect(containerID).toBeTruthy; |
| 9 | + await worker.removeContainer(); |
15 | 10 | }); |
16 | 11 |
|
17 | 12 | // TODO write a tast case for writeFile() & copyContext |
18 | 13 |
|
19 | 14 | it("should not create a container", async () => { |
20 | | - const worker = new JobWorker("invalidName" as any, { |
21 | | - code: "", |
22 | | - functionName: "", |
23 | | - }); |
24 | | - worker |
25 | | - .createContainer() |
26 | | - .catch( |
27 | | - ({ error, containerID, errorMessage }: ContainerInitialization) => { |
28 | | - expect(error).toBe(true); |
29 | | - expect(containerID).toBeFalsy(); |
30 | | - expect(errorMessage).toBeTruthy(); |
31 | | - } |
32 | | - ); |
| 15 | + const worker = new JobWorker("invalidName" as any, { code: "", functionName: ""}); |
| 16 | + expect.assertions(3); |
| 17 | + try { |
| 18 | + await worker.createContainer() |
| 19 | + } catch ({ error, containerID, errorMessage }: any) { |
| 20 | + expect(error).toBe(true); |
| 21 | + expect(containerID).toBeFalsy(); |
| 22 | + expect(errorMessage).toBe("Invalid language name."); |
| 23 | + } |
33 | 24 | }); |
34 | 25 |
|
35 | 26 |
|
36 | 27 | it("should not initialize a container", async () => { |
37 | 28 | const worker = new JobWorker("invalidName" as any, { code: "print('Hello World!')", functionName: "" }); |
38 | | - worker |
39 | | - .initContainer() |
40 | | - .then(({ error, message }) => { |
41 | | - expect(error).toBe(false); |
42 | | - expect(message).toBe("Job has succedded."); |
43 | | - worker.cleanupJob(); |
44 | | - }) |
45 | | - .catch((_) => {}); |
| 29 | + expect.assertions(2); |
| 30 | + try { |
| 31 | + await worker.initContainer() |
| 32 | + } catch ({ error, message }: any) { |
| 33 | + expect(error).toEqual(true) |
| 34 | + expect(message).toEqual("Invalid language name.") |
| 35 | + } |
46 | 36 | }); |
47 | 37 |
|
48 | 38 | it("should initialize a python container with code in it", async () => { |
49 | 39 | const worker = new JobWorker("python3", { code: "print('Hello World!')", functionName: "" }); |
50 | | - worker |
51 | | - .initContainer() |
52 | | - .then(({ error, message }) => { |
53 | | - expect(error).toBe(false) |
54 | | - expect(message).toBeTruthy; |
55 | | - expect(message).toBe("Job has succedded."); |
56 | | - worker.cleanupJob(); |
57 | | - }) |
58 | | - .catch((_) => {}); |
| 40 | + const { error, message } = await worker.initContainer() |
| 41 | + expect(error).toBe(false) |
| 42 | + expect(message).toBe("Job has succeeded."); |
| 43 | + worker.cleanupJob(); |
59 | 44 | }); |
60 | 45 | }); |
0 commit comments