Project

General

Profile

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

foreman_docker / test / functionals / containers_steps_controller_test.rb @ ada932ab

1
require 'test_plugin_helper'
2

    
3
module Containers
4
  class StepsControllerTest < ActionController::TestCase
5
    setup do
6
      @container = FactoryGirl.create(:container)
7
    end
8

    
9
    test 'sets a docker image and tag for a new container' do
10
      put :update, { :id => :image,
11
                     :image => { :docker_registry_id => '',
12
                                 :image_id => 'centos' },
13
                     :container_id => @container.id,
14
                     :container => { :tag => 'latest' } }, set_session_user
15
      assert_response :found
16
      assert_redirected_to container_step_path(:container_id => @container.id,
17
                                               :id           => :configuration)
18
      assert_equal DockerImage.find_by_image_id('centos'), @container.reload.image
19
      assert_equal DockerTag.find_by_tag('latest'), @container.tag
20
    end
21

    
22
    context 'container creation' do
23
      setup do
24
        @container.update_attribute(:image, (image = FactoryGirl.create(:docker_image,
25
                                                                        :image_id => 'centos')))
26
        @container.update_attribute(:tag, FactoryGirl.create(:docker_tag, :image => image,
27
                                                                          :tag   => 'latest'))
28
      end
29

    
30
      test 'uuid of the created container is saved at the end of the wizard' do
31
        Fog.mock!
32
        fake_container = @container.compute_resource.send(:client).servers.first
33
        ForemanDocker::Docker.any_instance.expects(:create_container).returns(fake_container)
34
        put :update, { :id           => :environment,
35
                       :container_id => @container.id }, set_session_user
36
        assert_equal fake_container.id, Container.find(@container.id).uuid
37
      end
38

    
39
      test 'errors are displayed when container creation fails' do
40
        Docker::Container.expects(:create).raises(Docker::Error::DockerError, 'some error')
41
        put :update, { :id           => :environment,
42
                       :container_id => @container.id }, set_session_user
43
        assert_template 'environment'
44
        assert_match(/some error/, flash[:error])
45
      end
46
    end
47

    
48
    test 'wizard finishes with a redirect to the managed container' do
49
      get :show, { :id => :wicked_finish,
50
                   :container_id => @container.id }, set_session_user
51
      assert_redirected_to container_path(:id => @container.id)
52
    end
53
  end
54
end