Project

General

Profile

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

foreman_docker / test / functionals / containers_steps_controller_test.rb @ bc82d5d5

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 'wizard finishes with a redirect to the managed container' do
10
      state = DockerContainerWizardState.create!
11
      Service::Containers.any_instance.expects(:start_container!).with(equals(state))
12
        .returns(@container)
13
      put :update, { :wizard_state_id => state.id,
14
                     :id => :environment,
15
                     :docker_container_wizard_states_environment => { :tty => false } },
16
          set_session_user
17

    
18
      assert_redirected_to container_path(:id => @container.id)
19
    end
20

    
21
    test 'image show doesnot load katello' do
22
      compute_resource = FactoryGirl.create(:docker_cr)
23
      state = DockerContainerWizardState.create!
24
      create_options = { :wizard_state => state,
25
                         :compute_resource_id => compute_resource.id
26

    
27
                       }
28
      state.preliminary = DockerContainerWizardStates::Preliminary.create!(create_options)
29
      DockerContainerWizardState.expects(:find).at_least_once.returns(state)
30
      get :show, { :wizard_state_id => state.id, :id => :image }, set_session_user
31
      refute state.image.katello?
32
      refute response.body.include?("katello") # this is code generated by katello partial
33
      docker_image = @controller.instance_eval do
34
        @docker_container_wizard_states_image
35
      end
36
      assert_equal state.image, docker_image
37
    end
38

    
39
    test 'new container respects exposed_ports configuration' do
40
      state = DockerContainerWizardState.create!
41
      environment_options = {
42
        :docker_container_wizard_state_id => state.id
43
      }
44
      state.environment = DockerContainerWizardStates::Environment.create!(environment_options)
45
      state.environment.exposed_ports.create!(:name => '1654', :value => 'tcp')
46
      state.environment.exposed_ports.create!(:name => '1655', :value => 'udp')
47
      get :show, { :wizard_state_id => state.id, :id => :environment }, set_session_user
48
      assert response.body.include?("1654")
49
      assert response.body.include?("1655")
50

    
51
      # Load ExposedPort variables into container
52
      state.environment.exposed_ports.each do |e|
53
        @container.exposed_ports.build :name => e.name,
54
                                       :value => e.value,
55
                                       :priority => e.priority
56
      end
57
      # Check if parametrized value of container matches Docker API's expectations
58
      assert @container.parametrize.key? "ExposedPorts"
59
      assert @container.parametrize["ExposedPorts"].key? "1654/tcp"
60
      assert @container.parametrize["ExposedPorts"].key? "1655/udp"
61
    end
62

    
63
    test 'new container respects dns configuration' do
64
      state = DockerContainerWizardState.create!
65
      environment_options = {
66
        :docker_container_wizard_state_id => state.id
67
      }
68
      state.environment = DockerContainerWizardStates::Environment.create!(environment_options)
69
      state.environment.dns.create!(:name => '18.18.18.18')
70
      state.environment.dns.create!(:name => '19.19.19.19')
71
      get :show, { :wizard_state_id => state.id, :id => :environment }, set_session_user
72
      assert response.body.include?("18.18.18.18")
73
      assert response.body.include?("19.19.19.19")
74

    
75
      # Load Dns variables into container
76
      state.environment.dns.each do |e|
77
        @container.dns.build :name => e.name,
78
                             :priority => e.priority
79
      end
80
      # Check if parametrized value of container matches Docker API's expectations
81
      assert @container.parametrize.key? "HostConfig"
82
      assert @container.parametrize["HostConfig"].key? "Dns"
83
      assert @container.parametrize["HostConfig"].value? ["18.18.18.18", "19.19.19.19"]
84
    end
85
  end
86
end