mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 07:31:24 +00:00
refactor(test): reuse env snapshots in gateway call tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
|
|
||||||
const loadConfig = vi.fn();
|
const loadConfig = vi.fn();
|
||||||
const resolveGatewayPort = vi.fn();
|
const resolveGatewayPort = vi.fn();
|
||||||
@@ -331,7 +332,10 @@ describe("callGateway error details", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("callGateway url override auth requirements", () => {
|
describe("callGateway url override auth requirements", () => {
|
||||||
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv(["OPENCLAW_GATEWAY_TOKEN", "OPENCLAW_GATEWAY_PASSWORD"]);
|
||||||
loadConfig.mockReset();
|
loadConfig.mockReset();
|
||||||
resolveGatewayPort.mockReset();
|
resolveGatewayPort.mockReset();
|
||||||
pickPrimaryTailnetIPv4.mockReset();
|
pickPrimaryTailnetIPv4.mockReset();
|
||||||
@@ -345,8 +349,7 @@ describe("callGateway url override auth requirements", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
envSnapshot.restore();
|
||||||
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws when url override is set without explicit credentials", async () => {
|
it("throws when url override is set without explicit credentials", async () => {
|
||||||
@@ -366,9 +369,10 @@ describe("callGateway url override auth requirements", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("callGateway password resolution", () => {
|
describe("callGateway password resolution", () => {
|
||||||
const originalEnvPassword = process.env.OPENCLAW_GATEWAY_PASSWORD;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv(["OPENCLAW_GATEWAY_PASSWORD"]);
|
||||||
loadConfig.mockReset();
|
loadConfig.mockReset();
|
||||||
resolveGatewayPort.mockReset();
|
resolveGatewayPort.mockReset();
|
||||||
pickPrimaryTailnetIPv4.mockReset();
|
pickPrimaryTailnetIPv4.mockReset();
|
||||||
@@ -383,11 +387,7 @@ describe("callGateway password resolution", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (originalEnvPassword == null) {
|
envSnapshot.restore();
|
||||||
delete process.env.OPENCLAW_GATEWAY_PASSWORD;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_GATEWAY_PASSWORD = originalEnvPassword;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses local config password when env is unset", async () => {
|
it("uses local config password when env is unset", async () => {
|
||||||
@@ -468,9 +468,10 @@ describe("callGateway password resolution", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("callGateway token resolution", () => {
|
describe("callGateway token resolution", () => {
|
||||||
const originalEnvToken = process.env.OPENCLAW_GATEWAY_TOKEN;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv(["OPENCLAW_GATEWAY_TOKEN"]);
|
||||||
loadConfig.mockReset();
|
loadConfig.mockReset();
|
||||||
resolveGatewayPort.mockReset();
|
resolveGatewayPort.mockReset();
|
||||||
pickPrimaryTailnetIPv4.mockReset();
|
pickPrimaryTailnetIPv4.mockReset();
|
||||||
@@ -485,11 +486,7 @@ describe("callGateway token resolution", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (originalEnvToken == null) {
|
envSnapshot.restore();
|
||||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_GATEWAY_TOKEN = originalEnvToken;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses explicit token when url override is set", async () => {
|
it("uses explicit token when url override is set", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user