Skip to content

Commit 9bcab3b

Browse files
author
Jason Heath
committed
Adds e2e test for hab plan cli command
Signed-off-by: Jason Heath <jason.heath@progress.com>
1 parent cb891ff commit 9bcab3b

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
Describe 'hab plan render' {
2+
3+
BeforeAll {
4+
$tempdir = New-TemporaryDirectory
5+
6+
$output = hab plan render ./test/fixtures/render/consul/config/consul_config.json `
7+
--default-toml ./test/fixtures/render/consul/default.toml `
8+
--mock-data ./test/fixtures/render/consul/override.json `
9+
--render-dir $tempdir `
10+
--user-toml ./test/fixtures/render/consul/user.toml `
11+
--print 2>&1
12+
$output | Out-Null # for PSScriptAnalyzer which can't see actual usage
13+
14+
$outfile = Join-Path -Path $tempdir consul_config.json
15+
$outfile | Out-Null # for PSScriptAnalyzer which can't see actual usage
16+
}
17+
18+
AfterAll { Remove-Item -Path $tempdir -Recurse -Force }
19+
20+
It '--print should work' {
21+
$output | Should -Not -BeNullOrEmpty
22+
}
23+
24+
It '--render-dir should work' {
25+
$outfile | Should -Exist
26+
}
27+
28+
It '--default-toml should work' {
29+
$outfile | Should -FileContentMatch 'IN_DEFAULT_TOML'
30+
}
31+
32+
It '--mock-data should work' {
33+
$outfile | Should -FileContentMatch 'IN_OVERRIDE_JSON'
34+
}
35+
36+
It '--user-toml should work' {
37+
$outfile | Should -FileContentMatch 'IN_USER_TOML'
38+
}
39+
}
40+
41+
Describe 'hab plan init' {
42+
43+
BeforeAll {
44+
$testroot = Get-Location
45+
$testroot | Out-Null # for PSScriptAnalyzer which can't see actual usage
46+
if ($IsWindows) {
47+
$plan_file = 'plan.ps1'
48+
} else {
49+
$plan_file = 'plan.sh'
50+
}
51+
$plan_file | Out-Null # for PSScriptAnalyzer which can't see actual usage
52+
# This always be just hab for committed code but if you are working
53+
# locally to extend or debug these tests then you can swap the
54+
# variables to use your locally built hab binary
55+
# $hab = Join-Path -Path $testroot target debug hab
56+
$hab = 'hab'
57+
$hab | Out-Null # for PSScriptAnalyzer which can't see actual usage
58+
}
59+
60+
BeforeEach {
61+
$tempdir = New-TemporaryDirectory
62+
Set-Location $tempdir
63+
$plan_path = Join-Path -Path $tempdir bar $plan_file
64+
$plan_path | Out-Null # for PSScriptAnalyzer which can't see actual usage
65+
}
66+
67+
AfterEach {
68+
Set-Location $testroot
69+
Remove-Item -Path $tempdir -Recurse -Force
70+
}
71+
72+
# NOTE about the tests that follow. When testing the scaffolding there was
73+
# some weirdness with string interpolation where $ needed to be escaped even
74+
# inside of a single quoted string and $ is Windows specific which we want
75+
# to smooth over anyway. So the scaffolding asserts intentionally drop '#'
76+
# and '$' to just stay away from any weirdness at all. In addition, there
77+
# was an issue in which the code was defaulting to "core/scaffolding-ruby"
78+
# even when the --scaffolding option wasn't specified so the explicit
79+
# denial of "core/scaffolding-ruby" is about making sure that defaulting
80+
# is not occuring somehow and testing "core/scaffolding-go" is about making
81+
# sure the explicit choice was exercised.
82+
83+
It 'normal plan file (scaffolding placeholder)' {
84+
Invoke-NativeCommand "$hab" plan init --origin foo bar 2>&1 | Out-Null
85+
$plan_path | Should -Exist
86+
$plan_path | Should -FileContentMatch "# This file is the heart of your application's habitat."
87+
$plan_path | Should -FileContentMatch 'pkg_scaffolding="some/scaffolding"'
88+
$plan_path | Should -Not -FileContentMatch 'pkg_scaffolding="core/scaffolding-ruby"'
89+
$plan_path | Should -Not -FileContentMatch 'pkg_scaffolding="core/scaffolding-go"'
90+
}
91+
92+
It 'minimal plan file (scaffolding placeholder)' {
93+
Invoke-NativeCommand "$hab" plan init --origin foo --min bar 2>&1 | Out-Null
94+
$plan_path | Should -Exist
95+
$plan_path | Should -Not -FileContentMatch "# This file is the heart of your application's habitat."
96+
$plan_path | Should -FileContentMatch 'pkg_scaffolding="some/scaffolding"'
97+
$plan_path | Should -Not -FileContentMatch 'pkg_scaffolding="core/scaffolding-ruby"'
98+
$plan_path | Should -Not -FileContentMatch 'pkg_scaffolding="core/scaffolding-go"'
99+
}
100+
101+
It 'minimal plan file with scaffolding specified' {
102+
Invoke-NativeCommand "$hab" plan init --origin foo --min --scaffolding go bar 2>&1 | Out-Null
103+
$plan_path | Should -Exist
104+
$plan_path | Should -Not -FileContentMatch "# This file is the heart of your application's habitat."
105+
$plan_path | Should -Not -FileContentMatch 'pkg_scaffolding="some/scaffolding"'
106+
$plan_path | Should -Not -FileContentMatch 'pkg_scaffolding="core/scaffolding-ruby"'
107+
$plan_path | Should -FileContentMatch 'pkg_scaffolding="core/scaffolding-go"'
108+
}
109+
}

0 commit comments

Comments
 (0)