tfwrapper 0.4.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -5
- data/.travis.yml +62 -0
- data/ChangeLog.md +31 -0
- data/Gemfile +4 -0
- data/README.md +48 -5
- data/lib/tfwrapper/helpers.rb +25 -3
- data/lib/tfwrapper/raketasks.rb +91 -10
- data/lib/tfwrapper/version.rb +1 -1
- data/spec/acceptance/acceptance_helpers.rb +16 -3
- data/spec/acceptance/acceptance_spec.rb +229 -0
- data/spec/fixtures/landscapeTest/Rakefile +38 -0
- data/spec/fixtures/landscapeTest/failingTerraform/main.tf +28 -0
- data/spec/fixtures/landscapeTest/main.tf +32 -0
- data/spec/fixtures/landscapeTest/state.json +43 -0
- data/spec/fixtures/landscapeTest/with_landscape_default.out +45 -0
- data/spec/fixtures/landscapeTest/with_landscape_dots.out +45 -0
- data/spec/fixtures/landscapeTest/with_landscape_lines.out +70 -0
- data/spec/fixtures/landscapeTest/with_landscape_stream.out +71 -0
- data/spec/fixtures/landscapeTest/without_landscape.out +62 -0
- data/spec/fixtures/testOne.tf +1 -0
- data/spec/fixtures/testThree/bar/testThreeBar.tf +1 -0
- data/spec/fixtures/testThree/baz/testThreeBaz.tf +1 -0
- data/spec/fixtures/testThree/foo/testThreeFoo.tf +1 -0
- data/spec/fixtures/testTwo/foo/bar/testTwo.tf +1 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/unit/helpers_spec.rb +131 -3
- data/spec/unit/raketasks_spec.rb +250 -26
- data/tfwrapper.gemspec +1 -0
- metadata +36 -4
- data/circle.yml +0 -28
@@ -0,0 +1,45 @@
|
|
1
|
+
Terraform v0.11.2
|
2
|
+
|
3
|
+
Your version of Terraform is out of date! The latest version
|
4
|
+
is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
|
5
|
+
terraform_runner command: 'terraform init -input=false' (in %%FIXTUREPATH%%)
|
6
|
+
Running with: Terraform v0.11.2
|
7
|
+
|
8
|
+
Your version of Terraform is out of date! The latest version
|
9
|
+
is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
|
10
|
+
|
11
|
+
[0m[1mInitializing the backend...[0m
|
12
|
+
[0m[32m
|
13
|
+
Successfully configured the backend "consul"! Terraform will automatically
|
14
|
+
use this backend unless the backend configuration changes.[0m
|
15
|
+
|
16
|
+
[0m[1mInitializing provider plugins...[0m
|
17
|
+
- Checking for available provider plugins on https://releases.hashicorp.com...
|
18
|
+
- Downloading plugin for provider "consul" (1.0.0)...
|
19
|
+
|
20
|
+
[0m[1m[32mTerraform has been successfully initialized![0m[32m[0m
|
21
|
+
[0m[32m
|
22
|
+
You may now begin working with Terraform. Try running "terraform plan" to see
|
23
|
+
any changes that are required for your infrastructure. All Terraform commands
|
24
|
+
should now work.
|
25
|
+
|
26
|
+
If you ever set or change modules or backend configuration for Terraform,
|
27
|
+
rerun this command to reinitialize your working directory. If you forget, other
|
28
|
+
commands will detect it and remind you to do so if necessary.[0m
|
29
|
+
terraform_runner command 'terraform init -input=false' finished and exited 0
|
30
|
+
Terraform vars written to: %%FIXTUREPATH%%/dots_build.tfvars.json
|
31
|
+
terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/dots_build.tfvars.json' (in %%FIXTUREPATH%%)
|
32
|
+
Terraform vars:
|
33
|
+
..........................terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/dots_build.tfvars.json' finished and exited 0
|
34
|
+
|
35
|
+
[0;33;49m~ consul_key_prefix.landscapeTest[0m
|
36
|
+
[0;33;49m subkeys.foo: [0m{
|
37
|
+
[31m- "bar": "barval",[0m
|
38
|
+
[31m- "baz": "bazval",[0m
|
39
|
+
[31m- "foo": "fooval"[0m
|
40
|
+
[32m+ "bar": "bar2val",[0m
|
41
|
+
[32m+ "baz": "baz2val",[0m
|
42
|
+
[32m+ "foo": "foo2val"[0m
|
43
|
+
}
|
44
|
+
|
45
|
+
Plan: 0 to add, 1 to change, 0 to destroy.
|
@@ -0,0 +1,70 @@
|
|
1
|
+
Terraform v0.11.2
|
2
|
+
|
3
|
+
Your version of Terraform is out of date! The latest version
|
4
|
+
is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
|
5
|
+
terraform_runner command: 'terraform init -input=false' (in %%FIXTUREPATH%%)
|
6
|
+
Running with: Terraform v0.11.2
|
7
|
+
|
8
|
+
Your version of Terraform is out of date! The latest version
|
9
|
+
is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
|
10
|
+
|
11
|
+
[0m[1mInitializing the backend...[0m
|
12
|
+
[0m[32m
|
13
|
+
Successfully configured the backend "consul"! Terraform will automatically
|
14
|
+
use this backend unless the backend configuration changes.[0m
|
15
|
+
|
16
|
+
[0m[1mInitializing provider plugins...[0m
|
17
|
+
- Checking for available provider plugins on https://releases.hashicorp.com...
|
18
|
+
- Downloading plugin for provider "consul" (1.0.0)...
|
19
|
+
|
20
|
+
[0m[1m[32mTerraform has been successfully initialized![0m[32m[0m
|
21
|
+
[0m[32m
|
22
|
+
You may now begin working with Terraform. Try running "terraform plan" to see
|
23
|
+
any changes that are required for your infrastructure. All Terraform commands
|
24
|
+
should now work.
|
25
|
+
|
26
|
+
If you ever set or change modules or backend configuration for Terraform,
|
27
|
+
rerun this command to reinitialize your working directory. If you forget, other
|
28
|
+
commands will detect it and remind you to do so if necessary.[0m
|
29
|
+
terraform_runner command 'terraform init -input=false' finished and exited 0
|
30
|
+
Terraform vars written to: %%FIXTUREPATH%%/lines_build.tfvars.json
|
31
|
+
terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/lines_build.tfvars.json' (in %%FIXTUREPATH%%)
|
32
|
+
Terraform vars:
|
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
|
+
terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/lines_build.tfvars.json' finished and exited 0
|
60
|
+
[0;33;49m~ consul_key_prefix.landscapeTest[0m
|
61
|
+
[0;33;49m subkeys.foo: [0m{
|
62
|
+
[31m- "bar": "barval",[0m
|
63
|
+
[31m- "baz": "bazval",[0m
|
64
|
+
[31m- "foo": "fooval"[0m
|
65
|
+
[32m+ "bar": "bar2val",[0m
|
66
|
+
[32m+ "baz": "baz2val",[0m
|
67
|
+
[32m+ "foo": "foo2val"[0m
|
68
|
+
}
|
69
|
+
|
70
|
+
Plan: 0 to add, 1 to change, 0 to destroy.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
Terraform v0.11.2
|
2
|
+
|
3
|
+
Your version of Terraform is out of date! The latest version
|
4
|
+
is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
|
5
|
+
terraform_runner command: 'terraform init -input=false' (in %%FIXTUREPATH%%)
|
6
|
+
Running with: Terraform v0.11.2
|
7
|
+
|
8
|
+
Your version of Terraform is out of date! The latest version
|
9
|
+
is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
|
10
|
+
|
11
|
+
[0m[1mInitializing the backend...[0m
|
12
|
+
[0m[32m
|
13
|
+
Successfully configured the backend "consul"! Terraform will automatically
|
14
|
+
use this backend unless the backend configuration changes.[0m
|
15
|
+
|
16
|
+
[0m[1mInitializing provider plugins...[0m
|
17
|
+
- Checking for available provider plugins on https://releases.hashicorp.com...
|
18
|
+
- Downloading plugin for provider "consul" (1.0.0)...
|
19
|
+
|
20
|
+
[0m[1m[32mTerraform has been successfully initialized![0m[32m[0m
|
21
|
+
[0m[32m
|
22
|
+
You may now begin working with Terraform. Try running "terraform plan" to see
|
23
|
+
any changes that are required for your infrastructure. All Terraform commands
|
24
|
+
should now work.
|
25
|
+
|
26
|
+
If you ever set or change modules or backend configuration for Terraform,
|
27
|
+
rerun this command to reinitialize your working directory. If you forget, other
|
28
|
+
commands will detect it and remind you to do so if necessary.[0m
|
29
|
+
terraform_runner command 'terraform init -input=false' finished and exited 0
|
30
|
+
Terraform vars written to: %%FIXTUREPATH%%/stream_build.tfvars.json
|
31
|
+
terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/stream_build.tfvars.json' (in %%FIXTUREPATH%%)
|
32
|
+
Terraform vars:
|
33
|
+
[0m[1mRefreshing Terraform state in-memory prior to plan...[0m
|
34
|
+
The refreshed state will be used to calculate this plan, but will not be
|
35
|
+
persisted to local or remote state storage.
|
36
|
+
[0m
|
37
|
+
[0m[1mconsul_key_prefix.landscapeTest: Refreshing state... (ID: landscapeTest/)[0m
|
38
|
+
|
39
|
+
------------------------------------------------------------------------
|
40
|
+
|
41
|
+
An execution plan has been generated and is shown below.
|
42
|
+
Resource actions are indicated with the following symbols:
|
43
|
+
[33m~[0m update in-place
|
44
|
+
[0m
|
45
|
+
Terraform will perform the following actions:
|
46
|
+
|
47
|
+
[33m [33m~[0m [33mconsul_key_prefix.landscapeTest
|
48
|
+
[0m subkeys.foo: "{\"bar\":\"barval\",\"baz\":\"bazval\",\"foo\":\"fooval\"}" => "{\"bar\":\"bar2val\",\"baz\":\"baz2val\",\"foo\":\"foo2val\"}"
|
49
|
+
[0m
|
50
|
+
[0m
|
51
|
+
[0m[1mPlan:[0m 0 to add, 1 to change, 0 to destroy.[0m
|
52
|
+
|
53
|
+
------------------------------------------------------------------------
|
54
|
+
|
55
|
+
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
|
56
|
+
can't guarantee that exactly these actions will be performed if
|
57
|
+
"terraform apply" is subsequently run.
|
58
|
+
|
59
|
+
terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/stream_build.tfvars.json' finished and exited 0
|
60
|
+
[0;33;49m~ consul_key_prefix.landscapeTest[0m
|
61
|
+
[0;33;49m subkeys.foo: [0m{
|
62
|
+
[31m- "bar": "barval",[0m
|
63
|
+
[31m- "baz": "bazval",[0m
|
64
|
+
[31m- "foo": "fooval"[0m
|
65
|
+
[32m+ "bar": "bar2val",[0m
|
66
|
+
[32m+ "baz": "baz2val",[0m
|
67
|
+
[32m+ "foo": "foo2val"[0m
|
68
|
+
}
|
69
|
+
|
70
|
+
Plan: 0 to add, 1 to change, 0 to destroy.
|
71
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
Terraform v0.11.2
|
2
|
+
|
3
|
+
Your version of Terraform is out of date! The latest version
|
4
|
+
is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
|
5
|
+
terraform_runner command: 'terraform init -input=false' (in %%FIXTUREPATH%%)
|
6
|
+
Running with: Terraform v0.11.2
|
7
|
+
|
8
|
+
Your version of Terraform is out of date! The latest version
|
9
|
+
is %%TF_LATEST_VER%%. You can update by downloading from www.terraform.io/downloads.html
|
10
|
+
|
11
|
+
[0m[1mInitializing the backend...[0m
|
12
|
+
[0m[32m
|
13
|
+
Successfully configured the backend "consul"! Terraform will automatically
|
14
|
+
use this backend unless the backend configuration changes.[0m
|
15
|
+
|
16
|
+
[0m[1mInitializing provider plugins...[0m
|
17
|
+
- Checking for available provider plugins on https://releases.hashicorp.com...
|
18
|
+
- Downloading plugin for provider "consul" (1.0.0)...
|
19
|
+
|
20
|
+
[0m[1m[32mTerraform has been successfully initialized![0m[32m[0m
|
21
|
+
[0m[32m
|
22
|
+
You may now begin working with Terraform. Try running "terraform plan" to see
|
23
|
+
any changes that are required for your infrastructure. All Terraform commands
|
24
|
+
should now work.
|
25
|
+
|
26
|
+
If you ever set or change modules or backend configuration for Terraform,
|
27
|
+
rerun this command to reinitialize your working directory. If you forget, other
|
28
|
+
commands will detect it and remind you to do so if necessary.[0m
|
29
|
+
terraform_runner command 'terraform init -input=false' finished and exited 0
|
30
|
+
Terraform vars written to: %%FIXTUREPATH%%/default_build.tfvars.json
|
31
|
+
terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/default_build.tfvars.json' (in %%FIXTUREPATH%%)
|
32
|
+
Terraform vars:
|
33
|
+
[0m[1mRefreshing Terraform state in-memory prior to plan...[0m
|
34
|
+
The refreshed state will be used to calculate this plan, but will not be
|
35
|
+
persisted to local or remote state storage.
|
36
|
+
[0m
|
37
|
+
|
38
|
+
------------------------------------------------------------------------
|
39
|
+
|
40
|
+
An execution plan has been generated and is shown below.
|
41
|
+
Resource actions are indicated with the following symbols:
|
42
|
+
[32m+[0m create
|
43
|
+
[0m
|
44
|
+
Terraform will perform the following actions:
|
45
|
+
|
46
|
+
[32m [32m+[0m [32mconsul_key_prefix.landscapeTest
|
47
|
+
[0m id: <computed>
|
48
|
+
datacenter: <computed>
|
49
|
+
path_prefix: "landscapeTest/"
|
50
|
+
subkeys.%: "1"
|
51
|
+
subkeys.foo: "{\"bar\":\"bar2val\",\"baz\":\"baz2val\",\"foo\":\"foo2val\"}"
|
52
|
+
[0m
|
53
|
+
[0m
|
54
|
+
[0m[1mPlan:[0m 1 to add, 0 to change, 0 to destroy.[0m
|
55
|
+
|
56
|
+
------------------------------------------------------------------------
|
57
|
+
|
58
|
+
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
|
59
|
+
can't guarantee that exactly these actions will be performed if
|
60
|
+
"terraform apply" is subsequently run.
|
61
|
+
|
62
|
+
terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/default_build.tfvars.json' finished and exited 0
|
data/spec/fixtures/testOne.tf
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,13 @@ require 'simplecov'
|
|
4
4
|
require 'simplecov-console'
|
5
5
|
require 'rspec_junit_formatter'
|
6
6
|
|
7
|
+
begin
|
8
|
+
require 'terraform_landscape'
|
9
|
+
HAVE_LANDSCAPE = true
|
10
|
+
rescue LoadError
|
11
|
+
HAVE_LANDSCAPE = false
|
12
|
+
end
|
13
|
+
|
7
14
|
ENV['CONSUL_ADDR'] ||= '127.0.0.1:8500'
|
8
15
|
ENV['CONSUL_URL'] ||= "http://#{ENV['CONSUL_ADDR']}"
|
9
16
|
|
data/spec/unit/helpers_spec.rb
CHANGED
@@ -54,12 +54,91 @@ describe TFWrapper::Helpers do
|
|
54
54
|
expect(Open3).to receive(:popen2e)
|
55
55
|
.once.with('foo bar', chdir: '/foo')
|
56
56
|
expect(STDOUT).to receive(:puts).once.with('mystdout')
|
57
|
+
expect(STDOUT).to_not receive(:print)
|
57
58
|
expect($stdout).to receive(:sync=).once.with(true)
|
58
59
|
expect($stdout).to receive(:sync=).once.with(false)
|
59
60
|
expect(TFWrapper::Helpers.run_cmd_stream_output('foo bar', '/foo'))
|
60
61
|
.to eq(['mystdout', 0])
|
61
62
|
end
|
62
63
|
end
|
64
|
+
context 'progress dots' do
|
65
|
+
it 'prints dots and returns output' do
|
66
|
+
dbl_wait_thread = double(Thread)
|
67
|
+
@outerrpipe_w.write('mystdout')
|
68
|
+
@outerrpipe_w.close
|
69
|
+
es = double('exitstatus', exitstatus: 0)
|
70
|
+
allow(dbl_wait_thread).to receive(:value).and_return(es)
|
71
|
+
allow($stdout).to receive(:sync).and_return(false)
|
72
|
+
allow($stdout).to receive(:sync=).with(true)
|
73
|
+
allow(Open3).to receive(:popen2e).and_yield(
|
74
|
+
@inpipe_w, @outerrpipe_r, dbl_wait_thread
|
75
|
+
)
|
76
|
+
|
77
|
+
expect(Open3).to receive(:popen2e)
|
78
|
+
.once.with('foo bar', chdir: '/foo')
|
79
|
+
expect(STDOUT).to receive(:puts).once.with('')
|
80
|
+
expect(STDOUT).to receive(:print).once.with('.')
|
81
|
+
expect($stdout).to receive(:sync=).once.with(true)
|
82
|
+
expect($stdout).to receive(:sync=).once.with(false)
|
83
|
+
expect(
|
84
|
+
TFWrapper::Helpers.run_cmd_stream_output(
|
85
|
+
'foo bar', '/foo', progress: :dots
|
86
|
+
)
|
87
|
+
).to eq(['mystdout', 0])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
context 'progress lines' do
|
91
|
+
it 'prints a dot per line and returns output' do
|
92
|
+
dbl_wait_thread = double(Thread)
|
93
|
+
@outerrpipe_w.write('mystdout')
|
94
|
+
@outerrpipe_w.close
|
95
|
+
es = double('exitstatus', exitstatus: 0)
|
96
|
+
allow(dbl_wait_thread).to receive(:value).and_return(es)
|
97
|
+
allow($stdout).to receive(:sync).and_return(false)
|
98
|
+
allow($stdout).to receive(:sync=).with(true)
|
99
|
+
allow(Open3).to receive(:popen2e).and_yield(
|
100
|
+
@inpipe_w, @outerrpipe_r, dbl_wait_thread
|
101
|
+
)
|
102
|
+
|
103
|
+
expect(Open3).to receive(:popen2e)
|
104
|
+
.once.with('foo bar', chdir: '/foo')
|
105
|
+
expect(STDOUT).to receive(:puts).once.with('.')
|
106
|
+
expect(STDOUT).to_not receive(:print)
|
107
|
+
expect($stdout).to receive(:sync=).once.with(true)
|
108
|
+
expect($stdout).to receive(:sync=).once.with(false)
|
109
|
+
expect(
|
110
|
+
TFWrapper::Helpers.run_cmd_stream_output(
|
111
|
+
'foo bar', '/foo', progress: :lines
|
112
|
+
)
|
113
|
+
).to eq(['mystdout', 0])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
context 'progress nil' do
|
117
|
+
it 'does not print anything but returns output' do
|
118
|
+
dbl_wait_thread = double(Thread)
|
119
|
+
@outerrpipe_w.write('mystdout')
|
120
|
+
@outerrpipe_w.close
|
121
|
+
es = double('exitstatus', exitstatus: 0)
|
122
|
+
allow(dbl_wait_thread).to receive(:value).and_return(es)
|
123
|
+
allow($stdout).to receive(:sync).and_return(false)
|
124
|
+
allow($stdout).to receive(:sync=).with(true)
|
125
|
+
allow(Open3).to receive(:popen2e).and_yield(
|
126
|
+
@inpipe_w, @outerrpipe_r, dbl_wait_thread
|
127
|
+
)
|
128
|
+
|
129
|
+
expect(Open3).to receive(:popen2e)
|
130
|
+
.once.with('foo bar', chdir: '/foo')
|
131
|
+
expect(STDOUT).to_not receive(:puts)
|
132
|
+
expect(STDOUT).to_not receive(:print)
|
133
|
+
expect($stdout).to receive(:sync=).once.with(true)
|
134
|
+
expect($stdout).to receive(:sync=).once.with(false)
|
135
|
+
expect(
|
136
|
+
TFWrapper::Helpers.run_cmd_stream_output(
|
137
|
+
'foo bar', '/foo', progress: nil
|
138
|
+
)
|
139
|
+
).to eq(['mystdout', 0])
|
140
|
+
end
|
141
|
+
end
|
63
142
|
context 'IOError' do
|
64
143
|
it 'handles IOErrors gracefully' do
|
65
144
|
dbl_wait_thread = double(Thread)
|
@@ -106,15 +185,44 @@ describe TFWrapper::Helpers do
|
|
106
185
|
.to eq(["mystdout\nSTDERR\n", 23])
|
107
186
|
end
|
108
187
|
end
|
188
|
+
context 'invalid :progress option' do
|
189
|
+
it 'raises an error' do
|
190
|
+
dbl_wait_thread = double(Thread)
|
191
|
+
@outerrpipe_w.write('mystdout')
|
192
|
+
@outerrpipe_w.close
|
193
|
+
es = double('exitstatus', exitstatus: 0)
|
194
|
+
allow(dbl_wait_thread).to receive(:value).and_return(es)
|
195
|
+
allow($stdout).to receive(:sync).and_return(false)
|
196
|
+
allow($stdout).to receive(:sync=).with(true)
|
197
|
+
allow(Open3).to receive(:popen2e).and_yield(
|
198
|
+
@inpipe_w, @outerrpipe_r, dbl_wait_thread
|
199
|
+
)
|
200
|
+
|
201
|
+
expect(Open3).to_not receive(:popen2e)
|
202
|
+
expect(STDOUT).to_not receive(:puts)
|
203
|
+
expect($stdout).to_not receive(:sync=)
|
204
|
+
expect do
|
205
|
+
TFWrapper::Helpers.run_cmd_stream_output(
|
206
|
+
'foo bar', '/foo', progress: :foo
|
207
|
+
)
|
208
|
+
end.to raise_error(ArgumentError, /progress option must be one of/)
|
209
|
+
end
|
210
|
+
end
|
109
211
|
end
|
110
212
|
describe '#check_env_vars' do
|
111
213
|
it 'returns nil if vars present' do
|
112
214
|
ENV['foo'] = 'fooval'
|
113
215
|
ENV['bar'] = 'barval'
|
114
|
-
expect(TFWrapper::Helpers.check_env_vars(%w[foo bar])).to be_nil
|
216
|
+
expect(TFWrapper::Helpers.check_env_vars(%w[foo bar], [])).to be_nil
|
115
217
|
ENV.delete('foo')
|
116
218
|
ENV.delete('bar')
|
117
219
|
end
|
220
|
+
it 'returns nil if vars ignored' do
|
221
|
+
ENV['foo'] = ''
|
222
|
+
expect(TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[foo bar]))
|
223
|
+
.to be_nil
|
224
|
+
ENV.delete('foo')
|
225
|
+
end
|
118
226
|
it 'exits if not present' do
|
119
227
|
ENV.delete('foo')
|
120
228
|
ENV.delete('bar')
|
@@ -122,7 +230,7 @@ describe TFWrapper::Helpers do
|
|
122
230
|
.with('ERROR: Environment variable \'foo\' must be set.')
|
123
231
|
expect(STDOUT).to receive(:puts)
|
124
232
|
.with('ERROR: Environment variable \'bar\' must be set.')
|
125
|
-
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar]) }
|
233
|
+
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[baz]) }
|
126
234
|
.to raise_error StandardError, 'Missing or empty environment ' \
|
127
235
|
'variables: ["foo", "bar"]'
|
128
236
|
end
|
@@ -133,11 +241,31 @@ describe TFWrapper::Helpers do
|
|
133
241
|
.with("ERROR: Environment variable 'foo' must not be empty.")
|
134
242
|
expect(STDOUT).to receive(:puts)
|
135
243
|
.with("ERROR: Environment variable 'bar' must not be empty.")
|
136
|
-
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar]) }
|
244
|
+
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[baz]) }
|
137
245
|
.to raise_error StandardError, 'Missing or empty environment ' \
|
138
246
|
'variables: ["foo", "bar"]'
|
139
247
|
ENV.delete('foo')
|
140
248
|
ENV.delete('bar')
|
141
249
|
end
|
250
|
+
it 'exits if not present and partially ignored' do
|
251
|
+
ENV.delete('foo')
|
252
|
+
ENV.delete('bar')
|
253
|
+
expect(STDOUT).to receive(:puts)
|
254
|
+
.with('ERROR: Environment variable \'foo\' must be set.')
|
255
|
+
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[bar]) }
|
256
|
+
.to raise_error StandardError, 'Missing or empty environment ' \
|
257
|
+
'variables: ["foo"]'
|
258
|
+
end
|
259
|
+
it 'exits if empty and partially ignored' do
|
260
|
+
ENV['foo'] = ''
|
261
|
+
ENV['bar'] = ' '
|
262
|
+
expect(STDOUT).to receive(:puts)
|
263
|
+
.with("ERROR: Environment variable 'foo' must not be empty.")
|
264
|
+
expect { TFWrapper::Helpers.check_env_vars(%w[foo bar], %w[bar]) }
|
265
|
+
.to raise_error StandardError, 'Missing or empty environment ' \
|
266
|
+
'variables: ["foo"]'
|
267
|
+
ENV.delete('foo')
|
268
|
+
ENV.delete('bar')
|
269
|
+
end
|
142
270
|
end
|
143
271
|
end
|