2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_ebs_volume"
|
2018-09-21 15:49:28 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
|
|
|
require "resources/aws/aws_ebs_volume"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-09-21 15:49:28 +00:00
|
|
|
class TestEbs < Minitest::Test
|
2019-05-31 21:59:06 +00:00
|
|
|
ID = "volume-id".freeze
|
2018-09-21 15:49:28 +00:00
|
|
|
|
|
|
|
def setup
|
|
|
|
@mock_conn = Minitest::Mock.new
|
|
|
|
@mock_client = Minitest::Mock.new
|
|
|
|
@mock_resource = Minitest::Mock.new
|
|
|
|
|
|
|
|
@mock_conn.expect :ec2_client, @mock_client
|
|
|
|
@mock_conn.expect :ec2_resource, @mock_resource
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_id_returns_id_directly_when_constructed_with_an_id
|
2019-05-31 21:59:06 +00:00
|
|
|
assert_equal ID, AwsEbsVolume.new(ID, @mock_conn).id
|
2018-09-21 15:49:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_id_returns_fetched_id_when_constructed_with_a_name
|
|
|
|
mock_volume = Minitest::Mock.new
|
|
|
|
mock_volume.expect :nil?, false
|
2019-05-31 21:59:06 +00:00
|
|
|
mock_volume.expect :id, ID
|
2018-09-21 15:49:28 +00:00
|
|
|
@mock_resource.expect :volumes, [mock_volume], [Hash]
|
2019-05-31 21:59:06 +00:00
|
|
|
assert_equal ID, AwsEbsVolume.new({ name: "cut" }, @mock_conn).id
|
2018-09-21 15:49:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_volume_returns_volume_when_volume_exists
|
|
|
|
mock_volume = Object.new
|
|
|
|
|
2019-05-31 21:59:06 +00:00
|
|
|
@mock_resource.expect :volume, mock_volume, [ID]
|
2018-09-21 15:49:28 +00:00
|
|
|
assert_same(
|
|
|
|
mock_volume,
|
2019-05-31 21:59:06 +00:00
|
|
|
AwsEbsVolume.new(ID, @mock_conn).send(:volume)
|
2018-09-21 15:49:28 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_volume_returns_nil_when_volume_does_not_exist
|
2019-05-31 21:59:06 +00:00
|
|
|
@mock_resource.expect :volume, nil, [ID]
|
|
|
|
assert AwsEbsVolume.new(ID, @mock_conn).send(:volume).nil?
|
2018-09-21 15:49:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_exists_returns_true_when_volume_exists
|
|
|
|
mock_volume = Minitest::Mock.new
|
|
|
|
mock_volume.expect :nil?, false
|
|
|
|
mock_volume.expect :exists?, true
|
2019-05-31 21:59:06 +00:00
|
|
|
@mock_resource.expect :volume, mock_volume, [ID]
|
|
|
|
assert AwsEbsVolume.new(ID, @mock_conn).exists?
|
2018-09-21 15:49:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_exists_returns_false_when_volume_does_not_exist
|
|
|
|
mock_volume = Minitest::Mock.new
|
|
|
|
mock_volume.expect :nil?, true
|
|
|
|
mock_volume.expect :exists?, false
|
2019-05-31 21:59:06 +00:00
|
|
|
@mock_resource.expect :volume, mock_volume, [ID]
|
|
|
|
refute AwsEbsVolume.new(ID, @mock_conn).exists?
|
2018-09-21 15:49:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_encrypted_returns_true_when_volume_is_encrypted
|
|
|
|
mock_volume = Minitest::Mock.new
|
|
|
|
mock_volume.expect :nil?, false
|
|
|
|
mock_volume.expect :encrypted, true
|
2019-05-31 21:59:06 +00:00
|
|
|
@mock_resource.expect :volume, mock_volume, [ID]
|
|
|
|
assert AwsEbsVolume.new(ID, @mock_conn).encrypted?
|
2018-09-21 15:49:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_encrypted_returns_false_when_volume_is_not_encrypted
|
|
|
|
mock_volume = Minitest::Mock.new
|
|
|
|
mock_volume.expect :nil?, false
|
|
|
|
mock_volume.expect :encrypted, false
|
2019-05-31 21:59:06 +00:00
|
|
|
@mock_resource.expect :volume, mock_volume, [ID]
|
|
|
|
refute AwsEbsVolume.new(ID, @mock_conn).encrypted?
|
2018-09-21 15:49:28 +00:00
|
|
|
end
|
|
|
|
end
|