mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
bdd86542b0
Signed-off-by: Viktor Yakovlyev <Viktor.Y@D2L.com>
60 lines
1.6 KiB
Ruby
60 lines
1.6 KiB
Ruby
require 'helper'
|
|
|
|
require 'ec2'
|
|
|
|
class TestEc2 < Minitest::Test
|
|
Id = "instance-id"
|
|
|
|
def setup
|
|
@mockConn = Minitest::Mock.new
|
|
@mockClient = Minitest::Mock.new
|
|
@mockResource = Minitest::Mock.new
|
|
|
|
@mockConn.expect :ec2_client, @mockClient
|
|
@mockConn.expect :ec2_resource, @mockResource
|
|
end
|
|
|
|
def test_that_id_returns_id_directly_when_constructed_with_an_id
|
|
assert_equal Id, Ec2.new(Id, @mockConn).id
|
|
end
|
|
|
|
def test_that_id_returns_fetched_id_when_constructed_with_a_name
|
|
mockInstance = Minitest::Mock.new
|
|
|
|
mockInstance.expect :nil?, false
|
|
mockInstance.expect :id, Id
|
|
@mockResource.expect :instances, [mockInstance], [Hash]
|
|
|
|
assert_equal Id, Ec2.new({name: 'cut'}, @mockConn).id
|
|
end
|
|
|
|
def test_that_instance_returns_instance_when_instance_exists
|
|
mockInstance = Object.new
|
|
|
|
@mockResource.expect :instance, mockInstance, [Id]
|
|
|
|
assert_same mockInstance, Ec2.new(Id, @mockConn).send(:instance)
|
|
end
|
|
|
|
def test_that_instance_returns_nil_when_instance_does_not_exist
|
|
@mockResource.expect :instance, nil, [Id]
|
|
|
|
assert Ec2.new(Id, @mockConn).send(:instance).nil?
|
|
end
|
|
|
|
def test_that_exists_returns_true_when_instance_exists
|
|
mockInstance = Minitest::Mock.new
|
|
mockInstance.expect :exists?, true
|
|
@mockResource.expect :instance, mockInstance, [Id]
|
|
|
|
assert Ec2.new(Id, @mockConn).exists?
|
|
end
|
|
|
|
def test_that_exists_returns_false_when_instance_does_not_exist
|
|
mockInstance = Minitest::Mock.new
|
|
mockInstance.expect :exists?, false
|
|
@mockResource.expect :instance, mockInstance, [Id]
|
|
|
|
assert !Ec2.new(Id, @mockConn).exists?
|
|
end
|
|
end
|