test/components/queue_subscription_test.rb in propono-1.1.3 vs test/components/queue_subscription_test.rb in propono-1.2.0

- old
+ new

@@ -28,11 +28,11 @@ subscription = QueueSubscription.new(topic_id) TopicCreator.stubs(find_or_create: Topic.new("1123")) queue_name = subscription.send(:queue_name) - + sqs = mock() 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})) @@ -73,22 +73,19 @@ end def test_create_calls_set_queue_attributes arn = "arn123" policy = "{foobar: 123}" - slow_policy = "{foobar: 456}" TopicCreator.stubs(find_or_create: Topic.new(arn)) QueueCreator.stubs(find_or_create: Queue.new(Fog::AWS::SQS::Mock::QueueUrl)) sqs = mock() - sqs.expects(:set_queue_attributes).with(Fog::AWS::SQS::Mock::QueueUrl, "Policy", policy) - sqs.expects(:set_queue_attributes).with(Fog::AWS::SQS::Mock::QueueUrl, "Policy", slow_policy) + 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.stubs(generate_slow_policy: slow_policy) subscription.create end def test_create_saves_queue queue = Queue.new(Fog::AWS::SQS::Mock::QueueUrl) @@ -100,11 +97,11 @@ 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 - + assert_equal queue, subscription.queue assert_equal failed_queue, subscription.failed_queue assert_equal corrupt_queue, subscription.corrupt_queue end @@ -114,9 +111,37 @@ subscription.create end end def test_generate_policy - skip "TODO - Implement this test." + queue_arn = "queue-arn" + topic_arn = "topic-arn" + queue = mock().tap {|m|m.stubs(arn: queue_arn)} + topic = mock().tap {|m|m.stubs(arn: topic_arn)} + + policy = <<-EOS +{ + "Version": "2008-10-17", + "Id": "#{queue_arn}/SQSDefaultPolicy", + "Statement": [ + { + "Sid": "#{queue_arn}-Sid", + "Effect": "Allow", + "Principal": { + "AWS": "*" + }, + "Action": "SQS:*", + "Resource": "#{queue_arn}", + "Condition": { + "StringEquals": { + "aws:SourceArn": "#{topic_arn}" + } + } + } + ] +} +EOS + + assert_equal policy, QueueSubscription.new(nil).send(:generate_policy, queue, topic) end end end