1
|
require 'rubygems'
|
2
|
require 'minitest/autorun'
|
3
|
|
4
|
require './test/support/repository_support'
|
5
|
require './lib/runcible'
|
6
|
|
7
|
module Extensions
|
8
|
module TestOstreeRepositoryBase
|
9
|
def setup
|
10
|
@support = RepositorySupport.new('ostree')
|
11
|
@extension = TestRuncible.server.extensions.repository
|
12
|
end
|
13
|
end
|
14
|
|
15
|
class TestOstreeRepositoryCreate < MiniTest::Unit::TestCase
|
16
|
include TestOstreeRepositoryBase
|
17
|
|
18
|
def teardown
|
19
|
@support.destroy_repo
|
20
|
super
|
21
|
end
|
22
|
|
23
|
def test_create_with_importer
|
24
|
response = @extension.create_with_importer(RepositorySupport.repo_id, :id => 'ostree_web_importer')
|
25
|
assert_equal 201, response.code
|
26
|
response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
|
27
|
assert_equal RepositorySupport.repo_id, response['id']
|
28
|
assert_equal 'ostree_web_importer', response['importers'].first['importer_type_id']
|
29
|
end
|
30
|
|
31
|
def test_create_with_importer_object
|
32
|
url = "http://cdn.qa.redhat.com/content/htb/rhel/server/7/x86_64/extras/ostree/"
|
33
|
branches = ["redhat-atomic-host/el7.0/x86_64/base", "redhat-atomic-host/el7.0/x86_64/medium"]
|
34
|
mock_importer = Runcible::Models::OstreeImporter.new(:feed => url,
|
35
|
:branches => branches)
|
36
|
response = @extension.create_with_importer(RepositorySupport.repo_id, mock_importer)
|
37
|
assert_equal 201, response.code
|
38
|
response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
|
39
|
assert_equal RepositorySupport.repo_id, response['id']
|
40
|
assert_equal 'ostree_web_importer', response['importers'].first['importer_type_id']
|
41
|
|
42
|
@extension.expects(:create).with(RepositorySupport.repo_id, has_entry(:notes, anything)).returns(true)
|
43
|
@extension.create_with_importer(RepositorySupport.repo_id, Runcible::Models::OstreeImporter.new)
|
44
|
end
|
45
|
|
46
|
def test_create_with_distributors
|
47
|
distributors = [{'type_id' => 'ostree_web_distributor', 'id' => '123', 'auto_publish' => true,
|
48
|
'config' => {'ostree_publish_directory' => '/path'}}]
|
49
|
response = @extension.create_with_distributors(RepositorySupport.repo_id, distributors)
|
50
|
|
51
|
assert_equal 201, response.code
|
52
|
assert_equal RepositorySupport.repo_id, response['id']
|
53
|
end
|
54
|
|
55
|
def test_create_with_distributor_object
|
56
|
repo_id = "#{RepositorySupport.repo_id}_distro"
|
57
|
ostree_publish_directory = "/path"
|
58
|
relative_path = "/relative_path"
|
59
|
mock_distro = Runcible::Models::OstreeDistributor.new(:ostree_publish_directory => ostree_publish_directory,
|
60
|
:id => '123',
|
61
|
:relative_path => relative_path)
|
62
|
response = @extension.create_with_distributors(repo_id, [mock_distro])
|
63
|
assert_equal 201, response.code
|
64
|
response = @extension.retrieve(repo_id, :details => true)
|
65
|
assert_equal repo_id, response['id']
|
66
|
assert_equal 'ostree_web_distributor', response['distributors'].first['distributor_type_id']
|
67
|
assert_equal relative_path, response['distributors'].first['config']["relative_path"]
|
68
|
assert_equal ostree_publish_directory, response['distributors'].first['config']["ostree_publish_directory"]
|
69
|
ensure
|
70
|
@support.destroy_repo(repo_id)
|
71
|
end
|
72
|
|
73
|
def test_create_with_importer_and_distributors
|
74
|
distributors = [{'type_id' => 'ostree_web_distributor', 'id' => '123', 'auto_publish' => true,
|
75
|
'config' => {}}]
|
76
|
response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id,
|
77
|
{:id => 'ostree_web_importer'}, distributors)
|
78
|
assert_equal 201, response.code
|
79
|
|
80
|
response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
|
81
|
assert_equal RepositorySupport.repo_id, response['id']
|
82
|
assert_equal 'ostree_web_distributor', response['distributors'].first['distributor_type_id']
|
83
|
end
|
84
|
|
85
|
def test_create_with_importer_and_distributors_objects
|
86
|
distributor_depth = -1
|
87
|
distributors = [Runcible::Models::OstreeDistributor.new(:id => '123', :depth => distributor_depth)]
|
88
|
importer = Runcible::Models::OstreeImporter.new
|
89
|
importer_depth = 4
|
90
|
importer.depth = importer_depth
|
91
|
response = @extension.create_with_importer_and_distributors(RepositorySupport.repo_id, importer, distributors)
|
92
|
assert_equal 201, response.code
|
93
|
|
94
|
response = @extension.retrieve(RepositorySupport.repo_id, :details => true)
|
95
|
assert_equal RepositorySupport.repo_id, response['id']
|
96
|
assert_equal 'ostree_web_importer', response['importers'].first['importer_type_id']
|
97
|
assert_equal importer_depth, response['importers'].first['config']['depth']
|
98
|
assert_equal 'ostree_web_distributor', response['distributors'].first['distributor_type_id']
|
99
|
assert_equal distributor_depth, response['distributors'].first['config']['depth']
|
100
|
end
|
101
|
end
|
102
|
|
103
|
class TestOstreeBranchRepositoryUnitList < MiniTest::Unit::TestCase
|
104
|
def self.before_suite
|
105
|
@@extension = TestRuncible.server.extensions.repository
|
106
|
self.support = RepositorySupport.new("ostree")
|
107
|
self.support.destroy_repo
|
108
|
self.support.create_and_sync_repo(:importer => true)
|
109
|
end
|
110
|
|
111
|
def self.after_suite
|
112
|
self.support.destroy_repo
|
113
|
end
|
114
|
|
115
|
def test_ostree_branch_ids
|
116
|
response = @@extension.ostree_branch_ids(RepositorySupport.repo_id)
|
117
|
refute_empty response
|
118
|
assert_kind_of String, response.first
|
119
|
end
|
120
|
|
121
|
def test_ostree_branches
|
122
|
response = @@extension.ostree_branches(RepositorySupport.repo_id)
|
123
|
refute_empty response
|
124
|
assert_kind_of Hash, response.first
|
125
|
assert_includes response.first.keys, "branch"
|
126
|
assert_includes response.first.keys, "commit"
|
127
|
assert_includes response.first.keys, "metadata"
|
128
|
assert_includes response.first["metadata"].keys, "version"
|
129
|
end
|
130
|
end
|
131
|
end
|