|
1 |
| -// import * as assert from "assert" |
| 1 | +import * as assert from "assert" |
| 2 | +import { promises as fs } from "fs" |
| 3 | +import * as path from "path" |
2 | 4 | import * as vscode from "vscode"
|
3 |
| -// import * as auth from "./download" |
| 5 | +import * as auth from "./auth" |
| 6 | +import * as utils from "./utils" |
4 | 7 |
|
5 | 8 | suite("Authenticate", () => {
|
6 | 9 | vscode.window.showInformationMessage("Start authenticate tests.")
|
7 | 10 |
|
8 |
| - // TODO: Implement. |
9 |
| - test("authenticate") |
| 11 | + const tmpPath = "tests/auth" |
| 12 | + suiteSetup(async () => { |
| 13 | + // Cleanup anything left over from the last run. |
| 14 | + await utils.clean(tmpPath) |
| 15 | + }) |
| 16 | + |
| 17 | + teardown(() => utils.resetEnv()) |
| 18 | + |
| 19 | + const assertDirs = (dir: string) => { |
| 20 | + assert.match(auth.getConfigDir("linux"), new RegExp(path.join(dir, ".config$"))) |
| 21 | + assert.match(auth.getConfigDir("freebsd"), new RegExp(path.join(dir, ".config$"))) |
| 22 | + assert.match(auth.getConfigDir("win32"), new RegExp(path.join(dir, "AppData/Roaming$"))) |
| 23 | + assert.match(auth.getConfigDir("darwin"), new RegExp(path.join(dir, "Library/Application Support$"))) |
| 24 | + } |
| 25 | + |
| 26 | + test("getConfigDir", async () => { |
| 27 | + // Make sure local config mocks work. |
| 28 | + const tmpDir = await utils.tmpdir(tmpPath) |
| 29 | + utils.setEnv("HOME", tmpDir) |
| 30 | + assertDirs(tmpDir) |
| 31 | + |
| 32 | + // Make sure the global mock also works. For example the Linux temp config |
| 33 | + // directory looks like: /tmp/coder/tests/config/tmp-Dzfqwl/home/.config |
| 34 | + // This runs after the local mock to make sure environment variables are |
| 35 | + // being restored correctly. |
| 36 | + utils.resetEnv() |
| 37 | + assertDirs("tests/config/.+/home") |
| 38 | + }) |
| 39 | + |
| 40 | + test("currentUri", async () => { |
| 41 | + const tmpDir = await utils.tmpdir(tmpPath) |
| 42 | + utils.setEnv("HOME", tmpDir) |
| 43 | + |
| 44 | + const accessUri = "https://coder-workspaces-test" |
| 45 | + assert.strictEqual(await auth.currentUri(), undefined) |
| 46 | + const dir = path.join(auth.getConfigDir(), "coder") |
| 47 | + await fs.mkdir(dir, { recursive: true }) |
| 48 | + await fs.writeFile(path.join(dir, "url"), accessUri) |
| 49 | + assert.strictEqual(await auth.currentUri(), accessUri) |
| 50 | + }) |
10 | 51 | })
|
0 commit comments