mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-10-15 13:21:11 +00:00
fix: preserve stack log selection on fetch failures
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import {
|
||||
getContainersByAppNameMatch,
|
||||
getStackContainersByAppName,
|
||||
} from "@dokploy/server/services/docker";
|
||||
import {
|
||||
execAsync,
|
||||
execAsyncRemote,
|
||||
} from "@dokploy/server/utils/process/execAsync";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@dokploy/server/utils/process/execAsync", async (importOriginal) => ({
|
||||
...(await importOriginal<
|
||||
typeof import("@dokploy/server/utils/process/execAsync")
|
||||
>()),
|
||||
execAsync: vi.fn(),
|
||||
execAsyncRemote: vi.fn(),
|
||||
}));
|
||||
|
||||
const execAsyncMock = vi.mocked(execAsync);
|
||||
const execAsyncRemoteMock = vi.mocked(execAsyncRemote);
|
||||
|
||||
describe("stack container lookup results", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it("returns undefined when the native stack lookup fails", async () => {
|
||||
execAsyncMock.mockRejectedValueOnce(new Error("Docker is unavailable"));
|
||||
|
||||
await expect(
|
||||
getContainersByAppNameMatch("farmgate-odoo", "stack"),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns an empty list for a successful native lookup with no tasks", async () => {
|
||||
execAsyncMock.mockResolvedValueOnce({ stdout: "", stderr: "" });
|
||||
|
||||
await expect(
|
||||
getContainersByAppNameMatch("farmgate-odoo", "stack"),
|
||||
).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
it("returns undefined when the remote native stack lookup fails", async () => {
|
||||
execAsyncRemoteMock.mockRejectedValueOnce(new Error("SSH is unavailable"));
|
||||
|
||||
await expect(
|
||||
getContainersByAppNameMatch("farmgate-odoo", "stack", "server-1"),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns undefined when the Swarm stack lookup reports an error", async () => {
|
||||
execAsyncRemoteMock.mockResolvedValueOnce({
|
||||
stdout: "",
|
||||
stderr: "node is unavailable",
|
||||
});
|
||||
|
||||
await expect(
|
||||
getStackContainersByAppName("farmgate-odoo", "server-1"),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns an empty list for a successful Swarm lookup with no tasks", async () => {
|
||||
execAsyncMock.mockResolvedValueOnce({ stdout: "", stderr: "" });
|
||||
|
||||
await expect(getStackContainersByAppName("farmgate-odoo")).resolves.toEqual(
|
||||
[],
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -167,7 +167,7 @@ export const getContainersByAppNameMatch = async (
|
||||
return containers || [];
|
||||
} catch {}
|
||||
|
||||
return [];
|
||||
return appType === "stack" ? undefined : [];
|
||||
};
|
||||
|
||||
const getStackTaskContainers = async (appName: string, serverId?: string) => {
|
||||
@@ -227,7 +227,7 @@ const getStackTaskContainers = async (appName: string, serverId?: string) => {
|
||||
return containers;
|
||||
} catch {}
|
||||
|
||||
return [];
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const getStackContainersByAppName = async (
|
||||
@@ -243,7 +243,7 @@ export const getStackContainersByAppName = async (
|
||||
const { stdout, stderr } = await execAsyncRemote(serverId, command);
|
||||
|
||||
if (stderr) {
|
||||
return [];
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!stdout) return [];
|
||||
@@ -252,7 +252,7 @@ export const getStackContainersByAppName = async (
|
||||
const { stdout, stderr } = await execAsync(command);
|
||||
|
||||
if (stderr) {
|
||||
return [];
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!stdout) return [];
|
||||
@@ -292,7 +292,7 @@ export const getStackContainersByAppName = async (
|
||||
return containers || [];
|
||||
} catch {}
|
||||
|
||||
return [];
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const getServiceContainersByAppName = async (
|
||||
|
||||
Reference in New Issue
Block a user