Test cases fixed and new test cases added

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2022-03-10 18:32:11 +05:30
parent 39081c51ba
commit 9e1ef742f8
5 changed files with 56 additions and 11 deletions

View file

@ -43,7 +43,7 @@ module Inspec::DSL
include DeprecatedCloudResourcesList
cloud_resource = id.start_with?("aws_") ? "aws" : "azure"
# this check raises deprecation warning for aws and azure resources that were part of InSpec before version 5.
# Deprecated AWS and Azure resources in InSpec 5.
if CLOUD_RESOURCES_DEPRECATED.include? id
Inspec.deprecate(:"#{cloud_resource}_resources_in_resource_pack", "Resource '#{id}'")
else

View file

@ -0,0 +1,24 @@
control 'azure_resource_group_example' do
title 'Check if the Example Resource Group matches expectations'
impact 1.0
describe azure_resource_group(name: 'Inspec-Azure') do
# Check if the Resource Group is located in the correct region
its('location') { should cmp 'westeurope' }
# Check if the Resource Group has tags
it { should have_tags }
# Check if the number of VMs in the Resource Group is correct
its('vm_count') { should eq 3 }
# Check if the number of public IPs is correct
its('public_ip_count') { should eq 1 }
# Check if the number of Network Security Groups is correct
its('nsg_count') { should eq 1 }
# Check if the number of Storage Accounts is correct
its('sa_count') { should eq 1 }
end
end

View file

@ -0,0 +1,9 @@
name: azure
title: azure example profile
maintainer: Chef Software, Inc.
copyright: Chef Software, Inc.
copyright_email: support@chef.io
license: Apache-2.0
summary: Testing stub
version: 1.0.0
license: Apache-2.0

View file

@ -42,8 +42,7 @@ describe "inspec check" do
describe "inspec check with a aws profile" do
it "ignore train connection error" do
out = inspec("check " + File.join(examples_path, "profile-aws"))
assert_exit_code 0, out
assert_exit_code 3, out
end
end
@ -51,7 +50,7 @@ describe "inspec check" do
it "ignore train connection error" do
out = inspec("check " + File.join(examples_path, "profile-azure"))
assert_exit_code 0, out
assert_exit_code 3, out
end
end

View file

@ -479,15 +479,28 @@ Test Summary: 0 successful, 0 failures, 0 skipped
end
describe "with a profile that contains skipped resources" do
let(:out) { inspec("exec " + File.join(profile_path, "aws-profile")) }
let(:out) { inspec("exec " + File.join(examples_path, "profile-aws")) }
it "exits with an error" do
skip if ENV["NO_AWS"]
_(stdout).must_include "Unsupported resource/backend combination: aws_iam_users"
_(stdout).must_include "Unsupported resource/backend combination: aws_iam_access_keys"
_(stdout).must_include "Unsupported resource/backend combination: aws_s3_bucket"
_(stdout).must_include "3 failures"
_(stdout).must_include "Skipping profile: 'profile-aws' on unsupported platform"
assert_exit_code 101, out
end
end
assert_exit_code 100, out
# Deprecation tests are called without aws:// and azure:// due to lack of creds
# aws-profile and azure-profiles does not have platforms as aws and azure for testing this scenario
describe "with a profile that contains deprecated aws resources" do
let(:out) { inspec("exec " + File.join(profile_path, "aws-profile")) }
it "exits with deprecation error" do
_(stdout).must_include "DEPRECATION: AWS resources shipped with core InSpec are deprecated"
assert_exit_code 3, out
end
end
describe "with a profile that contains deprecated azure resources" do
let(:out) { inspec("exec " + File.join(profile_path, "azure-profile")) }
it "exits with deprecation error" do
_(stdout).must_include "DEPRECATION: Azure resources shipped with core InSpec are deprecated"
assert_exit_code 3, out
end
end