1
|
require 'rubygems'
|
2
|
require 'minitest/autorun'
|
3
|
|
4
|
require './test/support/repository_support'
|
5
|
require './test/support/consumer_support'
|
6
|
require './lib/runcible/resources/task_group'
|
7
|
|
8
|
module Resources
|
9
|
module TestTaskGroupBase
|
10
|
def setup
|
11
|
@consumer_support = ConsumerSupport.new
|
12
|
@resource = TestRuncible.server.resources.task_group
|
13
|
@repo_resource = TestRuncible.server.resources.repository
|
14
|
|
15
|
@criteria = {
|
16
|
'parallel' => true,
|
17
|
'repo_criteria' => { 'filters' => { 'id' => { '$in' => [RepositorySupport.repo_id] } } }
|
18
|
}
|
19
|
@response = @repo_resource.regenerate_applicability(@criteria)
|
20
|
@group_id = @response["group_id"]
|
21
|
end
|
22
|
end
|
23
|
|
24
|
class TestTaskGroup < MiniTest::Unit::TestCase
|
25
|
include TestTaskGroupBase
|
26
|
def self.before_suite
|
27
|
self.support = RepositorySupport.new
|
28
|
self.support.create_and_sync_repo(:importer_and_distributor => true)
|
29
|
end
|
30
|
|
31
|
def self.after_suite
|
32
|
self.support.destroy_repo
|
33
|
end
|
34
|
|
35
|
def test_path
|
36
|
path = @resource.class.path
|
37
|
assert_match 'task_groups/', path
|
38
|
end
|
39
|
|
40
|
def test_path_with_task_id
|
41
|
path = @resource.class.path(@group_id)
|
42
|
assert_match "task_groups/#{@group_id}/", path
|
43
|
end
|
44
|
|
45
|
def test_summary_path_with_task_id
|
46
|
path = @resource.class.summary_path(@group_id)
|
47
|
assert_match "task_groups/#{@group_id}/state_summary/", path
|
48
|
end
|
49
|
|
50
|
def test_summary
|
51
|
response = @resource.summary(@group_id)
|
52
|
assert_equal 200, response.code
|
53
|
keys = ["accepted", "finished", "running", "canceled", "waiting", "skipped", "suspended", "error", "total"]
|
54
|
assert_equal [], keys - response.keys
|
55
|
assert keys.all? { |key| response[key].is_a? Numeric }
|
56
|
end
|
57
|
|
58
|
def test_completed
|
59
|
task_group = Runcible::Resources::TaskGroup.new
|
60
|
test1 = {"finished" => 10, "canceled" => 2, "skipped" => 4, "suspended" => 3, "error" => 1, "total" => 20}
|
61
|
assert task_group.completed?(test1)
|
62
|
test1["finished"] -= 1
|
63
|
refute task_group.completed?(test1)
|
64
|
end
|
65
|
end
|
66
|
|
67
|
class TestTaskGroupCancel < TestTaskGroup
|
68
|
def teardown
|
69
|
@consumer_support.destroy_consumer
|
70
|
end
|
71
|
|
72
|
def test_cancel
|
73
|
|
74
|
@consumer_support.create_consumer(true)
|
75
|
|
76
|
tasks = TestRuncible.server.resources.consumer.bind(ConsumerSupport.consumer_id, RepositorySupport.repo_id,
|
77
|
self.class.support.distributor['id'], :notify_agent => false)
|
78
|
self.class.support.wait_on_response(tasks)
|
79
|
tasks = TestRuncible.server.resources.consumer.regenerate_applicability_by_id(ConsumerSupport.consumer_id)
|
80
|
self.class.support.wait_on_response(tasks)
|
81
|
|
82
|
group_id = @repo_resource.regenerate_applicability(@criteria)['group_id']
|
83
|
|
84
|
response = @resource.cancel(group_id)
|
85
|
assert_equal 200, response.code
|
86
|
end
|
87
|
end
|
88
|
end
|