|
1 | 1 | import * as os from "os"
|
2 |
| -import { it, expect } from "vitest" |
3 |
| -import { getHeaders } from "./headers" |
| 2 | +import { it, expect, describe, beforeEach, afterEach, vi } from "vitest" |
| 3 | +import { WorkspaceConfiguration } from "vscode" |
| 4 | +import { getHeaderCommand, getHeaders } from "./headers" |
4 | 5 |
|
5 | 6 | const logger = {
|
6 | 7 | writeToCoderOutputChannel() {
|
@@ -55,3 +56,49 @@ it("should have access to environment variables", async () => {
|
55 | 56 | it("should error on non-zero exit", async () => {
|
56 | 57 | await expect(getHeaders("localhost", "exit 10", logger)).rejects.toMatch(/exited unexpectedly with code 10/)
|
57 | 58 | })
|
| 59 | + |
| 60 | +describe("getHeaderCommand", () => { |
| 61 | + beforeEach(() => { |
| 62 | + vi.stubEnv("CODER_HEADER_COMMAND", "") |
| 63 | + }) |
| 64 | + |
| 65 | + afterEach(() => { |
| 66 | + vi.unstubAllEnvs() |
| 67 | + }) |
| 68 | + |
| 69 | + it("should return undefined if coder.headerCommand is not set in config", () => { |
| 70 | + const config = { |
| 71 | + get: () => undefined, |
| 72 | + } as unknown as WorkspaceConfiguration |
| 73 | + |
| 74 | + expect(getHeaderCommand(config)).toBeUndefined() |
| 75 | + }) |
| 76 | + |
| 77 | + it("should return undefined if coder.headerCommand is not a string", () => { |
| 78 | + const config = { |
| 79 | + get: () => 1234, |
| 80 | + } as unknown as WorkspaceConfiguration |
| 81 | + |
| 82 | + expect(getHeaderCommand(config)).toBeUndefined() |
| 83 | + }) |
| 84 | + |
| 85 | + it("should return coder.headerCommand if set in config", () => { |
| 86 | + vi.stubEnv("CODER_HEADER_COMMAND", "printf 'x=y'") |
| 87 | + |
| 88 | + const config = { |
| 89 | + get: () => "printf 'foo=bar'", |
| 90 | + } as unknown as WorkspaceConfiguration |
| 91 | + |
| 92 | + expect(getHeaderCommand(config)).toBe("printf 'foo=bar'") |
| 93 | + }) |
| 94 | + |
| 95 | + it("should return CODER_HEADER_COMMAND if coder.headerCommand is not set in config and CODER_HEADER_COMMAND is set in environment", () => { |
| 96 | + vi.stubEnv("CODER_HEADER_COMMAND", "printf 'x=y'") |
| 97 | + |
| 98 | + const config = { |
| 99 | + get: () => undefined, |
| 100 | + } as unknown as WorkspaceConfiguration |
| 101 | + |
| 102 | + expect(getHeaderCommand(config)).toBe("printf 'x=y'") |
| 103 | + }) |
| 104 | +}) |
0 commit comments