Project

General

Profile

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

foreman-docker / test / functionals / containers_steps_controller_test.rb @ ef3feba4

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!(:name => '1654', :value => 'tcp')
47
      state.environment.exposed_ports.create!(:name => '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 :name => e.name,
55
                                       :value => e.value,
56
                                       :priority => e.priority
57
      end
58
      # Check if parametrized value of container matches Docker API's expectations
59
      assert @container.parametrize.key? "ExposedPorts"
60
      assert @container.parametrize["ExposedPorts"].key? "1654/tcp"
61
      assert @container.parametrize["ExposedPorts"].key? "1655/udp"
62
    end
63

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

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