feat: add test framework (#48)
* Add test framework * Add aws-region tests * Add azure-region tests * Update CONTRIBUTING.md * Add formatting * Improve fmt * Format Terraform
This commit is contained in:
@@ -6,6 +6,7 @@ maintainer_github: coder
|
||||
verified: true
|
||||
tags: [git, helper]
|
||||
---
|
||||
|
||||
# Git Clone
|
||||
|
||||
This module allows you to automatically clone a repository by URL and skip if it exists in the path provided.
|
||||
|
||||
39
git-clone/main.test.ts
Normal file
39
git-clone/main.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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",
|
||||
url: "foo",
|
||||
});
|
||||
|
||||
it("fails without git", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
url: "some-url",
|
||||
});
|
||||
const output = await executeScriptInContainer(state, "alpine");
|
||||
expect(output.exitCode).toBe(1);
|
||||
expect(output.stdout).toEqual(["Git is not installed!"]);
|
||||
});
|
||||
|
||||
it("runs with git", async () => {
|
||||
const state = await runTerraformApply(import.meta.dir, {
|
||||
agent_id: "foo",
|
||||
url: "fake-url",
|
||||
});
|
||||
const output = await executeScriptInContainer(state, "alpine/git");
|
||||
expect(output.exitCode).toBe(128);
|
||||
expect(output.stdout).toEqual([
|
||||
"Creating directory ~/fake-url...",
|
||||
"Cloning fake-url to ~/fake-url...",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -10,8 +10,8 @@ terraform {
|
||||
}
|
||||
|
||||
variable "url" {
|
||||
description = "The URL of the Git repository."
|
||||
type = string
|
||||
description = "The URL of the Git repository."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "path" {
|
||||
@@ -21,17 +21,17 @@ variable "path" {
|
||||
}
|
||||
|
||||
variable "agent_id" {
|
||||
description = "The ID of a Coder agent."
|
||||
type = string
|
||||
description = "The ID of a Coder agent."
|
||||
type = string
|
||||
}
|
||||
|
||||
resource "coder_script" "git_clone" {
|
||||
agent_id = var.agent_id
|
||||
display_name = "Git Clone"
|
||||
icon = "/icons/git.svg"
|
||||
script = templatefile("${path.module}/run.sh", {
|
||||
CLONE_PATH: var.path != "" ? var.path : join("/", ["~", basename(var.url)]),
|
||||
REPO_URL: var.url,
|
||||
})
|
||||
run_on_start = true
|
||||
agent_id = var.agent_id
|
||||
display_name = "Git Clone"
|
||||
icon = "/icons/git.svg"
|
||||
script = templatefile("${path.module}/run.sh", {
|
||||
CLONE_PATH : var.path != "" ? var.path : join("/", ["~", basename(var.url)]),
|
||||
REPO_URL : var.url,
|
||||
})
|
||||
run_on_start = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user