Project

General

Profile

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

foreman-docker / test / functionals / containers_controller_test.rb @ d2e54db4

1 8b1f4103 Daniel Lobato
require 'test_plugin_helper'
2
3
class ContainersControllerTest < ActionController::TestCase
4
  test 'redirect if Docker provider is not available' do
5
    get :index, {}, set_session_user
6
    assert_redirected_to new_compute_resource_path
7
  end
8
9
  test 'index if Docker resource is available' do
10
    Fog.mock!
11
    # Avoid rendering errors by not retrieving any container
12
    ComputeResource.any_instance.stubs(:vms).returns([])
13
    FactoryGirl.create(:docker_cr)
14
    get :index, {}, set_session_user
15
    assert_template 'index'
16
  end
17
18
  test 'deleting a container in compute resource redirects to containers index' do
19
    Fog.mock!
20
    container_resource = FactoryGirl.create(:docker_cr)
21
    container          = container_resource.vms.first
22
    container.class.any_instance.expects(:destroy).returns(true)
23
    delete :destroy, { :compute_resource_id => container_resource,
24
                       :id                  => container.id }, set_session_user
25
    assert_redirected_to containers_path
26
  end
27 387babdd Daniel Lobato
28
  test 'committing a managed container' do
29
    container = FactoryGirl.create(:container)
30
    request.env['HTTP_REFERER'] = container_path(:id => container.id)
31
    commit_hash = { :author => 'a', :repo => 'b', :tag => 'c', :comment => 'd' }
32
33
    mock_container = mock
34 5397ee73 David Davis
    ::Docker::Container.expects(:get).with(container.uuid, anything, anything)
35
      .returns(mock_container)
36 387babdd Daniel Lobato
    mock_container.expects(:commit).with(commit_hash)
37
38
    post :commit, { :commit => commit_hash,
39
                    :id     => container.id }, set_session_user
40
  end
41 8b1f4103 Daniel Lobato
end