refactor(test): reuse env helper in gateway status e2e
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { withEnvAsync } from "../test-utils/env.js";
|
||||
|
||||
const loadConfig = vi.fn(() => ({
|
||||
gateway: {
|
||||
@@ -133,16 +134,6 @@ function createRuntimeCapture() {
|
||||
return { runtime, runtimeLogs, runtimeErrors };
|
||||
}
|
||||
|
||||
async function withUserEnv(user: string, fn: () => Promise<void>) {
|
||||
const originalUser = process.env.USER;
|
||||
try {
|
||||
process.env.USER = user;
|
||||
await fn();
|
||||
} finally {
|
||||
process.env.USER = originalUser;
|
||||
}
|
||||
}
|
||||
|
||||
describe("gateway-status command", () => {
|
||||
it("prints human output by default", async () => {
|
||||
const { runtime, runtimeLogs, runtimeErrors } = createRuntimeCapture();
|
||||
@@ -206,7 +197,7 @@ describe("gateway-status command", () => {
|
||||
|
||||
it("skips invalid ssh-auto discovery targets", async () => {
|
||||
const { runtime } = createRuntimeCapture();
|
||||
await withUserEnv("steipete", async () => {
|
||||
await withEnvAsync({ USER: "steipete" }, async () => {
|
||||
loadConfig.mockReturnValueOnce({
|
||||
gateway: {
|
||||
mode: "remote",
|
||||
@@ -234,7 +225,7 @@ describe("gateway-status command", () => {
|
||||
|
||||
it("infers SSH target from gateway.remote.url and ssh config", async () => {
|
||||
const { runtime } = createRuntimeCapture();
|
||||
await withUserEnv("steipete", async () => {
|
||||
await withEnvAsync({ USER: "steipete" }, async () => {
|
||||
loadConfig.mockReturnValueOnce({
|
||||
gateway: {
|
||||
mode: "remote",
|
||||
@@ -268,7 +259,7 @@ describe("gateway-status command", () => {
|
||||
|
||||
it("falls back to host-only when USER is missing and ssh config is unavailable", async () => {
|
||||
const { runtime } = createRuntimeCapture();
|
||||
await withUserEnv("", async () => {
|
||||
await withEnvAsync({ USER: "" }, async () => {
|
||||
loadConfig.mockReturnValueOnce({
|
||||
gateway: {
|
||||
mode: "remote",
|
||||
|
||||
Reference in New Issue
Block a user