From 9a92acc08a97b3ac07117d0c47c37ecc49841ac2 Mon Sep 17 00:00:00 2001 From: Stuart Paterson Date: Mon, 11 Jun 2018 10:09:49 +0100 Subject: [PATCH] Fixes according to issues: #19, #20, #21 and #22. * Ensure resources have consistent exists methods. * Corrected a coupld of arguments in example doc strings. Signed-off-by: Stuart Paterson --- libraries/google_compute_firewall.rb | 4 ++++ libraries/google_compute_image.rb | 4 ++++ libraries/google_compute_instance_group.rb | 6 +++++- libraries/google_container_node_pool.rb | 2 +- libraries/google_service_account.rb | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/google_compute_firewall.rb b/libraries/google_compute_firewall.rb index 8de5ee601..2b96216f5 100644 --- a/libraries/google_compute_firewall.rb +++ b/libraries/google_compute_firewall.rb @@ -51,6 +51,10 @@ def ports_protocol_allowed(port_list, protocol = 'tcp', index = 0) end end + def exists? + !@firewall.nil? + end + def to_s "Firewall Rule #{@display_name}" end diff --git a/libraries/google_compute_image.rb b/libraries/google_compute_image.rb index 9af0e5d86..06c6e9bdb 100644 --- a/libraries/google_compute_image.rb +++ b/libraries/google_compute_image.rb @@ -36,6 +36,10 @@ def initialize(opts = {}) end end + def exists? + !@image.nil? + end + def to_s "Image #{@display_name}" end diff --git a/libraries/google_compute_instance_group.rb b/libraries/google_compute_instance_group.rb index d0cdcab80..a4ea28f7a 100644 --- a/libraries/google_compute_instance_group.rb +++ b/libraries/google_compute_instance_group.rb @@ -8,7 +8,7 @@ class GoogleComputeInstanceGroup < GcpResourceBase desc 'Verifies settings for a compute instance group' example " - describe google_compute_instance_group(project: 'chef-inspec-gcp', location: 'us-west2', name: 'gcp-inspec-test') do + describe google_compute_instance_group(project: 'chef-inspec-gcp', zone: 'europe-west2-a', name: 'gcp-inspec-test') do it { should exist } its('name') { should eq 'inspec-test' } its('status') { should eq 'in_use' } @@ -38,6 +38,10 @@ def get_named_ports(index = 0, key = :name) named_ports[index].item[key] end + def exists? + !@instance_group.nil? + end + def to_s "Instance Group #{@display_name}" end diff --git a/libraries/google_container_node_pool.rb b/libraries/google_container_node_pool.rb index 38786d420..4ffbb2491 100644 --- a/libraries/google_container_node_pool.rb +++ b/libraries/google_container_node_pool.rb @@ -9,7 +9,7 @@ class GoogleContainerNodePool < GcpResourceBase desc 'Verifies settings for a container nodepool' example " - describe gcp_container_nodepool(project: 'chef-inspec-gcp', zone: 'gcp-inspec-test', name: 'cluster-name') do + describe google_container_node_pool(project: 'chef-inspec-gcp', zone: 'gcp-inspec-test', cluster_name: 'cluster-name', nodepool_name: 'nodepool_name') do it { should exist } its('name') { should eq 'inspec-test' } its('status') { should eq 'in_use' } diff --git a/libraries/google_service_account.rb b/libraries/google_service_account.rb index 9e73776f4..5347a848c 100644 --- a/libraries/google_service_account.rb +++ b/libraries/google_service_account.rb @@ -32,7 +32,7 @@ def initialize(opts = {}) end def exists? - !@iam_role.nil? + !@service_account.nil? end def to_s