Project

General

Profile

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

foreman-docker / test / units / containers_service_test.rb @ ef3feba4

1
require 'test_plugin_helper'
2

    
3
class ContainersServiceTest < ActiveSupport::TestCase
4
  setup do
5
    @state = DockerContainerWizardState.create! do |s|
6
      s.build_preliminary(:compute_resource_id => FactoryGirl.create(:docker_cr).id,
7
                          :locations           => [taxonomies(:location1)],
8
                          :organizations       => [taxonomies(:organization1)])
9
      s.build_image(:repository_name => 'test', :tag => 'test')
10
      s.build_configuration(:name => 'test', :command => '/bin/bash')
11
      s.build_environment(:tty => false)
12
    end
13
  end
14

    
15
  test 'removes current state after successful container creation' do
16
    ret = OpenStruct.new(:id => 1)
17
    ForemanDocker::Docker.any_instance.expects(:create_image).returns(ret).with do |subject|
18
      subject.must_equal(:fromImage => "test:test")
19
    end
20
    ForemanDocker::Docker.any_instance.expects(:create_container)
21
      .returns(OpenStruct.new(:uuid => 1))
22
    Fog.mock!
23
    Service::Containers.new.start_container!(@state)
24
    Fog.unmock!
25
    assert_equal DockerContainerWizardState.where(:id => @state.id).count, 0
26
  end
27

    
28
  test 'passes errors from compute resource' do
29
    # Since the compute resource will be unreachable, this test will always
30
    # fail at the 'pull_image' step
31
    containers_service = Service::Containers.new
32
    assert_raises(ActiveRecord::Rollback) do
33
      containers_service.create_container_object(@state)
34
    end
35
    assert containers_service.errors.present?
36
  end
37

    
38
end