1
|
require 'test_plugin_helper'
|
2
|
|
3
|
module Api
|
4
|
module V2
|
5
|
class ContainersControllerTest < ActionController::TestCase
|
6
|
test 'index returns a list of all containers' do
|
7
|
get :index, {}, set_session_user
|
8
|
assert_response :success
|
9
|
assert_template 'index'
|
10
|
end
|
11
|
|
12
|
context 'container operations' do
|
13
|
setup do
|
14
|
@container = FactoryGirl.create(:container, :name => 'foo')
|
15
|
end
|
16
|
|
17
|
test 'logs returns latest lines of container log' do
|
18
|
fake_container = Struct.new(:logs)
|
19
|
fake_container.expects(:logs).returns('I am a log').twice
|
20
|
Docker::Container.expects(:get).with(@container.uuid).returns(fake_container)
|
21
|
get :logs, :id => @container.id
|
22
|
assert_response :success
|
23
|
assert_equal ActiveSupport::JSON.decode(response.body)['logs'], fake_container.logs
|
24
|
end
|
25
|
|
26
|
test 'show returns information about container' do
|
27
|
get :show, :id => @container.id
|
28
|
assert_response :success
|
29
|
assert_equal ActiveSupport::JSON.decode(response.body)['name'], 'foo'
|
30
|
end
|
31
|
|
32
|
test 'delete removes a container in foreman and in Docker host' do
|
33
|
delete :destroy, :id => @container.id
|
34
|
assert_response :success
|
35
|
assert_equal ActiveSupport::JSON.decode(response.body)['name'], 'foo'
|
36
|
end
|
37
|
|
38
|
test 'power call turns on/off container in Docker host' do
|
39
|
Fog.mock!
|
40
|
Fog::Compute::Fogdocker::Server.any_instance.expects(:start)
|
41
|
put :power, :id => @container.id, :power_action => 'start'
|
42
|
assert_response :success
|
43
|
end
|
44
|
|
45
|
test 'power call checks status of container in Docker host' do
|
46
|
Fog.mock!
|
47
|
Fog::Compute::Fogdocker::Server.any_instance.expects(:ready?).returns(false)
|
48
|
put :power, :id => @container.id, :power_action => 'status'
|
49
|
assert_response :success
|
50
|
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
51
|
end
|
52
|
|
53
|
test 'power call host' do
|
54
|
Fog.mock!
|
55
|
Fog::Compute::Fogdocker::Server.any_instance.expects(:ready?).returns(false)
|
56
|
put :power, :id => @container.id, :power_action => 'status'
|
57
|
assert_response :success
|
58
|
assert_equal ActiveSupport::JSON.decode(response.body)['running'], false
|
59
|
end
|
60
|
|
61
|
test 'creates a container with correct params' do
|
62
|
Service::Containers.any_instance.expects(:pull_image).returns(true)
|
63
|
Service::Containers.any_instance.expects(:start_container).returns(true)
|
64
|
post :create, :container => { :name => 'foo', :registry_id => 3, :image => 'centos:7' }
|
65
|
assert_response :created
|
66
|
end
|
67
|
end
|
68
|
end
|
69
|
end
|
70
|
end
|