mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
add tests for :instance and :exists
Signed-off-by: Chris Redekop <chris.redekop@d2l.com>
This commit is contained in:
parent
1842cc2fd9
commit
9d8afa5440
1 changed files with 36 additions and 7 deletions
|
@ -14,14 +14,11 @@ class TestEc2 < Minitest::Test
|
|||
@mockConn.expect :ec2_resource, @mockResource
|
||||
end
|
||||
|
||||
def test_that_id_returns_directly_provided_id
|
||||
@cut = Ec2.new(Id, @mockConn)
|
||||
|
||||
assert_equal @cut.id, Id
|
||||
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_id_for_provided_name
|
||||
@cut = Ec2.new({name: 'cut'}, @mockConn)
|
||||
def test_that_id_returns_fetched_id_when_constructed_with_a_name
|
||||
mockInstance = Minitest::Mock.new
|
||||
|
||||
mockInstance.expect :nil?, false
|
||||
|
@ -29,6 +26,38 @@ class TestEc2 < Minitest::Test
|
|||
|
||||
@mockResource.expect :instances, [mockInstance], [Hash]
|
||||
|
||||
assert_equal @cut.id, Id
|
||||
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 = Object.new
|
||||
|
||||
@mockResource.expect :instance, mockInstance, [Id]
|
||||
|
||||
assert Ec2.new(Id, @mockConn).exists?
|
||||
end
|
||||
|
||||
# A test similar to this one should pass once issue #13 is fixed`
|
||||
# def test_that_exists_returns_false_when_instance_does_not_exist
|
||||
# @cut = Ec2.new(Id, @mockConn)
|
||||
# mockInstance = Object.new
|
||||
|
||||
# @mockResource.expect :instance, nil, [Id]
|
||||
|
||||
# assert_false @cut.exists?
|
||||
# end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue