2017-01-27 18:38:04 +00:00
|
|
|
require 'helper'
|
|
|
|
|
|
|
|
require 'ec2'
|
|
|
|
|
|
|
|
class TestEc2 < Minitest::Test
|
2017-02-01 22:31:18 +00:00
|
|
|
Id = "instance-id"
|
|
|
|
|
2017-01-27 18:38:04 +00:00
|
|
|
def setup
|
2017-02-01 22:31:18 +00:00
|
|
|
@mockConn = Minitest::Mock.new
|
|
|
|
@mockClient = Minitest::Mock.new
|
|
|
|
@mockResource = Minitest::Mock.new
|
2017-01-27 18:38:04 +00:00
|
|
|
|
2017-02-01 22:31:18 +00:00
|
|
|
@mockConn.expect :ec2_client, @mockClient
|
|
|
|
@mockConn.expect :ec2_resource, @mockResource
|
2017-01-27 18:38:04 +00:00
|
|
|
end
|
|
|
|
|
2017-02-08 18:46:52 +00:00
|
|
|
def test_that_id_returns_id_directly_when_constructed_with_an_id
|
|
|
|
assert_equal Id, Ec2.new(Id, @mockConn).id
|
2017-01-27 18:38:04 +00:00
|
|
|
end
|
|
|
|
|
2017-02-08 18:46:52 +00:00
|
|
|
def test_that_id_returns_fetched_id_when_constructed_with_a_name
|
2017-02-01 22:31:18 +00:00
|
|
|
mockInstance = Minitest::Mock.new
|
|
|
|
|
|
|
|
mockInstance.expect :nil?, false
|
|
|
|
mockInstance.expect :id, Id
|
|
|
|
|
|
|
|
@mockResource.expect :instances, [mockInstance], [Hash]
|
|
|
|
|
2017-02-08 18:46:52 +00:00
|
|
|
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?
|
2017-02-01 22:31:18 +00:00
|
|
|
end
|
2017-02-08 18:46:52 +00:00
|
|
|
|
|
|
|
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
|
2017-01-27 18:38:04 +00:00
|
|
|
end
|