Skip to content

Commit 529ea6a

Browse files
author
Simon So
committed
Add tests for instance_templates and statically define assertions in MIG tests
1 parent 7101ece commit 529ea6a

File tree

5 files changed

+124
-28
lines changed

5 files changed

+124
-28
lines changed

modules/instance_template/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ resource "google_compute_instance_template" "tpl" {
6464
}
6565

6666
lifecycle {
67-
create_before_destroy = true
67+
create_before_destroy = "true"
6868
}
6969
}

modules/mig/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ resource "google_compute_region_instance_group_manager" "mig" {
4747
update_policy = ["${var.update_policy}"]
4848

4949
lifecycle {
50-
create_before_destroy = true
50+
create_before_destroy = "true"
5151
}
5252
}
5353

test/fixtures/mig/autoscaler/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module "mig_autoscaler" {
3131
environment = "dev"
3232
}
3333

34-
autoscaling_enabled = true
34+
autoscaling_enabled = "true"
3535
min_replicas = 4
3636

3737
autoscaling_cpu = [{

test/integration/mig_autoscaler/controls/mig_autoscaler.rb

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,75 @@
4444
end
4545
end
4646

47-
describe "network tags" do
47+
describe "network tags for instance 1" do
4848
it "should include 'foo'" do
49-
data.each do |instance|
50-
expect(instance['tags']['items']).to include("foo")
51-
end
49+
expect(data[0]['tags']['items']).to include("foo")
5250
end
5351
end
5452

55-
describe "labels" do
53+
describe "network tags for instance 2" do
54+
it "should include 'foo'" do
55+
expect(data[1]['tags']['items']).to include("foo")
56+
end
57+
end
58+
59+
describe "network tags for instance 3" do
60+
it "should include 'foo'" do
61+
expect(data[2]['tags']['items']).to include("foo")
62+
end
63+
end
64+
65+
describe "network tags for instance 4" do
66+
it "should include 'foo'" do
67+
expect(data[3]['tags']['items']).to include("foo")
68+
end
69+
end
70+
71+
describe "labels for instance 1" do
72+
it "should include 'environment' key" do
73+
expect(data[0]['labels']).to include("environment")
74+
end
75+
end
76+
77+
describe "labels for instance 2" do
78+
it "should include 'environment' key" do
79+
expect(data[1]['labels']).to include("environment")
80+
end
81+
end
82+
83+
describe "labels for instance 3" do
5684
it "should include 'environment' key" do
57-
data.each do |instance|
58-
expect(instance['labels']).to include("environment")
59-
end
85+
expect(data[2]['labels']).to include("environment")
86+
end
87+
end
88+
89+
describe "labels for instance 4" do
90+
it "should include 'environment' key" do
91+
expect(data[3]['labels']).to include("environment")
92+
end
93+
end
94+
95+
describe "labels for instance 1" do
96+
it "'environment' should have value 'dev'" do
97+
expect(data[0]['labels']['environment']).to eq("dev")
98+
end
99+
end
100+
101+
describe "labels for instance 2" do
102+
it "'environment' should have value 'dev'" do
103+
expect(data[1]['labels']['environment']).to eq("dev")
104+
end
105+
end
106+
107+
describe "labels for instance 3" do
108+
it "'environment' should have value 'dev'" do
109+
expect(data[2]['labels']['environment']).to eq("dev")
60110
end
61111
end
62112

63-
describe "labels" do
113+
describe "labels for instance 4" do
64114
it "'environment' should have value 'dev'" do
65-
data.each do |instance|
66-
expect(instance['labels']['environment']).to eq("dev")
67-
end
115+
expect(data[3]['labels']['environment']).to eq("dev")
68116
end
69117
end
70118

test/integration/mig_simple/controls/mig_simple.rb

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
if subject.exit_status == 0
3535
JSON.parse(subject.stdout)
3636
else
37-
[]]
37+
[]
3838
end
3939
end
4040

@@ -44,27 +44,75 @@
4444
end
4545
end
4646

47-
describe "network tags" do
47+
describe "network tags for instance 1" do
48+
it "should include 'foo'" do
49+
expect(data[0]['tags']['items']).to include("foo")
50+
end
51+
end
52+
53+
describe "network tags for instance 2" do
4854
it "should include 'foo'" do
49-
data.each do |instance|
50-
expect(instance['tags']['items']).to include("foo")
51-
end
55+
expect(data[1]['tags']['items']).to include("foo")
5256
end
5357
end
5458

55-
describe "labels" do
59+
describe "network tags for instance 3" do
60+
it "should include 'foo'" do
61+
expect(data[2]['tags']['items']).to include("foo")
62+
end
63+
end
64+
65+
describe "network tags for instance 4" do
66+
it "should include 'foo'" do
67+
expect(data[3]['tags']['items']).to include("foo")
68+
end
69+
end
70+
71+
describe "labels for instance 1" do
5672
it "should include 'environment' key" do
57-
data.each do |instance|
58-
expect(instance['labels']).to include("environment")
59-
end
73+
expect(data[0]['labels']).to include("environment")
74+
end
75+
end
76+
77+
describe "labels for instance 2" do
78+
it "should include 'environment' key" do
79+
expect(data[1]['labels']).to include("environment")
80+
end
81+
end
82+
83+
describe "labels for instance 3" do
84+
it "should include 'environment' key" do
85+
expect(data[2]['labels']).to include("environment")
86+
end
87+
end
88+
89+
describe "labels for instance 4" do
90+
it "should include 'environment' key" do
91+
expect(data[3]['labels']).to include("environment")
92+
end
93+
end
94+
95+
describe "labels for instance 1" do
96+
it "'environment' should have value 'dev'" do
97+
expect(data[0]['labels']['environment']).to eq("dev")
98+
end
99+
end
100+
101+
describe "labels for instance 2" do
102+
it "'environment' should have value 'dev'" do
103+
expect(data[1]['labels']['environment']).to eq("dev")
104+
end
105+
end
106+
107+
describe "labels for instance 3" do
108+
it "'environment' should have value 'dev'" do
109+
expect(data[2]['labels']['environment']).to eq("dev")
60110
end
61111
end
62112

63-
describe "labels" do
113+
describe "labels for instance 4" do
64114
it "'environment' should have value 'dev'" do
65-
data.each do |instance|
66-
expect(instance['labels']['environment']).to eq("dev")
67-
end
115+
expect(data[3]['labels']['environment']).to eq("dev")
68116
end
69117
end
70118

0 commit comments

Comments
 (0)