From 5e9694b5ce156085b91446c47c1d6111788d90e6 Mon Sep 17 00:00:00 2001 From: Hugo Lepetit Date: Fri, 17 Nov 2017 13:29:05 +0100 Subject: [PATCH 1/3] Added mocking for storage's request 'put_object' --- lib/fog/storage/openstack/requests/put_object.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/fog/storage/openstack/requests/put_object.rb b/lib/fog/storage/openstack/requests/put_object.rb index 51615c53f..af80c3c20 100644 --- a/lib/fog/storage/openstack/requests/put_object.rb +++ b/lib/fog/storage/openstack/requests/put_object.rb @@ -36,6 +36,15 @@ def put_object(container, object, data, options = {}, &block) request(params) end end + + class Mock + def put_object(container, object, data, options = {}, &block) + response = Excon::Response.new + response.status = 201 + response.body = "" + response + end + end end end end From 21ee8e02d94bf62df10d5241d4464adfb987c85c Mon Sep 17 00:00:00 2001 From: Hugo Lepetit Date: Fri, 17 Nov 2017 13:49:46 +0100 Subject: [PATCH 2/3] Attempt to mock storage public_url request --- lib/fog/storage/openstack.rb | 3 +++ .../storage/openstack/requests/public_url.rb | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/fog/storage/openstack.rb b/lib/fog/storage/openstack.rb index 17735c38f..1b71199b9 100644 --- a/lib/fog/storage/openstack.rb +++ b/lib/fog/storage/openstack.rb @@ -58,6 +58,9 @@ def self.reset def initialize(options = {}) @openstack_api_key = options[:openstack_api_key] @openstack_username = options[:openstack_username] + @openstack_management_url = options[:openstack_management_url] || 'http://example:8774/v2/AUTH_1234' + # XXX path should be loaded thatnks to parsing or use of openstack_management_url option + # need feedback loop with maintainers in pull request @path = '/v1/AUTH_1234' end diff --git a/lib/fog/storage/openstack/requests/public_url.rb b/lib/fog/storage/openstack/requests/public_url.rb index 63a1e3948..aad56f811 100644 --- a/lib/fog/storage/openstack/requests/public_url.rb +++ b/lib/fog/storage/openstack/requests/public_url.rb @@ -21,6 +21,27 @@ def url "#{@scheme}://#{@host}:#{@port}#{@path}" end end + + class Mock + # Get public_url for an object + # + # ==== Parameters + # * container<~String> - Name of container to look in + # * object<~String> - Name of object to look for + # + def public_url(container = nil, object = nil) + return nil if container.nil? + u = "#{url}/#{Fog::OpenStack.escape(container)}" + u << "/#{Fog::OpenStack.escape(object)}" unless object.nil? + u + end + + private + + def url + "#{@scheme}://#{@host}:#{@port}#{@path}" + end + end end end end From 3ee6de0c9fec76f9bd856167690fef120e57e560 Mon Sep 17 00:00:00 2001 From: Hugo Lepetit Date: Fri, 17 Nov 2017 14:27:45 +0100 Subject: [PATCH 3/3] Attempt #2 to mock storage public_url request --- lib/fog/storage/openstack.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/fog/storage/openstack.rb b/lib/fog/storage/openstack.rb index 1b71199b9..7ea4563a8 100644 --- a/lib/fog/storage/openstack.rb +++ b/lib/fog/storage/openstack.rb @@ -59,9 +59,14 @@ def initialize(options = {}) @openstack_api_key = options[:openstack_api_key] @openstack_username = options[:openstack_username] @openstack_management_url = options[:openstack_management_url] || 'http://example:8774/v2/AUTH_1234' - # XXX path should be loaded thatnks to parsing or use of openstack_management_url option - # need feedback loop with maintainers in pull request - @path = '/v1/AUTH_1234' + + @openstack_management_uri = URI.parse(@openstack_management_url) + + @host = @openstack_management_uri.host + @path = @openstack_management_uri.path + @path.sub!(%r{/$}, '') + @port = @openstack_management_uri.port + @scheme = @openstack_management_uri.scheme end def data