2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_subnet"
|
2018-02-07 15:03:11 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
|
|
|
require "resources/aws/aws_subnet"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-02-07 15:03:11 +00:00
|
|
|
# MVSSB = MockVpcSubnetSingleBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
2018-02-08 04:23:05 +00:00
|
|
|
class AwsSubnetConstructorTest < Minitest::Test
|
2018-02-07 15:03:11 +00:00
|
|
|
def setup
|
2018-02-08 04:23:05 +00:00
|
|
|
AwsSubnet::BackendFactory.select(AwsMVSSB::Basic)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_no_args_raises
|
2018-02-08 04:23:05 +00:00
|
|
|
assert_raises(ArgumentError) { AwsSubnet.new }
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_expected_well_formed_args
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsSubnet.new(subnet_id: "subnet-12345678")
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_reject_unknown_resource_params
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_raises(ArgumentError) { AwsSubnet.new(bla: "blabla") }
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Recall
|
|
|
|
#=============================================================================#
|
|
|
|
|
2018-02-08 04:23:05 +00:00
|
|
|
class AwsSubnetRecallTest < Minitest::Test
|
2018-02-07 15:03:11 +00:00
|
|
|
def setup
|
2018-02-08 04:23:05 +00:00
|
|
|
AwsSubnet::BackendFactory.select(AwsMVSSB::Basic)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_hit_via_hash_with_vpc_id_and_subnet_id_works
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsSubnet.new(subnet_id: "subnet-12345678").exists?
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_search_miss_is_not_an_exception
|
2019-06-11 22:24:35 +00:00
|
|
|
refute AwsSubnet.new(subnet_id: "subnet-00000000").exists?
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# properties
|
|
|
|
#=============================================================================#
|
|
|
|
|
2018-02-08 04:23:05 +00:00
|
|
|
class AwsSubnetPropertiesTest < Minitest::Test
|
2018-02-07 15:03:11 +00:00
|
|
|
def setup
|
2018-02-08 04:23:05 +00:00
|
|
|
AwsSubnet::BackendFactory.select(AwsMVSSB::Basic)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_subnet_id
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal("subnet-12345678", AwsSubnet.new(subnet_id: "subnet-12345678").subnet_id)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_vpc_id
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal("vpc-12345678", AwsSubnet.new(subnet_id: "subnet-12345678").vpc_id)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_cidr_block
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal("10.0.1.0/24", AwsSubnet.new(subnet_id: "subnet-12345678").cidr_block)
|
|
|
|
assert_nil(AwsSubnet.new(subnet_id: "subnet-00000000").cidr_block)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_availability_zone
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal("us-east-1", AwsSubnet.new(subnet_id: "subnet-12345678").availability_zone)
|
|
|
|
assert_nil(AwsSubnet.new(subnet_id: "subnet-00000000").availability_zone)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_available_ip_address_count
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal(251, AwsSubnet.new(subnet_id: "subnet-12345678").available_ip_address_count)
|
|
|
|
assert_nil(AwsSubnet.new(subnet_id: "subnet-00000000").available_ip_address_count)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_ipv_6_cidr_block_association_set
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_equal([], AwsSubnet.new(subnet_id: "subnet-12345678").ipv_6_cidr_block_association_set)
|
|
|
|
assert_nil(AwsSubnet.new(subnet_id: "subnet-00000000").ipv_6_cidr_block_association_set)
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Matchers
|
|
|
|
#=============================================================================#
|
2018-02-08 04:23:05 +00:00
|
|
|
class AwsSubnetPropertiesTest < Minitest::Test
|
2018-02-07 15:03:11 +00:00
|
|
|
def test_matcher_assign_ipv_6_address_on_creation
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsSubnet.new(subnet_id: "subnet-12345678").assigning_ipv_6_address_on_creation
|
|
|
|
refute AwsSubnet.new(subnet_id: "subnet-87654321").assigning_ipv_6_address_on_creation
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
2018-02-07 15:03:11 +00:00
|
|
|
def test_matcher_available
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsSubnet.new(subnet_id: "subnet-12345678").available?
|
|
|
|
refute AwsSubnet.new(subnet_id: "subnet-87654321").available?
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
2018-02-07 15:03:11 +00:00
|
|
|
def test_matcher_default_for_az
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsSubnet.new(subnet_id: "subnet-12345678").default_for_az?
|
|
|
|
refute AwsSubnet.new(subnet_id: "subnet-87654321").default_for_az?
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
2018-02-07 15:03:11 +00:00
|
|
|
def test_matcher_map_public_ip_on_launch
|
2019-06-11 22:24:35 +00:00
|
|
|
assert AwsSubnet.new(subnet_id: "subnet-12345678").mapping_public_ip_on_launch
|
|
|
|
refute AwsSubnet.new(subnet_id: "subnet-87654321").mapping_public_ip_on_launch
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
|
|
|
|
module AwsMVSSB
|
2018-02-08 04:26:37 +00:00
|
|
|
class Basic < AwsBackendBase
|
2018-02-07 15:03:11 +00:00
|
|
|
def describe_subnets(query)
|
|
|
|
subnets = {
|
2019-06-11 22:24:35 +00:00
|
|
|
"subnet-12345678" => OpenStruct.new({
|
|
|
|
subnets: [
|
2018-02-07 15:03:11 +00:00
|
|
|
OpenStruct.new({
|
|
|
|
availability_zone: "us-east-1",
|
|
|
|
available_ip_address_count: 251,
|
|
|
|
cidr_block: "10.0.1.0/24",
|
|
|
|
default_for_az: true,
|
|
|
|
map_public_ip_on_launch: true,
|
|
|
|
state: "available",
|
|
|
|
subnet_id: "subnet-12345678",
|
|
|
|
vpc_id: "vpc-12345678",
|
|
|
|
ipv_6_cidr_block_association_set: [],
|
|
|
|
assign_ipv_6_address_on_creation: true,
|
|
|
|
}),
|
2019-06-11 22:24:35 +00:00
|
|
|
],
|
2018-02-07 15:03:11 +00:00
|
|
|
}),
|
2019-06-11 22:24:35 +00:00
|
|
|
"subnet-87654321" => OpenStruct.new({
|
|
|
|
subnets: [
|
2018-02-07 15:03:11 +00:00
|
|
|
OpenStruct.new({
|
|
|
|
availability_zone: "us-east-1",
|
|
|
|
available_ip_address_count: 251,
|
|
|
|
cidr_block: "10.0.1.0/24",
|
|
|
|
default_for_az: false,
|
|
|
|
map_public_ip_on_launch: false,
|
|
|
|
state: "pending",
|
|
|
|
subnet_id: "subnet-87654321",
|
|
|
|
vpc_id: "vpc-87654321",
|
|
|
|
ipv_6_cidr_block_association_set: [],
|
|
|
|
assign_ipv_6_address_on_creation: false,
|
|
|
|
}),
|
2019-06-11 22:24:35 +00:00
|
|
|
],
|
|
|
|
}),
|
|
|
|
"empty" => OpenStruct.new({
|
|
|
|
subnets: [],
|
2018-02-07 15:03:11 +00:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
return subnets[query[:filters][0][:values][0]] unless subnets[query[:filters][0][:values][0]].nil?
|
2019-06-11 22:24:35 +00:00
|
|
|
subnets["empty"]
|
2018-02-07 15:03:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|