test/components/queue_subscription_test.rb in propono-1.7.0 vs test/components/queue_subscription_test.rb in propono-2.0.0.rc1

- old
+ new

@@ -3,112 +3,110 @@ module Propono class QueueSubscriptionTest < Minitest::Test def setup super @suffix = "-suf" - Propono.config.queue_suffix = @suffix + propono_config.queue_suffix = @suffix end def teardown super - Propono.config.queue_suffix = "" + propono_config.queue_suffix = "" end - def test_create_topic - topic_id = 'foobar' - topic = Topic.new(topic_id) - slow_topic_id = 'foobar-slow' - slow_topic = Topic.new(slow_topic_id) - TopicCreator.expects(:find_or_create).with("#{topic_id}#{@suffix}").returns(topic) - TopicCreator.expects(:find_or_create).with("#{topic_id}#{@suffix}-slow").returns(slow_topic) - QueueSubscription.create(topic_id) + def test_create_calls_submethods + subscription = QueueSubscription.new(aws_client, propono_config, "foobar") + subscription.expects(:create_and_subscribe_main_queue) + subscription.expects(:create_and_subscribe_slow_queue) + subscription.expects(:create_misc_queues) + subscription.create end - def test_sqs_create_is_called - topic_id = "Foobar" - subscription = QueueSubscription.new(topic_id) + def test_create_main_queue + policy = "Some policy" + topic_name = "SomeName" - TopicCreator.stubs(find_or_create: Topic.new("1123")) - + subscription = QueueSubscription.new(aws_client, propono_config, topic_name) + subscription.stubs(:create_and_subscribe_slow_queue) + subscription.stubs(:create_misc_queues) + subscription.stubs(generate_policy: policy) queue_name = subscription.send(:queue_name) - sqs = Fog::AWS::SQS::Mock.new - sqs.expects(:create_queue).with(queue_name).returns(mock(body: {'QueueUrl' => Fog::AWS::SQS::Mock::QueueUrl})) - sqs.expects(:create_queue).with(queue_name + '-failed').returns(mock(body: {'QueueUrl' => Fog::AWS::SQS::Mock::QueueUrl})) - sqs.expects(:create_queue).with(queue_name + '-corrupt').returns(mock(body: {'QueueUrl' => Fog::AWS::SQS::Mock::QueueUrl})) - sqs.expects(:create_queue).with(queue_name + '-slow').returns(mock(body: {'QueueUrl' => Fog::AWS::SQS::Mock::QueueUrl})) - QueueCreator.any_instance.stubs(sqs: sqs) + topic = mock + queue = mock + aws_client.expects(:create_topic).with("#{topic_name}#{@suffix}").returns(topic) + aws_client.expects(:create_queue).with(queue_name).returns(queue) + aws_client.expects(:subscribe_sqs_to_sns).with(queue, topic) + aws_client.expects(:set_sqs_policy).with(queue, policy) subscription.create + assert_equal queue, subscription.queue end - def test_subscription_queue_name - Propono.config.application_name = "MyApp" + def test_create_slow_queue + policy = "Some policy" + topic_name = "SomeName" + slow_queue = mock - topic_id = "Foobar" - subscription = QueueSubscription.new(topic_id) + subscription = QueueSubscription.new(aws_client, propono_config, topic_name) + subscription.stubs(:create_and_subscribe_main_queue) + subscription.stubs(:create_misc_queues) + subscription.stubs(generate_policy: policy) + queue_name = subscription.send(:queue_name) - assert_equal "MyApp-Foobar#{@suffix}", subscription.send(:queue_name) - end + topic = mock + slow_queue = mock + aws_client.expects(:create_topic).with("#{topic_name}#{@suffix}-slow").returns(topic) + aws_client.expects(:create_queue).with("#{queue_name}-slow").returns(slow_queue) + aws_client.expects(:subscribe_sqs_to_sns).with(slow_queue, topic) + aws_client.expects(:set_sqs_policy).with(slow_queue, policy) - def test_subscription_queue_name_with_spaces - Propono.config.application_name = "My App" - - topic_id = "Foobar" - subscription = QueueSubscription.new(topic_id) - - assert_equal "My_App-Foobar#{@suffix}", subscription.send(:queue_name) + subscription.create + assert_equal slow_queue, subscription.slow_queue end - def test_create_calls_subscribe - arn = "arn123" + def test_create_misc_queues + policy = "Some policy" + topic_name = "SomeName" + failed_queue = mock + corrupt_queue = mock - TopicCreator.stubs(find_or_create: Topic.new(arn)) - QueueCreator.stubs(find_or_create: Queue.new(Fog::AWS::SQS::Mock::QueueUrl)) + subscription = QueueSubscription.new(aws_client, propono_config, topic_name) + subscription.stubs(:create_and_subscribe_main_queue) + subscription.stubs(:create_and_subscribe_slow_queue) + subscription.stubs(generate_policy: policy) + queue_name = subscription.send(:queue_name) - sns = mock() - sns.expects(:subscribe).with(arn, Fog::AWS::SQS::Mock::QueueArn, 'sqs').twice - subscription = QueueSubscription.new("Some topic") - subscription.stubs(sns: sns) + aws_client.expects(:create_queue).with("#{queue_name}-failed").returns(failed_queue) + aws_client.expects(:create_queue).with("#{queue_name}-corrupt").returns(corrupt_queue) + subscription.create + + assert_equal failed_queue, subscription.failed_queue + assert_equal corrupt_queue, subscription.corrupt_queue end - def test_create_calls_set_queue_attributes - arn = "arn123" - policy = "{foobar: 123}" + def test_subscription_queue_name + propono_config.application_name = "MyApp" - TopicCreator.stubs(find_or_create: Topic.new(arn)) - QueueCreator.stubs(find_or_create: Queue.new(Fog::AWS::SQS::Mock::QueueUrl)) + topic_name = "Foobar" + subscription = QueueSubscription.new(aws_client, propono_config, topic_name) - sqs = mock() - sqs.expects(:set_queue_attributes).with(Fog::AWS::SQS::Mock::QueueUrl, "Policy", policy).twice - subscription = QueueSubscription.new("Some topic") - subscription.stubs(sqs: sqs) - subscription.stubs(generate_policy: policy) - subscription.create + assert_equal "MyApp-Foobar#{@suffix}", subscription.send(:queue_name) end - def test_create_saves_queue - queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl) - failed_queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl) - corrupt_queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl) - slow_queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl) + def test_subscription_queue_name_with_spaces + propono_config.application_name = "My App" - QueueCreator.expects(:find_or_create).with('MyApp-SomeTopic-suf').returns(queue) - QueueCreator.expects(:find_or_create).with('MyApp-SomeTopic-suf-failed').returns(failed_queue) - QueueCreator.expects(:find_or_create).with('MyApp-SomeTopic-suf-corrupt').returns(corrupt_queue) - QueueCreator.expects(:find_or_create).with('MyApp-SomeTopic-suf-slow').returns(slow_queue) - subscription = QueueSubscription.new("SomeTopic") - subscription.create + topic_name = "Foobar" + subscription = QueueSubscription.new(aws_client, propono_config, topic_name) - assert_equal queue, subscription.queue - assert_equal failed_queue, subscription.failed_queue - assert_equal corrupt_queue, subscription.corrupt_queue + assert_equal "My_App-Foobar#{@suffix}", subscription.send(:queue_name) end def test_create_raises_with_nil_topic - subscription = QueueSubscription.new(nil) + subscription = QueueSubscription.new(aws_client, propono_config, nil) assert_raises ProponoError do subscription.create end end @@ -139,9 +137,9 @@ } ] } EOS - assert_equal policy, QueueSubscription.new(nil).send(:generate_policy, queue, topic) + assert_equal policy, QueueSubscription.new(aws_client, propono_config, nil).send(:generate_policy, queue, topic) end end end