2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_ec2_instances"
|
2018-05-10 18:54:33 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
|
|
|
require "resources/aws/aws_ec2_instances"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-05-10 18:54:33 +00:00
|
|
|
# MAEIPB = MockAwsEC2InstancesPluralBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsEc2InstancesConstructorTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsEc2Instances::BackendFactory.select(MAEIPB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty_params_ok
|
|
|
|
AwsEc2Instances.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rejects_unrecognized_params
|
|
|
|
assert_raises(ArgumentError) { AwsEc2Instances.new(shoe_size: 9) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Search / Recall
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsEc2InstancesRecallEmptyTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsEc2Instances::BackendFactory.select(MAEIPB::Empty)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_recall_when_no_instances_exist
|
|
|
|
refute AwsEc2Instances.new.exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AwsEc2InstancesRecallBasicTest < Minitest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
AwsEc2Instances::BackendFactory.select(MAEIPB::Basic)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_recall_when_some_instances_exist
|
|
|
|
assert AwsEc2Instances.new.exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Properties
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsEc2InstancesProperties < Minitest::Test
|
|
|
|
def setup
|
|
|
|
AwsEc2Instances::BackendFactory.select(MAEIPB::Basic)
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
2018-05-10 18:54:33 +00:00
|
|
|
def test_property_instance_ids_when_no_instances_exist
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsEc2Instances::BackendFactory.select(MAEIPB::Empty)
|
2018-05-10 18:54:33 +00:00
|
|
|
empty = AwsEc2Instances.new
|
|
|
|
assert_kind_of(Array, empty.instance_ids)
|
|
|
|
assert_empty(empty.instance_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_property_instance_ids_when_instances_exist
|
|
|
|
basic = AwsEc2Instances.new
|
|
|
|
assert_kind_of(Array, basic.instance_ids)
|
2019-06-11 22:24:35 +00:00
|
|
|
assert(basic.instance_ids.include?("i-deadbeef"))
|
2018-05-10 18:54:33 +00:00
|
|
|
assert_equal(3, basic.instance_ids.length)
|
2019-06-11 22:24:35 +00:00
|
|
|
assert(basic.instance_ids.include?("i-11112222"))
|
2018-05-10 18:54:33 +00:00
|
|
|
refute(basic.instance_ids.include?(nil))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
module MAEIPB
|
|
|
|
class Empty < AwsBackendBase
|
|
|
|
def describe_instances(query = {})
|
|
|
|
OpenStruct.new( reservations: [] )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Basic < AwsBackendBase
|
|
|
|
def describe_instances(query = {})
|
|
|
|
Aws::EC2::Types::DescribeInstancesResult.new(
|
|
|
|
reservations: [
|
|
|
|
Aws::EC2::Types::Reservation.new(
|
|
|
|
instances: [
|
|
|
|
Aws::EC2::Types::Instance.new(
|
|
|
|
# Many, many other properties available here.
|
|
|
|
# We're starting with what we support.
|
2019-06-11 22:24:35 +00:00
|
|
|
instance_id: "i-0e8541d718e67e1be"
|
2018-05-10 18:54:33 +00:00
|
|
|
),
|
|
|
|
Aws::EC2::Types::Instance.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
instance_id: "i-deadbeef"
|
2018-05-10 18:54:33 +00:00
|
|
|
),
|
2019-06-11 22:24:35 +00:00
|
|
|
]
|
2018-05-10 18:54:33 +00:00
|
|
|
),
|
|
|
|
Aws::EC2::Types::Reservation.new(
|
|
|
|
instances: [
|
|
|
|
Aws::EC2::Types::Instance.new(
|
2019-06-11 22:24:35 +00:00
|
|
|
instance_id: "i-11112222"
|
2018-05-10 18:54:33 +00:00
|
|
|
),
|
2019-06-11 22:24:35 +00:00
|
|
|
]
|
2018-05-10 18:54:33 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|