puppet-library 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +13 -5
- data/.travis.yml +7 -4
- data/CHANGELOG.yml +4 -0
- data/{lib/puppet_library/module_repo/multi.rb → Guardfile} +6 -24
- data/README.md +15 -0
- data/Rakefile +60 -5
- data/config.ru +2 -2
- data/lib/puppet_library/forge/abstract.rb +183 -0
- data/lib/puppet_library/{module_repo → forge}/directory.rb +9 -3
- data/lib/puppet_library/forge/multi.rb +81 -0
- data/lib/puppet_library/{module_repo → forge}/proxy.rb +32 -22
- data/lib/puppet_library/forge/search_result.rb +50 -0
- data/lib/puppet_library/forge.rb +6 -91
- data/lib/puppet_library/http/cache.rb +21 -0
- data/lib/puppet_library/http.rb +22 -0
- data/lib/puppet_library/puppet_library.rb +13 -14
- data/lib/puppet_library/server.rb +22 -7
- data/lib/puppet_library/util.rb +25 -0
- data/lib/puppet_library/version.rb +1 -1
- data/lib/puppet_library.rb +8 -13
- data/puppet-library.gemspec +7 -0
- data/spec/{forge_spec.rb → forge/abstract_spec.rb} +120 -3
- data/spec/{module_repo → forge}/directory_spec.rb +27 -1
- data/spec/forge/multi_spec.rb +314 -0
- data/spec/forge/proxy_spec.rb +206 -0
- data/spec/puppet_library_spec.rb +17 -25
- data/spec/server_spec.rb +26 -3
- data/spec/spec_helper.rb +1 -1
- data/test/librarian_puppet_integration_test.rb +21 -6
- metadata +83 -37
- data/lib/puppet_library/module_metadata.rb +0 -72
- data/spec/module_repo/multi_spec.rb +0 -97
- data/spec/module_repo/proxy_spec.rb +0 -115
data/spec/spec_helper.rb
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
-
require 'simplecov'
|
18
|
+
require 'simplecov' unless RUBY_VERSION.start_with? "1.8"
|
19
19
|
require 'puppet_library'
|
20
20
|
require 'module_spec_helper'
|
21
21
|
require 'pry'
|
@@ -16,6 +16,7 @@
|
|
16
16
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
18
|
require 'spec_helper'
|
19
|
+
require 'open-uri'
|
19
20
|
|
20
21
|
module PuppetLibrary
|
21
22
|
describe "librarian-puppet integration test" do
|
@@ -25,10 +26,10 @@ module PuppetLibrary
|
|
25
26
|
let(:module_dir) { Tempfile.new("module_dir").path }
|
26
27
|
let(:project_dir) { Tempfile.new("project_dir").path }
|
27
28
|
let(:start_dir) { pwd }
|
28
|
-
let(:
|
29
|
+
let(:disk_forge) { Forge::Directory.new(module_dir) }
|
29
30
|
let(:disk_server) do
|
30
31
|
Server.set_up do |server|
|
31
|
-
server.
|
32
|
+
server.forge disk_forge
|
32
33
|
end
|
33
34
|
end
|
34
35
|
let(:disk_rack_server) do
|
@@ -44,10 +45,10 @@ module PuppetLibrary
|
|
44
45
|
disk_rack_server.start
|
45
46
|
end
|
46
47
|
end
|
47
|
-
let(:
|
48
|
+
let(:proxy_forge) { Forge::Proxy.new("http://localhost:9000") }
|
48
49
|
let(:proxy_server) do
|
49
50
|
Server.set_up do |server|
|
50
|
-
server.
|
51
|
+
server.forge proxy_forge
|
51
52
|
end
|
52
53
|
end
|
53
54
|
let(:proxy_rack_server) do
|
@@ -69,9 +70,13 @@ module PuppetLibrary
|
|
69
70
|
rm_rf project_dir
|
70
71
|
mkdir_p module_dir
|
71
72
|
mkdir_p project_dir
|
73
|
+
# Initialize to catch wiring errors
|
74
|
+
disk_rack_server
|
75
|
+
proxy_rack_server
|
76
|
+
|
77
|
+
# Start the servers
|
72
78
|
disk_server_runner
|
73
79
|
proxy_server_runner
|
74
|
-
sleep(2) # Wait for the servers to start
|
75
80
|
start_dir
|
76
81
|
cd project_dir
|
77
82
|
end
|
@@ -88,7 +93,7 @@ module PuppetLibrary
|
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
91
|
-
it "downloads
|
96
|
+
it "queries, downloads and searches through a proxy to a directory" do
|
92
97
|
add_module("puppetlabs", "apache", "1.0.0") do |metadata|
|
93
98
|
metadata["dependencies"] << { "name" => "puppetlabs/concat", "version_requirement" => ">= 2.0.0" }
|
94
99
|
metadata["dependencies"] << { "name" => "puppetlabs/stdlib", "version_requirement" => "~> 3.0.0" }
|
@@ -101,11 +106,21 @@ module PuppetLibrary
|
|
101
106
|
mod 'puppetlabs/apache'
|
102
107
|
EOF
|
103
108
|
|
109
|
+
# Install modules through the proxy
|
104
110
|
system "librarian-puppet install" or fail "call to puppet-library failed"
|
105
111
|
expect(File.directory? "modules").to be true
|
106
112
|
expect(File.directory? "modules/apache").to be true
|
107
113
|
expect(File.directory? "modules/concat").to be true
|
108
114
|
expect(File.directory? "modules/stdlib").to be true
|
115
|
+
|
116
|
+
# Search through the proxy
|
117
|
+
search_results = JSON.parse(open("http://localhost:9001/modules.json").read)
|
118
|
+
found_modules = Hash[search_results.map do |result|
|
119
|
+
[ result["full_name"], result["version"] ]
|
120
|
+
end]
|
121
|
+
expect(found_modules["puppetlabs/apache"]).to eq "1.0.0"
|
122
|
+
expect(found_modules["puppetlabs/concat"]).to eq "2.0.0"
|
123
|
+
expect(found_modules["puppetlabs/stdlib"]).to eq "3.0.0"
|
109
124
|
end
|
110
125
|
end
|
111
126
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-library
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- drrb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -56,28 +56,28 @@ dependencies:
|
|
56
56
|
name: coveralls
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '>='
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: librarian-puppet
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - '>='
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - '>='
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
@@ -98,84 +98,126 @@ dependencies:
|
|
98
98
|
name: pry
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - '>='
|
101
|
+
- - ! '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - '>='
|
108
|
+
- - ! '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: puppet
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - '>='
|
115
|
+
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - '>='
|
122
|
+
- - ! '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rack-test
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - '>='
|
129
|
+
- - ! '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - '>='
|
136
|
+
- - ! '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rake
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - '>='
|
143
|
+
- - ! '>='
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - '>='
|
150
|
+
- - ! '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - '>='
|
157
|
+
- - ! '>='
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - '>='
|
164
|
+
- - ! '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: simplecov
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - '>='
|
171
|
+
- - ! '>='
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - '>='
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: guard
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ! '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: guard-rspec
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ! '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ! '>='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: terminal-notifier-guard
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ! '>='
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ! '>='
|
179
221
|
- !ruby/object:Gem::Version
|
180
222
|
version: '0'
|
181
223
|
description: A Puppet module server
|
@@ -192,6 +234,7 @@ files:
|
|
192
234
|
- .travis.yml
|
193
235
|
- CHANGELOG.yml
|
194
236
|
- Gemfile
|
237
|
+
- Guardfile
|
195
238
|
- LICENSE.txt
|
196
239
|
- README.md
|
197
240
|
- Rakefile
|
@@ -200,27 +243,30 @@ files:
|
|
200
243
|
- config.ru
|
201
244
|
- lib/puppet_library.rb
|
202
245
|
- lib/puppet_library/forge.rb
|
246
|
+
- lib/puppet_library/forge/abstract.rb
|
247
|
+
- lib/puppet_library/forge/directory.rb
|
248
|
+
- lib/puppet_library/forge/multi.rb
|
249
|
+
- lib/puppet_library/forge/proxy.rb
|
250
|
+
- lib/puppet_library/forge/search_result.rb
|
251
|
+
- lib/puppet_library/http.rb
|
252
|
+
- lib/puppet_library/http/cache.rb
|
203
253
|
- lib/puppet_library/http/cache/in_memory.rb
|
204
254
|
- lib/puppet_library/http/cache/noop.rb
|
205
255
|
- lib/puppet_library/http/http_client.rb
|
206
256
|
- lib/puppet_library/http/url.rb
|
207
|
-
- lib/puppet_library/module_metadata.rb
|
208
|
-
- lib/puppet_library/module_repo/directory.rb
|
209
|
-
- lib/puppet_library/module_repo/multi.rb
|
210
|
-
- lib/puppet_library/module_repo/proxy.rb
|
211
257
|
- lib/puppet_library/puppet_library.rb
|
212
258
|
- lib/puppet_library/server.rb
|
213
259
|
- lib/puppet_library/util.rb
|
214
260
|
- lib/puppet_library/version.rb
|
215
261
|
- puppet-library.gemspec
|
216
|
-
- spec/
|
262
|
+
- spec/forge/abstract_spec.rb
|
263
|
+
- spec/forge/directory_spec.rb
|
264
|
+
- spec/forge/multi_spec.rb
|
265
|
+
- spec/forge/proxy_spec.rb
|
217
266
|
- spec/http/cache/in_memory_spec.rb
|
218
267
|
- spec/http/cache/noop_spec.rb
|
219
268
|
- spec/http/http_client_spec.rb
|
220
269
|
- spec/http/url_spec.rb
|
221
|
-
- spec/module_repo/directory_spec.rb
|
222
|
-
- spec/module_repo/multi_spec.rb
|
223
|
-
- spec/module_repo/proxy_spec.rb
|
224
270
|
- spec/module_spec_helper.rb
|
225
271
|
- spec/puppet_library_spec.rb
|
226
272
|
- spec/server_spec.rb
|
@@ -237,29 +283,29 @@ require_paths:
|
|
237
283
|
- lib
|
238
284
|
required_ruby_version: !ruby/object:Gem::Requirement
|
239
285
|
requirements:
|
240
|
-
- - '>='
|
286
|
+
- - ! '>='
|
241
287
|
- !ruby/object:Gem::Version
|
242
288
|
version: '0'
|
243
289
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
244
290
|
requirements:
|
245
|
-
- - '>='
|
291
|
+
- - ! '>='
|
246
292
|
- !ruby/object:Gem::Version
|
247
293
|
version: '0'
|
248
294
|
requirements: []
|
249
295
|
rubyforge_project:
|
250
|
-
rubygems_version: 2.
|
296
|
+
rubygems_version: 2.2.1
|
251
297
|
signing_key:
|
252
298
|
specification_version: 4
|
253
299
|
summary: Puppet Library is a private Puppet module server that's compatible with librarian-puppet.
|
254
300
|
test_files:
|
255
|
-
- spec/
|
301
|
+
- spec/forge/abstract_spec.rb
|
302
|
+
- spec/forge/directory_spec.rb
|
303
|
+
- spec/forge/multi_spec.rb
|
304
|
+
- spec/forge/proxy_spec.rb
|
256
305
|
- spec/http/cache/in_memory_spec.rb
|
257
306
|
- spec/http/cache/noop_spec.rb
|
258
307
|
- spec/http/http_client_spec.rb
|
259
308
|
- spec/http/url_spec.rb
|
260
|
-
- spec/module_repo/directory_spec.rb
|
261
|
-
- spec/module_repo/multi_spec.rb
|
262
|
-
- spec/module_repo/proxy_spec.rb
|
263
309
|
- spec/module_spec_helper.rb
|
264
310
|
- spec/puppet_library_spec.rb
|
265
311
|
- spec/server_spec.rb
|
@@ -1,72 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
# Puppet Library
|
3
|
-
# Copyright (C) 2014 drrb
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU General Public License
|
16
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
|
18
|
-
module PuppetLibrary
|
19
|
-
class ModuleMetadata
|
20
|
-
def initialize(metadata)
|
21
|
-
@metadata = metadata
|
22
|
-
end
|
23
|
-
|
24
|
-
def author
|
25
|
-
@metadata["name"][/^[^-]+/]
|
26
|
-
end
|
27
|
-
|
28
|
-
def name
|
29
|
-
@metadata["name"].sub(/^[^-]+-/, "")
|
30
|
-
end
|
31
|
-
|
32
|
-
def full_name
|
33
|
-
@metadata["name"].sub("-", "/")
|
34
|
-
end
|
35
|
-
|
36
|
-
def version
|
37
|
-
@metadata["version"]
|
38
|
-
end
|
39
|
-
|
40
|
-
def dependencies
|
41
|
-
@metadata["dependencies"]
|
42
|
-
end
|
43
|
-
|
44
|
-
def description
|
45
|
-
@metadata["description"]
|
46
|
-
end
|
47
|
-
|
48
|
-
def dependency_names
|
49
|
-
dependencies.map {|d| d["name"]}
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_info
|
53
|
-
{
|
54
|
-
"author" => author,
|
55
|
-
"full_name" => full_name,
|
56
|
-
"name" => name,
|
57
|
-
"desc" => description,
|
58
|
-
"releases" => [ { "version" => version } ]
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
|
-
def to_version
|
63
|
-
{
|
64
|
-
"file" => "/modules/#{author}-#{name}-#{version}.tar.gz",
|
65
|
-
"version" => version,
|
66
|
-
"dependencies" => dependencies.map do |dependency|
|
67
|
-
[ dependency["name"], dependency["version_requirement"] ]
|
68
|
-
end
|
69
|
-
}
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
# Puppet Library
|
3
|
-
# Copyright (C) 2014 drrb
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU General Public License
|
16
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
|
18
|
-
require 'spec_helper'
|
19
|
-
|
20
|
-
module PuppetLibrary::ModuleRepo
|
21
|
-
describe Multi do
|
22
|
-
let(:subrepo_one) { double('subrepo_one').as_null_object }
|
23
|
-
let(:subrepo_two) { double('subrepo_two').as_null_object }
|
24
|
-
let(:multi_repo) do
|
25
|
-
repo = Multi.new
|
26
|
-
repo.add_repo(subrepo_one)
|
27
|
-
repo.add_repo(subrepo_two)
|
28
|
-
return repo
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#get_module" do
|
32
|
-
before do
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when the module is found in a subrepository" do
|
36
|
-
it "returns the module from the first subrepo it's found in" do
|
37
|
-
expect(subrepo_one).to receive(:get_module).with("puppetlabs", "apache", "1.0.0").and_return("puppetlabs/apache module: 1.0.0")
|
38
|
-
expect(subrepo_two).not_to receive(:get_module)
|
39
|
-
|
40
|
-
mod = multi_repo.get_module("puppetlabs", "apache", "1.0.0")
|
41
|
-
|
42
|
-
expect(mod).to eq "puppetlabs/apache module: 1.0.0"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when the module is not found in any subrepository" do
|
47
|
-
it "returns nil" do
|
48
|
-
expect(subrepo_one).to receive(:get_module).with("puppetlabs", "nonexistant", "1.0.0").and_return(nil)
|
49
|
-
expect(subrepo_two).to receive(:get_module).with("puppetlabs", "nonexistant", "1.0.0").and_return(nil)
|
50
|
-
|
51
|
-
mod = multi_repo.get_module("puppetlabs", "nonexistant", "1.0.0")
|
52
|
-
|
53
|
-
expect(mod).to be_nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#get_metadata" do
|
59
|
-
context "when versions of the module are found in subrepositories" do
|
60
|
-
it "returns the metadata in an array" do
|
61
|
-
apache_module_metadata_one = { "name" => "apache", "version" => "1.0.0" }
|
62
|
-
apache_module_metadata_two = { "name" => "apache", "version" => "2.0.0" }
|
63
|
-
expect(subrepo_one).to receive(:get_metadata).with("puppetlabs", "apache").and_return([apache_module_metadata_one])
|
64
|
-
expect(subrepo_two).to receive(:get_metadata).with("puppetlabs", "apache").and_return([apache_module_metadata_two])
|
65
|
-
|
66
|
-
metadata_list = multi_repo.get_metadata("puppetlabs", "apache")
|
67
|
-
|
68
|
-
expect(metadata_list).to eq [ apache_module_metadata_one, apache_module_metadata_two ]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when no versions of the module are found in any subrepository" do
|
73
|
-
it "returns an empty array" do
|
74
|
-
expect(subrepo_one).to receive(:get_metadata).with("puppetlabs", "apache").and_return([])
|
75
|
-
expect(subrepo_two).to receive(:get_metadata).with("puppetlabs", "apache").and_return([])
|
76
|
-
|
77
|
-
metadata_list = multi_repo.get_metadata("puppetlabs", "apache")
|
78
|
-
|
79
|
-
expect(metadata_list).to be_empty
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "when the same version of a module is found in multiple repositories" do
|
84
|
-
it "returns the one from the first repository it appears in" do
|
85
|
-
apache_module_metadata_one = { "name" => "apache", "version" => "1.0.0", "repo" => "one" }
|
86
|
-
apache_module_metadata_two = { "name" => "apache", "version" => "1.0.0", "repo" => "two" }
|
87
|
-
expect(subrepo_one).to receive(:get_metadata).with("puppetlabs", "apache").and_return([apache_module_metadata_one])
|
88
|
-
expect(subrepo_two).to receive(:get_metadata).with("puppetlabs", "apache").and_return([apache_module_metadata_two])
|
89
|
-
|
90
|
-
metadata_list = multi_repo.get_metadata("puppetlabs", "apache")
|
91
|
-
|
92
|
-
expect(metadata_list).to eq [ apache_module_metadata_one ]
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
# Puppet Library
|
3
|
-
# Copyright (C) 2014 drrb
|
4
|
-
#
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
8
|
-
# (at your option) any later version.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU General Public License for more details.
|
14
|
-
#
|
15
|
-
# You should have received a copy of the GNU General Public License
|
16
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
|
18
|
-
require 'spec_helper'
|
19
|
-
|
20
|
-
module PuppetLibrary::ModuleRepo
|
21
|
-
describe Proxy do
|
22
|
-
let(:http_client) { double('http_client') }
|
23
|
-
let(:query_cache) { PuppetLibrary::Http::Cache::InMemory.new }
|
24
|
-
let(:download_cache) { PuppetLibrary::Http::Cache::InMemory.new }
|
25
|
-
let(:repo) { Proxy.new("http://puppetforge.example.com", query_cache, download_cache, http_client) }
|
26
|
-
|
27
|
-
describe "url" do
|
28
|
-
it "defaults to HTTP, when protocol not specified" do
|
29
|
-
repo = Proxy.new("forge.puppetlabs.com", query_cache, download_cache, http_client)
|
30
|
-
|
31
|
-
expect(http_client).to receive(:get).with(/http:\/\/forge.puppetlabs.com/).and_return('{"puppetlabs/apache":[]}')
|
32
|
-
|
33
|
-
repo.get_metadata("puppetlabs", "apache")
|
34
|
-
end
|
35
|
-
|
36
|
-
it "copes with a trailing slash" do
|
37
|
-
repo = Proxy.new("forge.puppetlabs.com/", query_cache, download_cache, http_client)
|
38
|
-
|
39
|
-
expect(http_client).to receive(:get).with(/http:\/\/forge.puppetlabs.com\/api/).and_return('{"puppetlabs/apache":[]}')
|
40
|
-
|
41
|
-
repo.get_metadata("puppetlabs", "apache")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#get_module" do
|
46
|
-
context "when the module exists" do
|
47
|
-
it "downloads the module" do
|
48
|
-
expect(http_client).to receive(:get).
|
49
|
-
with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
50
|
-
and_return('{"puppetlabs/apache":[{"file":"/system/releases/p/puppetlabs/puppetlabs-apache-1.2.3.tar.gz","version":"1.2.3","dependencies":[]}]}')
|
51
|
-
expect(http_client).to receive(:download).
|
52
|
-
with("http://puppetforge.example.com/system/releases/p/puppetlabs/puppetlabs-apache-1.2.3.tar.gz").
|
53
|
-
and_return("module buffer")
|
54
|
-
|
55
|
-
module_buffer = repo.get_module("puppetlabs", "apache", "1.2.3")
|
56
|
-
expect(module_buffer).to eq "module buffer"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "caches the download" do
|
60
|
-
expect(http_client).to receive(:get).at_least(1).times.and_return('{"puppetlabs/apache":[{"version": "1", "file":"/module.tar.gz"}]}')
|
61
|
-
expect(http_client).to receive(:download).once
|
62
|
-
|
63
|
-
repo.get_module("puppetlabs", "apache", "1")
|
64
|
-
repo.get_module("puppetlabs", "apache", "1")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when the module doesn't exist" do
|
69
|
-
it "returns nil" do
|
70
|
-
expect(http_client).to receive(:get).
|
71
|
-
with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
72
|
-
and_return('{"puppetlabs/apache":[{"file":"/system/releases/p/puppetlabs/puppetlabs-apache-1.2.3.tar.gz","version":"1.2.3","dependencies":[]}]}')
|
73
|
-
|
74
|
-
module_buffer = repo.get_module("puppetlabs", "apache", "9.9.9")
|
75
|
-
expect(module_buffer).to be_nil
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "#get_metadata" do
|
81
|
-
context "when the module doesn't exist" do
|
82
|
-
it "returns an empty array" do
|
83
|
-
expect(http_client).to receive(:get).
|
84
|
-
with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
85
|
-
and_raise(OpenURI::HTTPError.new("404 Not Found", "Module not found"))
|
86
|
-
|
87
|
-
metadata = repo.get_metadata("puppetlabs", "apache")
|
88
|
-
expect(metadata).to be_empty
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "when versions of the module exist" do
|
93
|
-
it "returns an array of the versions" do
|
94
|
-
expect(http_client).to receive(:get).
|
95
|
-
with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
96
|
-
and_return('{"puppetlabs/apache":[{"version":"1.0.0","dependencies":[["puppetlabs/concat",">= 1.0.0"],["puppetlabs/stdlib","~> 2.0.0"]]},{"version":"2.0.0","dependencies":[]}]}')
|
97
|
-
|
98
|
-
metadata = repo.get_metadata("puppetlabs", "apache")
|
99
|
-
expect(metadata.size).to eq 2
|
100
|
-
expect(metadata.first).to eq({ "name" => "puppetlabs-apache", "author" => "puppetlabs", "version" => "1.0.0", "dependencies" => [{ "name" => "puppetlabs/concat", "version_requirement" => ">= 1.0.0" }, { "name" => "puppetlabs/stdlib", "version_requirement" => "~> 2.0.0" }] })
|
101
|
-
expect(metadata.last).to eq({ "name" => "puppetlabs-apache", "author" => "puppetlabs", "version" => "2.0.0", "dependencies" => [] })
|
102
|
-
end
|
103
|
-
|
104
|
-
it "caches requests" do
|
105
|
-
expect(http_client).to receive(:get).
|
106
|
-
once.with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
107
|
-
and_return('{"puppetlabs/apache":[{"version":"1.0.0","dependencies":[["puppetlabs/concat",">= 1.0.0"],["puppetlabs/stdlib","~> 2.0.0"]]},{"version":"2.0.0","dependencies":[]}]}')
|
108
|
-
|
109
|
-
repo.get_metadata("puppetlabs", "apache")
|
110
|
-
repo.get_metadata("puppetlabs", "apache")
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|