-
Notifications
You must be signed in to change notification settings - Fork 2
/
terraform.test.js
97 lines (83 loc) · 2.76 KB
/
terraform.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import Terraform from "./terraform"
import {
runAction,
runActionExpectError,
cleanPath,
Cleaner,
Mute,
ignoreInstalled,
} from "./testutil"
Mute.all()
describe("runAction terraform", () => {
const cleaner = new Cleaner(Terraform, "tfenv")
afterEach(cleaner.clean)
it("works with terraform", async () => {
const version = "1.1.2"
const env = {
INPUT_TERRAFORM: version,
...ignoreInstalled(),
}
return runAction("index", env).then((proc) => {
expect(proc.stderr.toString()).toBe("")
expect(proc.stdout).toContain(`terraform --version: ${version}`)
expect(proc.stdout).toContain("terraform success!")
})
})
it("fails with bad TFENV_ROOT", () => {
const env = {
INPUT_TERRAFORM: "1.1.2",
TFENV_ROOT: "/tmp/.tfenv",
PATH: cleanPath("tfenv"),
...ignoreInstalled(),
}
return expect(
runActionExpectError("index", env).catch((err) => {
throw new Error(err.stdout)
}),
).rejects.toThrow(/::error::TFENV_ROOT misconfigured/)
})
})
describe("install", () => {
const cleaner = new Cleaner(Terraform, "tfenv")
afterEach(cleaner.clean)
it("works", async () => {
const root = Terraform.tempRoot()
cleaner.root = await new Terraform().install(root)
expect(cleaner.root).toMatch(/\/\.tfenv/)
})
})
describe("findRoot", () => {
const cleaner = new Cleaner(Terraform, "tfenv")
afterEach(cleaner.clean)
it("works", () => {
const tool = new Terraform()
// This is a garbage test since this will move around depending on
// environment, but at least it'll fail if there's an actual error
return expect(tool.findRoot()).resolves.toContain(tool.installer)
})
})
describe("setup", () => {
const cleaner = new Cleaner(Terraform, "tfenv")
afterEach(cleaner.clean)
it("works to install and find itself", async () => {
ignoreInstalled()
const tool = new Terraform()
const check = await tool
.subprocessShell("terraform --version")
.catch((err) => err)
if (check?.stdout?.includes(" 1.1.")) {
// This means we have terraform on the PATH and it won't install
// tfenv by default
return // success-ish
}
await tool.setup("1.1.2")
const proc = await tool.subprocessShell("tfenv --version")
expect(proc.stdout).toMatch(/^tfenv \d\.\d\.\d\n$/)
})
it("works with an override version", () => {
return new Terraform().setup("1.1.2")
})
it("is harmless if there's no versions", () => {
return new Terraform().setup()
})
})