diff --git a/lib/fog/fogdocker/compute.rb b/lib/fog/fogdocker/compute.rb index 1c0cee4db..35ab9faa4 100644 --- a/lib/fog/fogdocker/compute.rb +++ b/lib/fog/fogdocker/compute.rb @@ -25,6 +25,7 @@ module Fog request :image_create request :image_delete request :image_get + request :image_search class Mock def initialize(options={}) diff --git a/lib/fog/fogdocker/models/compute/images.rb b/lib/fog/fogdocker/models/compute/images.rb index 2eff66472..65b46fd56 100644 --- a/lib/fog/fogdocker/models/compute/images.rb +++ b/lib/fog/fogdocker/models/compute/images.rb @@ -14,6 +14,10 @@ module Fog def get(id) new service.image_get(id) end + + def image_search(query = {}) + service.image_search(query) + end end end end diff --git a/lib/fog/fogdocker/requests/compute/image_search.rb b/lib/fog/fogdocker/requests/compute/image_search.rb new file mode 100644 index 000000000..c0317f251 --- /dev/null +++ b/lib/fog/fogdocker/requests/compute/image_search.rb @@ -0,0 +1,29 @@ +module Fog + module Compute + class Fogdocker + class Real + def image_search(query = {}) + Docker::Util.parse_json(Docker.connection.get('/images/search', query)).map do |image| + downcase_hash_keys(image) + end + end + end + class Mock + def image_search(query = {}) + [ + {"description" => "", + "is_official" => false, + "is_automated" => false, + "name" => "wma55/u1210sshd", + "star_count" => 0}, + {"description" => "", + "is_official" => false, + "is_automated" => false, + "name" => "jdswinbank/sshd", + "star_count" => 0} + ] + end + end + end + end +end diff --git a/tests/fogdocker/compute_tests.rb b/tests/fogdocker/compute_tests.rb index a9ef742e2..391e98690 100644 --- a/tests/fogdocker/compute_tests.rb +++ b/tests/fogdocker/compute_tests.rb @@ -10,7 +10,7 @@ Shindo.tests('Fog::Compute[:fogdocker]', ['fogdocker']) do tests("Compute requests") do %w{ api_version container_all container_create container_delete container_get - container_action image_all image_create image_delete image_get }.each do |collection| + container_action image_all image_create image_delete image_get image_search }.each do |collection| test("it should respond to #{collection}") { compute.respond_to? collection } end end diff --git a/tests/fogdocker/requests/compute/image_search_tests.rb b/tests/fogdocker/requests/compute/image_search_tests.rb new file mode 100644 index 000000000..1b2fd41b5 --- /dev/null +++ b/tests/fogdocker/requests/compute/image_search_tests.rb @@ -0,0 +1,11 @@ +Shindo.tests("Fog::Compute[:fogdocker] | image_search request", 'fogdocker') do + + compute = Fog::Compute[:fogdocker] + + tests("Search images") do + response = compute.image_search('term' => 'test') + test("should be a kind of Array") { response.kind_of? Array} + test("Array elements should be a kind of Hash") { response.first.kind_of? Hash} + test("response elemetns should have a name") { !response.first['name'].nil? && !response.first['name'].empty? } + end +end