Project

General

Profile

Download (2.79 KB) Statistics
| Branch: | Tag: | Revision:

foreman-docker / test / functionals / image_search_controller_test.rb @ ef3feba4

1
require 'test_plugin_helper'
2

    
3
class ImageSearchControllerTest < ActionController::TestCase
4
  setup do
5
    @container = FactoryGirl.create(:docker_cr)
6
  end
7

    
8
  [Docker::Error::DockerError, Excon::Errors::Error, Errno::ECONNREFUSED].each do |error|
9
    test 'auto_complete_repository_name catches exceptions on network errors' do
10
      ForemanDocker::Docker.any_instance.expects(:exist?).raises(error)
11
      get :auto_complete_repository_name, { :search => "test", :id => @container.id },
12
          set_session_user
13
      assert_response_is_expected
14
    end
15

    
16
    test 'auto_complete_image_tag catch exceptions on network errors' do
17
      ForemanDocker::Docker.any_instance.expects(:tags).raises(error)
18
      get :auto_complete_image_tag, { :search => "test", :id => @container.id }, set_session_user
19
      assert_response_is_expected
20
    end
21

    
22
    test 'search_repository catch exceptions on network errors' do
23
      ForemanDocker::Docker.any_instance.expects(:search).raises(error)
24
      get :search_repository, { :search => "test", :id => @container.id }, set_session_user
25
      assert_response_is_expected
26
    end
27
  end
28

    
29
  test "centos 7 search responses are handled correctly" do
30
    repository = "registry-fancycorp.rhcloud.com/fancydb-rhel7/fancydb"
31
    repo_full_name = "redhat.com: #{repository}"
32
    request.env["HTTP_ACCEPT"] = "application/javascript"
33
    expected = [{  "description" => "Really fancy database app...",
34
                   "is_official" => true,
35
                   "is_trusted" => true,
36
                   "name" =>  repo_full_name,
37
                   "star_count" => 0
38
                }]
39
    ForemanDocker::Docker.any_instance.expects(:search).returns(expected).at_least_once
40
    get :search_repository, { :search => "centos", :id => @container.id }, set_session_user
41
    assert_response :success
42
    refute response.body.include?(repo_full_name)
43
    assert response.body.include?(repository)
44
  end
45

    
46
  test "fedora search responses are handled correctly" do
47
    repository = "registry-fancycorp.rhcloud.com/fancydb-rhel7/fancydb"
48
    repo_full_name = repository
49
    request.env["HTTP_ACCEPT"] = "application/javascript"
50
    expected = [{ "description" => "Really fancy database app...",
51
                  "is_official" => true,
52
                  "is_trusted" => true,
53
                  "name" =>  repo_full_name,
54
                  "star_count" => 0
55
                }]
56
    ForemanDocker::Docker.any_instance.expects(:search).returns(expected).at_least_once
57
    get :search_repository, { :search => "centos", :id => @container.id }, set_session_user
58
    assert_response :success
59
    assert response.body.include?(repo_full_name)
60
    assert response.body.include?(repository)
61
  end
62

    
63
  def assert_response_is_expected
64
    assert_response :error
65
    assert response.body.include?('An error occured during repository search:')
66
  end
67
end