Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking for public_url and put_object #341

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/fog/storage/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ def self.reset
def initialize(options = {})
@openstack_api_key = options[:openstack_api_key]
@openstack_username = options[:openstack_username]
@path = '/v1/AUTH_1234'
@openstack_management_url = options[:openstack_management_url] || 'http://example:8774/v2/AUTH_1234'

@openstack_management_uri = URI.parse(@openstack_management_url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks duplicated from OpenStack::Core.authenticate, which I guess is only included in the Real classes (e.g. in storage/openstack.rb). I looked around and couldn't find a better way to fit this. We could make a mixin that just parses the management URL, but it seems a bit silly. I think this is ok, but if you have an idea on how to avoid duplicating this code, I'd be all ears.


@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
Expand Down
21 changes: 21 additions & 0 deletions lib/fog/storage/openstack/requests/public_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try enabling some of the tests we currently skip in test/requests to use this with FOG_MOCK?

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
9 changes: 9 additions & 0 deletions lib/fog/storage/openstack/requests/put_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused method argument - container. If it's necessary, use _ or _container as an argument name to indicate that it won't be used. You can also write as put_object() if you want the method to accept any arguments but don't care about them.
Unused method argument - object. If it's necessary, use _ or _object as an argument name to indicate that it won't be used. You can also write as put_object(
) if you want the method to accept any arguments but don't care about them.
Unused method argument - data. If it's necessary, use _ or _data as an argument name to indicate that it won't be used. You can also write as put_object() if you want the method to accept any arguments but don't care about them.
Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used. You can also write as put_object(
) if you want the method to accept any arguments but don't care about them.
Unused method argument - block. If it's necessary, use _ or _block as an argument name to indicate that it won't be used. You can also write as put_object(*) if you want the method to accept any arguments but don't care about them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swift returns the etag of the object on PUT. We could mimic similar behavior by returning an MD5 sum of the object. This would allow us to enable some of the requests tests that currently are skipped if FOG_MOCK is set.

response = Excon::Response.new
response.status = 201
response.body = ""
response
end
end
end
end
end