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