tfwrapper 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -5
- data/ChangeLog.md +5 -0
- data/Gemfile +4 -0
- data/README.md +21 -2
- data/circle.yml +9 -5
- data/lib/tfwrapper/helpers.rb +21 -2
- data/lib/tfwrapper/raketasks.rb +72 -3
- data/lib/tfwrapper/version.rb +1 -1
- data/spec/acceptance/acceptance_helpers.rb +12 -0
- data/spec/acceptance/acceptance_spec.rb +190 -0
- data/spec/fixtures/landscapeTest/Rakefile +32 -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 +46 -0
- data/spec/fixtures/landscapeTest/with_landscape_lines.out +71 -0
- data/spec/fixtures/landscapeTest/with_landscape_stream.out +71 -0
- data/spec/fixtures/landscapeTest/without_landscape.out +62 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/unit/helpers_spec.rb +102 -0
- data/spec/unit/raketasks_spec.rb +205 -16
- metadata +18 -2
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tfwrapper/raketasks'
|
4
|
+
|
5
|
+
TFWrapper::RakeTasks.install_tasks(
|
6
|
+
'.',
|
7
|
+
namespace_prefix: 'default'
|
8
|
+
)
|
9
|
+
|
10
|
+
TFWrapper::RakeTasks.install_tasks(
|
11
|
+
'.',
|
12
|
+
namespace_prefix: 'disabled',
|
13
|
+
disable_landscape: true
|
14
|
+
)
|
15
|
+
|
16
|
+
TFWrapper::RakeTasks.install_tasks(
|
17
|
+
'.',
|
18
|
+
namespace_prefix: 'stream',
|
19
|
+
landscape_progress: :stream
|
20
|
+
)
|
21
|
+
|
22
|
+
TFWrapper::RakeTasks.install_tasks(
|
23
|
+
'.',
|
24
|
+
namespace_prefix: 'dots',
|
25
|
+
landscape_progress: :dots
|
26
|
+
)
|
27
|
+
|
28
|
+
TFWrapper::RakeTasks.install_tasks(
|
29
|
+
'.',
|
30
|
+
namespace_prefix: 'lines',
|
31
|
+
landscape_progress: :lines
|
32
|
+
)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "> 0.9.0"
|
3
|
+
backend "consul" {
|
4
|
+
address = "127.0.0.1:8500"
|
5
|
+
path = "terraform/landscapeTest"
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
provider "consul" {
|
10
|
+
address = "127.0.0.1:8500"
|
11
|
+
version = "~> 1.0"
|
12
|
+
}
|
13
|
+
|
14
|
+
locals {
|
15
|
+
keys = {
|
16
|
+
foo = "foo2val"
|
17
|
+
bar = "bar2val"
|
18
|
+
baz = "baz2val"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
variable "foo" { default = "bar" }
|
23
|
+
|
24
|
+
resource "consul_key_prefix" "landscapeTest" {
|
25
|
+
path_prefix = "landscapeTest/"
|
26
|
+
|
27
|
+
subkeys = {
|
28
|
+
foo = "${jsonencode(local.keys)}"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
output "foo_variable" { value = "${var.foo}" }
|
@@ -0,0 +1,43 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"terraform_version": "0.11.2",
|
4
|
+
"serial": 1,
|
5
|
+
"lineage": "2bab32f5-67fc-4210-8a74-af61d21a5420",
|
6
|
+
"modules": [
|
7
|
+
{
|
8
|
+
"path": [
|
9
|
+
"root"
|
10
|
+
],
|
11
|
+
"outputs": {
|
12
|
+
"foo_variable": {
|
13
|
+
"sensitive": false,
|
14
|
+
"type": "string",
|
15
|
+
"value": "bar"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"resources": {
|
19
|
+
"consul_key_prefix.landscapeTest": {
|
20
|
+
"type": "consul_key_prefix",
|
21
|
+
"depends_on": [
|
22
|
+
"local.keys"
|
23
|
+
],
|
24
|
+
"primary": {
|
25
|
+
"id": "landscapeTest/",
|
26
|
+
"attributes": {
|
27
|
+
"datacenter": "dc1",
|
28
|
+
"id": "landscapeTest/",
|
29
|
+
"path_prefix": "landscapeTest/",
|
30
|
+
"subkeys.%": "1",
|
31
|
+
"subkeys.foo": "{\"bar\":\"bar2val\",\"baz\":\"baz2val\",\"foo\":\"foo2val\"}"
|
32
|
+
},
|
33
|
+
"meta": {},
|
34
|
+
"tainted": false
|
35
|
+
},
|
36
|
+
"deposed": [],
|
37
|
+
"provider": "provider.consul"
|
38
|
+
}
|
39
|
+
},
|
40
|
+
"depends_on": []
|
41
|
+
}
|
42
|
+
]
|
43
|
+
}
|
@@ -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%%/default_build.tfvars.json
|
31
|
+
terraform_runner command: 'terraform plan -var-file %%FIXTUREPATH%%/default_build.tfvars.json' (in %%FIXTUREPATH%%)
|
32
|
+
Terraform vars:
|
33
|
+
terraform_runner command 'terraform plan -var-file %%FIXTUREPATH%%/default_build.tfvars.json' finished and exited 0
|
34
|
+
[0;33;49m~ consul_key_prefix.landscapeTest[0m
|
35
|
+
[0;33;49m subkeys.foo: [0m{
|
36
|
+
[31m- "bar": "barval",[0m
|
37
|
+
[31m- "baz": "bazval",[0m
|
38
|
+
[31m- "foo": "fooval"[0m
|
39
|
+
[32m+ "bar": "bar2val",[0m
|
40
|
+
[32m+ "baz": "baz2val",[0m
|
41
|
+
[32m+ "foo": "foo2val"[0m
|
42
|
+
}
|
43
|
+
|
44
|
+
Plan: 0 to add, 1 to change, 0 to destroy.
|
45
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Terraform v0.11.2
|
2
|
+
|
3
|
+
Your version of Terraform is out of date! The latest version
|
4
|
+
is 0.11.5. You can update by downloading from www.terraform.io/downloads.html
|
5
|
+
terraform_runner command: 'terraform init -input=false' (in /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest)
|
6
|
+
Running with: Terraform v0.11.2
|
7
|
+
|
8
|
+
Your version of Terraform is out of date! The latest version
|
9
|
+
is 0.11.5. 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: /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest/dots_build.tfvars.json
|
31
|
+
terraform_runner command: 'terraform plan -var-file /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest/dots_build.tfvars.json' (in /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest)
|
32
|
+
Terraform vars:
|
33
|
+
..........................terraform_runner command 'terraform plan -var-file /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest/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.
|
46
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
Terraform v0.11.2
|
2
|
+
|
3
|
+
Your version of Terraform is out of date! The latest version
|
4
|
+
is 0.11.5. You can update by downloading from www.terraform.io/downloads.html
|
5
|
+
terraform_runner command: 'terraform init -input=false' (in /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest)
|
6
|
+
Running with: Terraform v0.11.2
|
7
|
+
|
8
|
+
Your version of Terraform is out of date! The latest version
|
9
|
+
is 0.11.5. 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: /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest/lines_build.tfvars.json
|
31
|
+
terraform_runner command: 'terraform plan -var-file /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest/lines_build.tfvars.json' (in /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest)
|
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 /home/jantman/manheim/git/github_dot_com/tfwrapper/spec/fixtures/landscapeTest/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.
|
71
|
+
|
@@ -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/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,6 +185,29 @@ 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
|