diff --git a/lib/fog/hp/cdn.rb b/lib/fog/hp/cdn.rb index 21f1488e5..324ecb437 100644 --- a/lib/fog/hp/cdn.rb +++ b/lib/fog/hp/cdn.rb @@ -26,7 +26,9 @@ module Fog def self.data @data ||= Hash.new do |hash, key| - hash[key] = {} + hash[key] = { + :cdn_containers => {} + } end end diff --git a/lib/fog/hp/requests/cdn/delete_container.rb b/lib/fog/hp/requests/cdn/delete_container.rb index 196f93564..79570856f 100644 --- a/lib/fog/hp/requests/cdn/delete_container.rb +++ b/lib/fog/hp/requests/cdn/delete_container.rb @@ -18,6 +18,21 @@ module Fog end end + + class Mock # :nodoc:all + def delete_container(name) + response = Excon::Response.new + if self.data[:cdn_containers][name] + self.data[:cdn_containers].delete(name) + response.status = 204 + response.body = "" + response + else + raise Fog::CDN::HP::NotFound + end + end + end + end end end \ No newline at end of file diff --git a/lib/fog/hp/requests/cdn/get_containers.rb b/lib/fog/hp/requests/cdn/get_containers.rb index c1db3f014..6e78c26b4 100644 --- a/lib/fog/hp/requests/cdn/get_containers.rb +++ b/lib/fog/hp/requests/cdn/get_containers.rb @@ -26,6 +26,19 @@ module Fog end end + + class Mock # :nodoc:all + + def get_containers(options = {}) + response = Excon::Response.new + data = self.data[:cdn_containers].map {|_,v| v} + response.body = data + response.status = 200 + response + end + + end + end end end diff --git a/lib/fog/hp/requests/cdn/head_container.rb b/lib/fog/hp/requests/cdn/head_container.rb index 2f783becd..c9c043473 100644 --- a/lib/fog/hp/requests/cdn/head_container.rb +++ b/lib/fog/hp/requests/cdn/head_container.rb @@ -26,6 +26,25 @@ module Fog end end + + class Mock # :nodoc:all + def head_container(name) + response = Excon::Response.new + headers = {} + if data = self.data[:cdn_containers][name] + data.each do |k,_| + headers[k] = data[k] if data[k] + end + response.headers = headers + response.status = 204 + response.body = "" + response + else + raise Fog::CDN::HP::NotFound + end + end + end + end end end diff --git a/lib/fog/hp/requests/cdn/post_container.rb b/lib/fog/hp/requests/cdn/post_container.rb index 6ebdf31d9..fd99c592b 100644 --- a/lib/fog/hp/requests/cdn/post_container.rb +++ b/lib/fog/hp/requests/cdn/post_container.rb @@ -23,6 +23,30 @@ module Fog end end + + class Mock # :nodoc:all + def post_container(name, options = {}) + response = Excon::Response.new + container_id = Fog::Mock.random_hex(33) + if data = self.data[:cdn_containers][name] + options.each do |k,v| + data[k] = options[k] if options[k] + end + response.headers = { + "X-Cdn-Ssl-Uri" => "https://a111.cdn.net/cdn-test.net/#{container_id}/abc", + "X-Cdn-Uri" => "http://#{container_id}.cdn-test.net", + "X-Trans-Id" => Fog::Mock.random_hex(34) + } + response.status = 202 + response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n " + self.data[:cdn_containers][name] = data + response + else + raise Fog::CDN::HP::NotFound + end + end + end + end end end diff --git a/lib/fog/hp/requests/cdn/put_container.rb b/lib/fog/hp/requests/cdn/put_container.rb index 7b2a19585..66eda2088 100644 --- a/lib/fog/hp/requests/cdn/put_container.rb +++ b/lib/fog/hp/requests/cdn/put_container.rb @@ -23,6 +23,31 @@ module Fog end end + + class Mock # :nodoc:all + def put_container(name, options = {}) + response = Excon::Response.new + container_id = Fog::Mock.random_hex(33) + data = { + 'x-cdn-ssl-uri' => "https://a111.cdn.net/cdn-test.net/#{container_id}/abc", + 'cdn_enabled' => true, + 'name' => name, + 'x-cdn-uri' => "http://#{container_id}.cdn-test.net", + 'ttl' => 86400, + 'log_retention' => false + } + response.headers = { + "X-Cdn-Ssl-Uri" => "https://a111.cdn.net/cdn-test.net/#{container_id}/abc", + "X-Cdn-Uri" => "http://#{container_id}.cdn-test.net", + "X-Trans-Id" => Fog::Mock.random_hex(34) + } + response.status = 201 + response.body = "201 Created\n\n\n\n " + self.data[:cdn_containers][name] = data + response + end + end + end end end