2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "resources/aws/aws_sqs_queue"
|
2018-12-20 19:33:21 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "resource_support/aws"
|
2019-05-21 00:19:38 +00:00
|
|
|
|
2018-12-20 19:33:21 +00:00
|
|
|
# MSQB = MockSQsBackend
|
|
|
|
# Abbreviation not used outside this file
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Constructor Tests
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsSqsQueueConstructorTest < Minitest::Test
|
|
|
|
def setup
|
|
|
|
AwsSqsQueue::BackendFactory.select(AwsMSQB::Hit)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_some_args_required
|
|
|
|
assert_raises(ArgumentError) { AwsSqsQueue.new }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_accepts_scalar_url
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsSqsQueue.new("https://sqs.ap-southeast-2.amazonaws.com/5195277125796/MyQueue")
|
2018-12-20 19:33:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_constructor_accepts_url_as_hash
|
2019-06-11 22:24:35 +00:00
|
|
|
AwsSqsQueue.new(url: "https://sqs.ap-southeast-2.amazonaws.com/5195277125796/MyQueue")
|
2018-12-20 19:33:21 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
2018-12-20 19:33:21 +00:00
|
|
|
def test_constructor_rejects_unrecognized_resource_params
|
2019-06-11 22:24:35 +00:00
|
|
|
assert_raises(ArgumentError) { AwsSqsQueue.new(beep: "boop") }
|
2018-12-20 19:33:21 +00:00
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
2018-12-20 19:33:21 +00:00
|
|
|
def test_constructor_rejects_non_https_url
|
|
|
|
[
|
2019-06-11 22:24:35 +00:00
|
|
|
"not-even-a-url",
|
|
|
|
"http://example.com", # http
|
2018-12-20 19:33:21 +00:00
|
|
|
].each do |example|
|
|
|
|
assert_raises(ArgumentError) { AwsSqsQueue.new(url: example) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Search/Recall
|
|
|
|
#=============================================================================#
|
|
|
|
class AwsSqsQueueRecallTest < Minitest::Test
|
|
|
|
# No setup here - each test needs to explicitly declare
|
|
|
|
# what they want from the backend.
|
|
|
|
|
|
|
|
def test_recall_no_match_is_no_exception
|
|
|
|
AwsSqsQueue::BackendFactory.select(AwsMSQB::Miss)
|
2019-06-11 22:24:35 +00:00
|
|
|
queue = AwsSqsQueue.new("https://sqs.ap-southeast-2.amazonaws.com/12121/idontexist")
|
2018-12-20 19:33:21 +00:00
|
|
|
refute queue.exists?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_recall_match_single_result_works
|
|
|
|
AwsSqsQueue::BackendFactory.select(AwsMSQB::Hit)
|
2019-06-11 22:24:35 +00:00
|
|
|
queue = AwsSqsQueue.new("https://sqs.ap-southeast-2.amazonaws.com/12121/iexist")
|
2018-12-20 19:33:21 +00:00
|
|
|
assert queue.exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Properties
|
|
|
|
#=============================================================================#
|
|
|
|
|
|
|
|
class AwsSqsQueuePropertiesTest < Minitest::Test
|
|
|
|
# No setup here - each test needs to explicitly declare
|
|
|
|
# what they want from the backend.
|
|
|
|
|
|
|
|
#---------------------------------------
|
|
|
|
# confirmed_subscription_count
|
|
|
|
#---------------------------------------
|
|
|
|
def test_visibility_timeout
|
|
|
|
AwsSqsQueue::BackendFactory.select(AwsMSQB::Hit)
|
2019-06-11 22:24:35 +00:00
|
|
|
queue = AwsSqsQueue.new("https://sqs.ap-southeast-2.amazonaws.com/12121/iexist")
|
2018-12-20 19:33:21 +00:00
|
|
|
assert_equal(300, queue.visibility_timeout)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_not_fifo_queue
|
|
|
|
AwsSqsQueue::BackendFactory.select(AwsMSQB::Hit)
|
2019-06-11 22:24:35 +00:00
|
|
|
queue = AwsSqsQueue.new("https://sqs.ap-southeast-2.amazonaws.com/12121/iexist")
|
2018-12-20 19:33:21 +00:00
|
|
|
refute queue.is_fifo_queue
|
2019-06-11 22:24:35 +00:00
|
|
|
end
|
2018-12-20 19:33:21 +00:00
|
|
|
|
|
|
|
def test_fifo_queue
|
|
|
|
AwsSqsQueue::BackendFactory.select(AwsMSQB::FifoQueue)
|
2019-06-11 22:24:35 +00:00
|
|
|
queue = AwsSqsQueue.new("https://sqs.ap-southeast-2.amazonaws.com/12121/iexist")
|
2018-12-20 19:33:21 +00:00
|
|
|
assert queue.is_fifo_queue
|
|
|
|
assert queue.content_based_deduplication
|
2019-06-11 22:24:35 +00:00
|
|
|
end
|
2018-12-20 19:33:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
# Test Fixtures
|
|
|
|
#=============================================================================#
|
|
|
|
|
|
|
|
module AwsMSQB
|
|
|
|
|
|
|
|
class Miss < AwsBackendBase
|
|
|
|
def get_queue_attributes(criteria)
|
2019-06-11 22:24:35 +00:00
|
|
|
raise Aws::SQS::Errors::NonExistentQueue.new("No SQS queue with URL #{criteria[:url]}", "Nope")
|
2018-12-20 19:33:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Hit < AwsBackendBase
|
|
|
|
def get_queue_attributes(_criteria)
|
|
|
|
OpenStruct.new({
|
|
|
|
attributes: {
|
|
|
|
"QueueArn" => "arn:aws:sqs:ap-southeast-2:519527721296:MyQueue",
|
2019-06-11 22:24:35 +00:00
|
|
|
"VisibilityTimeout" => 300,
|
|
|
|
},
|
2018-12-20 19:33:21 +00:00
|
|
|
})
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
end
|
|
|
|
|
2018-12-20 19:33:21 +00:00
|
|
|
class FifoQueue < AwsBackendBase
|
|
|
|
def get_queue_attributes(_criteria)
|
|
|
|
OpenStruct.new({
|
|
|
|
attributes: {
|
|
|
|
"QueueArn" => "arn:aws:sqs:ap-southeast-2:519527721296:MyQueue.fifo",
|
|
|
|
"VisibilityTimeout" => 300,
|
|
|
|
"FifoQueue" => true,
|
2019-06-11 22:24:35 +00:00
|
|
|
"ContentBasedDeduplication" => true,
|
|
|
|
},
|
2018-12-20 19:33:21 +00:00
|
|
|
})
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
end
|
2019-05-21 00:19:38 +00:00
|
|
|
end
|