2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_rds_instance"
|
2018-03-28 15:23:44 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
|
|
|
require "resources/aws/aws_rds_instance"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-03-28 15:23:44 +00:00
|
|
|
# MRDSIB = MockRDSInstanceBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsMDBIConstructor < Minitest::Test
|
|
|
|
def setup
|
|
|
|
AwsRdsInstance::BackendFactory.select(AwsMRDSIB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_no_args_raises
|
|
|
|
assert_raises(ArgumentError) { AwsRdsInstance.new }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_accept_scalar_param
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsRdsInstance.new("test-instance-id")
|
2018-03-28 15:23:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_accepts_db_instance_identifier_as_hash
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsRdsInstance.new(db_instance_identifier: "test-instance-id")
|
2018-03-28 15:23:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_reject_malformed_args
|
|
|
|
{
|
2019-06-11 22:24:35 +00:00
|
|
|
db_instance_identifier: "no_good",
|
2018-03-28 15:23:44 +00:00
|
|
|
}.each do |param, value|
|
|
|
|
assert_raises(ArgumentError) { AwsRdsInstance.new(param => value) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_reject_unknown_resource_params
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_raises(ArgumentError) { AwsRdsInstance.new(beep: "boop") }
|
2018-03-28 15:23:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Search / Recall
|
|
|
|
#=============================================================================#
|
|
|
|
|
|
|
|
class AwsMDBIRecallTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsRdsInstance::BackendFactory.select(AwsMRDSIB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_hit_via_scalar_works
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsRdsInstance.new("some-db").exists?
|
2018-03-28 15:23:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_hit_via_hash_works
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsRdsInstance.new(db_instance_identifier: "some-db").exists?
|
2018-03-28 15:23:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_miss_is_not_an_exception
|
2019-06-11 22:24:35 +00:00
|
|
|
refute AwsRdsInstance.new(db_instance_identifier: "test-instance-id").exists?
|
2018-03-28 15:23:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
|
|
|
|
module AwsMRDSIB
|
|
|
|
class Empty < AwsBackendBase
|
|
|
|
def describe_db_instances(_query)
|
|
|
|
raise Aws::RDS::Errors::DBInstanceNotFound.new(nil, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Basic < AwsBackendBase
|
|
|
|
def describe_db_instances(query)
|
|
|
|
fixtures = [
|
|
|
|
OpenStruct.new({
|
2019-06-11 22:24:35 +00:00
|
|
|
db_instance_identifier: "some-db",
|
2018-03-28 15:23:44 +00:00
|
|
|
}),
|
|
|
|
OpenStruct.new({
|
2019-06-11 22:24:35 +00:00
|
|
|
db_instance_identifier: "awesome-db",
|
2018-03-28 15:23:44 +00:00
|
|
|
}),
|
|
|
|
]
|
|
|
|
|
|
|
|
selected = fixtures.select do |db|
|
|
|
|
db[:db_instance_identifier].eql? query[:db_instance_identifier]
|
|
|
|
end
|
|
|
|
|
|
|
|
if selected.empty?
|
|
|
|
raise Aws::RDS::Errors::DBInstanceNotFound.new(nil, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
OpenStruct.new({ db_instances: selected })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|