2017-01-27 18:38:04 +00:00
|
|
|
require 'helper'
|
|
|
|
require 'ec2'
|
|
|
|
|
|
|
|
class TestEc2 < Minitest::Test
|
2017-07-05 20:31:27 +00:00
|
|
|
Id = 'instance-id'.freeze
|
2017-02-01 22:31:18 +00:00
|
|
|
|
2017-01-27 18:38:04 +00:00
|
|
|
def setup
|
2017-07-05 20:31:27 +00:00
|
|
|
@mock_conn = Minitest::Mock.new
|
|
|
|
@mock_client = Minitest::Mock.new
|
|
|
|
@mock_resource = Minitest::Mock.new
|
2017-01-27 18:38:04 +00:00
|
|
|
|
2017-07-05 20:31:27 +00:00
|
|
|
@mock_conn.expect :ec2_client, @mock_client
|
|
|
|
@mock_conn.expect :ec2_resource, @mock_resource
|
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
|
2017-07-05 20:31:27 +00:00
|
|
|
assert_equal Id, Ec2.new(Id, @mock_conn).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-07-05 20:31:27 +00:00
|
|
|
mock_instance = Minitest::Mock.new
|
|
|
|
mock_instance.expect :nil?, false
|
|
|
|
mock_instance.expect :id, Id
|
|
|
|
@mock_resource.expect :instances, [mock_instance], [Hash]
|
|
|
|
assert_equal Id, Ec2.new({ name: 'cut' }, @mock_conn).id
|
2017-02-08 18:46:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_instance_returns_instance_when_instance_exists
|
2017-07-05 20:31:27 +00:00
|
|
|
mock_instance = Object.new
|
2017-02-08 18:46:52 +00:00
|
|
|
|
2017-07-05 20:31:27 +00:00
|
|
|
@mock_resource.expect :instance, mock_instance, [Id]
|
|
|
|
assert_same mock_instance, Ec2.new(Id, @mock_conn).send(:instance)
|
2017-02-08 18:46:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_that_instance_returns_nil_when_instance_does_not_exist
|
2017-07-05 20:31:27 +00:00
|
|
|
@mock_resource.expect :instance, nil, [Id]
|
|
|
|
assert Ec2.new(Id, @mock_conn).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
|
2017-07-05 20:31:27 +00:00
|
|
|
mock_instance = Minitest::Mock.new
|
|
|
|
mock_instance.expect :exists?, true
|
|
|
|
@mock_resource.expect :instance, mock_instance, [Id]
|
|
|
|
assert Ec2.new(Id, @mock_conn).exists?
|
2017-02-08 18:46:52 +00:00
|
|
|
end
|
|
|
|
|
2017-02-16 19:33:21 +00:00
|
|
|
def test_that_exists_returns_false_when_instance_does_not_exist
|
2017-07-05 20:31:27 +00:00
|
|
|
mock_instance = Minitest::Mock.new
|
|
|
|
mock_instance.expect :exists?, false
|
|
|
|
@mock_resource.expect :instance, mock_instance, [Id]
|
|
|
|
assert !Ec2.new(Id, @mock_conn).exists?
|
2017-02-16 19:33:21 +00:00
|
|
|
end
|
2017-01-27 18:38:04 +00:00
|
|
|
end
|