From 1efd11f651467f880ed64568e2791c434504c88f Mon Sep 17 00:00:00 2001 From: Stephen Kirby Date: Fri, 29 Sep 2023 16:31:32 +0000 Subject: [PATCH] tests WIP --- coder-login/main.test.ts | 31 +++++++++++++++++++++++++++++++ coder-login/run.sh | 12 +++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 coder-login/main.test.ts diff --git a/coder-login/main.test.ts b/coder-login/main.test.ts new file mode 100644 index 0000000..88f12b7 --- /dev/null +++ b/coder-login/main.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, it } from "bun:test"; +import { + executeScriptInContainer, + runTerraformApply, + runTerraformInit, + testRequiredVariables, +} from "../test"; + +describe("git-clone", async () => { + await runTerraformInit(import.meta.dir); + + testRequiredVariables(import.meta.dir, { + agent_id: "foo", + }); + + it("runs with default", async () => { + const state = await runTerraformApply(import.meta.dir, { + agent_id: "foo", + }); + const output = await executeScriptInContainer(state, "alpine"); + // expect(output.exitCode).toBe(0); + expect(output.stderr).toEqual([ + "" + ]); + expect(output.stdout).toEqual([ + "Authenticating with Coder...", + "", + "" + ]); + }); +}); diff --git a/coder-login/run.sh b/coder-login/run.sh index 3fc1b04..0f6588d 100644 --- a/coder-login/run.sh +++ b/coder-login/run.sh @@ -3,14 +3,16 @@ # Automatically authenticate the user if they are not # logged in to another deployment -echo "Logging into Coder..." +CODER_DEPLOYMENT_URL=("${CODER_DEPLOYMENT_URL}") +CODER_USER_TOKEN=("${CODER_USER_TOKEN}") +RESET='\033[0m' +BOLD='\033[0;1m' + +printf "$${BOLD}Logging into Coder...\n\n$${RESET}" -echo "SESSION TOKEN : ${CODER_USER_TOKEN}" -echo "DEPLOYMENT URL: ${CODER_DEPLOYMENT_URL}" -echo "" if ! coder list >/dev/null 2>&1; then set +x; coder login --token="${CODER_USER_TOKEN}" --url="${CODER_DEPLOYMENT_URL}" else - echo "You are already authenticated with coder" + echo "You are already authenticated with coder." fi