Project

General

Profile

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

foreman-docker / test / functionals / containers_steps_controller_test.rb @ 2b80fdd9

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
                     :start_on_create => true,
16
                     :docker_container_wizard_states_environment => { :tty => false } },
17
          set_session_user
18

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

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

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

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

    
52
      # Load ExposedPort variables into container
53
      state.environment.exposed_ports.each do |e|
54
        @container.exposed_ports.build :key => e.key,
55
                                       :value => e.value
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!(:key => '18.18.18.18')
70
      state.environment.dns.create!(:key => '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 :key => e.key
78
      end
79
      # Check if parametrized value of container matches Docker API's expectations
80
      assert @container.parametrize.key? "HostConfig"
81
      assert @container.parametrize["HostConfig"].key? "Dns"
82
      assert @container.parametrize["HostConfig"].value? ["18.18.18.18", "19.19.19.19"]
83
    end
84

    
85
    test "does not create a container with 2 exposed ports with the same key" do
86
      state = DockerContainerWizardState.new
87
      environment_options = {
88
          :docker_container_wizard_state_id => state.id
89
      }
90
      state.environment = DockerContainerWizardStates::Environment.new(environment_options)
91
      state.environment.exposed_ports.new(:key => '1654', :value => 'tcp')
92
      state.environment.exposed_ports.new(:key => '1654', :value => 'udp')
93
      refute_valid state
94
      assert_equal "Please ensure the following parameters are unique", state.errors[:'environment.exposed_ports'].first
95
    end
96
  end
97
end