Project

General

Profile

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

foreman-docker / test / functionals / containers_controller_test.rb @ 5397ee73

1
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

    
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
    ::Docker::Container.expects(:get).with(container.uuid, anything, anything)
35
      .returns(mock_container)
36
    mock_container.expects(:commit).with(commit_hash)
37

    
38
    post :commit, { :commit => commit_hash,
39
                    :id     => container.id }, set_session_user
40
  end
41
end