forked from rock-core/autoproj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_os_repository_resolver.rb
120 lines (107 loc) · 5.1 KB
/
test_os_repository_resolver.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require "autoproj/test"
# Tests for OSRepositoryResolver
module Autoproj
describe OSRepositoryResolver do
attr_reader :subject
attr_reader :definitions
before do
@subject = OSRepositoryResolver.new
@definitions = [{ "ubuntu" => [{ "xenial" => [{ "type" => "repo" }] }] }]
end
describe "#load" do
it "raises if file does not exist" do
assert_raises do
OSRepositoryResolver.load("/does/not/exist")
end
end
it "raises if file has invalid yml syntax" do
assert_raises do
OSRepositoryResolver.load(File.join(File.dirname(__FILE__), "data", "invalid.osrepos"))
end
end
it "verifies and loads definitions if yml syntax is correct" do
@subject = flexmock(OSRepositoryResolver)
subject.should_receive(:verify_definitions).with(definitions)
result = subject.load(File.join(File.dirname(__FILE__), "data", "test.osrepos"))
assert_equal definitions, result.definitions
end
end
describe "#merge" do
it "merges definitions in the receiver" do
new_defs = [{ "debian" => [{ "jessie" => [{ "type" => "key" }] }] }]
new_resolver = OSRepositoryResolver.new(new_defs, "/path/to/some.osrepos")
@subject = OSRepositoryResolver.new(definitions, "/foo/test.osrepos")
@subject.merge(new_resolver)
all_definitions = []
all_definitions << [["/foo/test.osrepos"], definitions.first]
all_definitions << [["/path/to/some.osrepos"], new_defs.first]
assert_equal subject.all_definitions, all_definitions.to_set
end
end
describe "#definitions" do
it "returns an array of the merged definitions" do
definitions << { "debian" => [{ "jessie" => [{ "type" => "key" }] }] }
definitions << { "debian" => [{ "jessie" => [{ "type" => "key" }] }] }
@subject = OSRepositoryResolver.new(definitions, "/foo/test.osrepos")
assert_equal subject.definitions, definitions.uniq
end
end
describe "#all_entries" do
it "returns an array of the merged entries" do
definitions << { "debian" => [{ "jessie" => [{ "type" => "key" }] }] }
definitions << { "debian" => [{ "jessie" => [{ "type" => "key" }] }] }
@subject = OSRepositoryResolver.new(definitions, "/foo/test.osrepos")
assert_equal subject.all_entries, [{ "type" => "repo" }, { "type" => "key" }]
end
end
describe "#resolved_entries" do
it "returns an array of the entries valid for this OS" do
definitions << { "debian" => [{ "jessie" => [{ "type" => "key" }] }] }
definitions << { "debian" => [{ "jessie" => [{ "type" => "key" }] }] }
@subject = OSRepositoryResolver.new(
definitions,
"/foo/test.osrepos",
operating_system: [["ubuntu"], ["xenial"]]
)
assert_equal subject.resolved_entries, [{ "type" => "repo" }]
end
end
describe "#resolved_entries" do
it 'allows "default" as a release name while resolving entries' do
definitions << { "ubuntu" => [{ "default" => [{ "type" => "key" }] }] }
definitions << { "debian" => [{ "jessie" => [{ "type" => "foo" }] }] }
@subject = OSRepositoryResolver.new(
definitions,
"/foo/test.osrepos",
operating_system: [["ubuntu"], ["xenial"]]
)
assert_equal subject.resolved_entries, [{ "type" => "repo" }, { "type" => "key" }]
end
end
describe "#verify_definitions" do
it "throws if definitions are not an array" do
assert_raises ArgumentError do
OSRepositoryResolver.verify_definitions("type" => "repo")
end
end
it "throws if OS element is not a hash" do
assert_raises ArgumentError do
OSRepositoryResolver.verify_definitions(["ubuntu"])
end
end
it "throws if release element is not a array" do
assert_raises ArgumentError do
OSRepositoryResolver.verify_definitions([{ "ubuntu" => "xenial" }])
end
end
it "throws if first element of the release hash is not nil" do
assert_raises ArgumentError do
OSRepositoryResolver.verify_definitions([{ "ubuntu" => [{ "type" => "repo" }] }])
end
end
it "does not throw if definitions are valid" do
OSRepositoryResolver.verify_definitions([{ "ubuntu" => [{ "xenial" => [{ "type" => "repo" }] }] }])
end
end
end
end