|
| 1 | +import { |
| 2 | + getContainersByAppNameMatch, |
| 3 | + getStackContainersByAppName, |
| 4 | +} from "@dokploy/server/services/docker"; |
| 5 | +import { |
| 6 | + execAsync, |
| 7 | + execAsyncRemote, |
| 8 | +} from "@dokploy/server/utils/process/execAsync"; |
| 9 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 10 | + |
| 11 | +vi.mock("@dokploy/server/utils/process/execAsync", async (importOriginal) => ({ |
| 12 | + ...(await importOriginal< |
| 13 | + typeof import("@dokploy/server/utils/process/execAsync") |
| 14 | + >()), |
| 15 | + execAsync: vi.fn(), |
| 16 | + execAsyncRemote: vi.fn(), |
| 17 | +})); |
| 18 | + |
| 19 | +const execAsyncMock = vi.mocked(execAsync); |
| 20 | +const execAsyncRemoteMock = vi.mocked(execAsyncRemote); |
| 21 | + |
| 22 | +describe("stack container lookup results", () => { |
| 23 | + beforeEach(() => { |
| 24 | + vi.resetAllMocks(); |
| 25 | + }); |
| 26 | + |
| 27 | + it("returns undefined when the native stack lookup fails", async () => { |
| 28 | + execAsyncMock.mockRejectedValueOnce(new Error("Docker is unavailable")); |
| 29 | + |
| 30 | + await expect( |
| 31 | + getContainersByAppNameMatch("farmgate-odoo", "stack"), |
| 32 | + ).resolves.toBeUndefined(); |
| 33 | + }); |
| 34 | + |
| 35 | + it("returns an empty list for a successful native lookup with no tasks", async () => { |
| 36 | + execAsyncMock.mockResolvedValueOnce({ stdout: "", stderr: "" }); |
| 37 | + |
| 38 | + await expect( |
| 39 | + getContainersByAppNameMatch("farmgate-odoo", "stack"), |
| 40 | + ).resolves.toEqual([]); |
| 41 | + }); |
| 42 | + |
| 43 | + it("returns undefined when the remote native stack lookup fails", async () => { |
| 44 | + execAsyncRemoteMock.mockRejectedValueOnce(new Error("SSH is unavailable")); |
| 45 | + |
| 46 | + await expect( |
| 47 | + getContainersByAppNameMatch("farmgate-odoo", "stack", "server-1"), |
| 48 | + ).resolves.toBeUndefined(); |
| 49 | + }); |
| 50 | + |
| 51 | + it("returns undefined when the Swarm stack lookup reports an error", async () => { |
| 52 | + execAsyncRemoteMock.mockResolvedValueOnce({ |
| 53 | + stdout: "", |
| 54 | + stderr: "node is unavailable", |
| 55 | + }); |
| 56 | + |
| 57 | + await expect( |
| 58 | + getStackContainersByAppName("farmgate-odoo", "server-1"), |
| 59 | + ).resolves.toBeUndefined(); |
| 60 | + }); |
| 61 | + |
| 62 | + it("returns an empty list for a successful Swarm lookup with no tasks", async () => { |
| 63 | + execAsyncMock.mockResolvedValueOnce({ stdout: "", stderr: "" }); |
| 64 | + |
| 65 | + await expect(getStackContainersByAppName("farmgate-odoo")).resolves.toEqual( |
| 66 | + [], |
| 67 | + ); |
| 68 | + }); |
| 69 | +}); |
0 commit comments