Skip to content

Commit 04ab273

Browse files
committed
test for dynamic files
1 parent c4157b0 commit 04ab273

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-0
lines changed

kitchen.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ suites:
5050
systems:
5151
- name: automatic-labelling-projects
5252
backend: gcp
53+
- name: dynamic-files
54+
driver:
55+
root_module_directory: test/fixtures/dynamic-files
56+
verifier:
57+
color: false
58+
systems:
59+
- name: dynamic-files
60+
backend: local
61+
control:
62+
- gcloud
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
module "dynamic_files" {
18+
source = "../../../examples/dynamic-files"
19+
20+
project_id = var.project_id
21+
folder_id = var.folder_id
22+
region = var.region
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "project_id" {
18+
value = var.project_id
19+
description = "The ID of the project to which resources are applied."
20+
}
21+
22+
output "region" {
23+
value = var.region
24+
description = "The region in which resources are applied."
25+
}
26+
27+
output "function_name" {
28+
value = module.dynamic_files.function_name
29+
description = "The name of the function created"
30+
}
31+
32+
output "random_file_string" {
33+
value = module.dynamic_files.random_file_string
34+
description = "The content of the terraform created file in the source directory."
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
type = string
19+
description = "The ID of the project to which resources will be applied."
20+
}
21+
22+
variable "folder_id" {
23+
type = string
24+
description = "The ID of the folder to look for changes."
25+
}
26+
27+
variable "region" {
28+
type = string
29+
description = "The region in which resources will be applied."
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
project_id = attribute('project_id')
16+
region = attribute('region')
17+
function_name = attribute('function_name')
18+
random_file_string = attribute('random_file_string')
19+
20+
control "gcloud" do
21+
title "gcloud configuration"
22+
23+
describe command("gcloud --project=#{project_id} functions call #{function_name} --region #{region} --data '{}' --format=json") do
24+
its(:exit_status) { should eq 0 }
25+
its(:stderr) { should eq '' }
26+
27+
let(:data) do
28+
if subject.exit_status == 0
29+
JSON.parse(subject.stdout)
30+
else
31+
{}
32+
end
33+
end
34+
35+
describe "terraform's file string" do
36+
it "should be returned" do
37+
expect(data).to include(
38+
"result" => random_file_string
39+
)
40+
end
41+
end
42+
end
43+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2019 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
name: automatic_labelling_projects
17+
version: 0.1.0
18+
depends:
19+
- name: inspec-gcp
20+
git: https://github.com/inspec/inspec-gcp.git
21+
tag: v0.10.0
22+
attributes:
23+
- name: project_id
24+
type: string
25+
required: true
26+
description: "The ID of the project to which resources are applied."
27+
- name: region
28+
type: string
29+
required: true
30+
description: "The region in which resources are applied."
31+
- name: function_name
32+
type: string
33+
required: true
34+
description: "The name of the function created"
35+
- name: random_file_string
36+
type: string
37+
required: true
38+
description: "The content of the terraform created file in the source directory."

0 commit comments

Comments
 (0)