inspec/test/unit/resources/ec2_test.rb
Viktor Yakovlyev bdd86542b0 add negative case test for exists?
Signed-off-by: Viktor Yakovlyev <Viktor.Y@D2L.com>
2017-02-16 14:33:21 -05:00

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