From 8e44b369a9ace264d71d02b0df25455210db44b9 Mon Sep 17 00:00:00 2001 From: Josh Lane Date: Mon, 29 Dec 2014 15:33:01 -0800 Subject: [PATCH] [aws/sns] basic subscription mock --- .../aws/requests/sns/list_subscriptions.rb | 9 ++++++ .../sns/list_subscriptions_by_topic.rb | 11 +++++++ lib/fog/aws/requests/sns/subscribe.rb | 30 +++++++++++++++++++ lib/fog/aws/sns.rb | 3 +- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib/fog/aws/requests/sns/list_subscriptions.rb b/lib/fog/aws/requests/sns/list_subscriptions.rb index 377d230f0..fd1585ecf 100644 --- a/lib/fog/aws/requests/sns/list_subscriptions.rb +++ b/lib/fog/aws/requests/sns/list_subscriptions.rb @@ -21,6 +21,15 @@ module Fog }.merge!(options)) end end + + class Mock + def list_subscriptions(options={}) + response = Excon::Response.new + + response.body = {'Subscriptions' => self.data[:subscriptions].values, 'RequestId' => Fog::AWS::Mock.request_id} + response + end + end end end end diff --git a/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb b/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb index c6ff0a06f..5b7214bdc 100644 --- a/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb +++ b/lib/fog/aws/requests/sns/list_subscriptions_by_topic.rb @@ -23,6 +23,17 @@ module Fog }.merge!(options)) end end + + class Mock + def list_subscriptions_by_topic(arn, options={}) + response = Excon::Response.new + + subscriptions = self.data[:subscriptions].values.select { |s| s["TopicArn"] == arn } + + response.body = {'Subscriptions' => subscriptions, 'RequestId' => Fog::AWS::Mock.request_id} + response + end + end end end end diff --git a/lib/fog/aws/requests/sns/subscribe.rb b/lib/fog/aws/requests/sns/subscribe.rb index 0c1a56c04..1cf22931b 100644 --- a/lib/fog/aws/requests/sns/subscribe.rb +++ b/lib/fog/aws/requests/sns/subscribe.rb @@ -25,6 +25,36 @@ module Fog }) end end + + class Mock + def subscribe(arn, endpoint, protocol) + response = Excon::Response.new + + unless topic = self.data[:topics][arn] + response.status = 400 + response.body = { + 'Code' => 'InvalidParameterValue', + 'Message' => 'Invalid parameter: TopicArn', + 'Type' => 'Sender', + } + + return response + end + + subscription_arn = Fog::AWS::Mock.arn(@module, @account_id, "#{topic["DisplayName"]}:#{Fog::AWS::Mock.request_id}", @region) + + self.data[:subscriptions][subscription_arn] = { + "Protocol" => protocol, + "Owner" => @account_id.to_s, + "TopicArn" => arn, + "SubscriptionArn" => subscription_arn, + "Endpoint" => endpoint, + } + + response.body = { 'SubscriptionArn' => 'pending confirmation', 'RequestId' => Fog::AWS::Mock.request_id } + response + end + end end end end diff --git a/lib/fog/aws/sns.rb b/lib/fog/aws/sns.rb index 7576a6ac3..c400ee5d9 100644 --- a/lib/fog/aws/sns.rb +++ b/lib/fog/aws/sns.rb @@ -32,7 +32,8 @@ module Fog @data ||= Hash.new do |hash, region| hash[region] = Hash.new do |region_hash, key| region_hash[key] = { - :topics => {}, + :topics => {}, + :subscriptions => {}, } end end