puppet-library 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd852d5afc9f767f3adbd20e96a3d6ba37fec092
4
- data.tar.gz: 9030ad628af928e81289963f28e9df751a4240b6
3
+ metadata.gz: 6c1ea499735a82bacf4051bd1b4ea24f2003d613
4
+ data.tar.gz: ad4e79023760adaf7bc96becfa61d9403f2c60be
5
5
  SHA512:
6
- metadata.gz: a168548b6050b5d34d121b1191f74dfe5a84e11024714f07d753828ef72894ef3b039ffbbd8c3c7a125179b29c4862ea8d4de17f2c45a3e0cf60527d48ae723a
7
- data.tar.gz: 1c130b6732c99488fffc95442bca7b3604b0ae38213aba4415b185dd79514b705ee76cdc8710f1b53054f5428c54143b54ae80ec987c7a243888f51752602c5f
6
+ metadata.gz: ebe0288bdc97d3df601dc7f1d523d49d3884662af2b756aac2a7634219175a7b7f6035b3a3ffd0bafcfd87f0c9c3c5eb847ff12409a9aca7daf4de24da4b1141
7
+ data.tar.gz: 81466a2f9550252a75f7f6d98d941df618eb0b611a52a2d7df0fb30e85b825dcdd0399ed3876889189417e07e14b650cb219f31d0cdb2e33b8d22cf597ce32e5
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  # Puppet Library
2
- # Copyright (C) 2013 drrb
2
+ # Copyright (C) 2014 drrb
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -19,6 +19,10 @@ before_install:
19
19
  - gem update --system 2.1.11
20
20
  - gem --version
21
21
  rvm:
22
- - "1.8.7"
23
- - "1.9.3"
24
- - "2.0.0"
22
+ - 1.8.7
23
+ - 1.9.3
24
+ - 2.0.0
25
+ - 2.1.0
26
+ matrix:
27
+ allow_failures:
28
+ - rvm: 2.1.0
data/CHANGELOG.yml ADDED
@@ -0,0 +1,31 @@
1
+ # Puppet Library
2
+ # Copyright (C) 2014 drrb
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ - tag: v0.0.1
18
+ changes:
19
+ - Support for serving modules from a directory on disk
20
+ - tag: v0.0.2
21
+ changes:
22
+ - Support for serving multiple module sources
23
+ - Bug fixes for Ruby 1.8.7
24
+ - tag: v0.1.0
25
+ changes:
26
+ - Support for proxying a remote forge
27
+ - tag: v0.2.0
28
+ changes:
29
+ - Support more specific module version queries using 'version' parameter
30
+ - Fixed bug on older versions of RubyGems
31
+
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Puppet Library
3
- # Copyright (C) 2013 drrb
3
+ # Copyright (C) 2014 drrb
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 drrb
1
+ Copyright (c) 2014 drrb
2
2
 
3
3
  GNU GENERAL PUBLIC LICENSE
4
4
  Version 3, 29 June 2007
data/bin/puppet-library CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Puppet Library
3
- # Copyright (C) 2013 drrb
3
+ # Copyright (C) 2014 drrb
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -19,10 +19,11 @@ require 'puppet_library/version'
19
19
 
20
20
  require 'puppet_library/puppet_library'
21
21
  require 'puppet_library/server'
22
- require 'puppet_library/http/cache'
22
+ require 'puppet_library/module_metadata'
23
23
  require 'puppet_library/http/http_client'
24
24
  require 'puppet_library/http/url'
25
- require 'puppet_library/module_metadata'
25
+ require 'puppet_library/http/cache/in_memory'
26
+ require 'puppet_library/http/cache/noop'
26
27
  require 'puppet_library/module_repo/directory'
27
28
  require 'puppet_library/module_repo/multi'
28
29
  require 'puppet_library/module_repo/proxy'
@@ -69,12 +69,24 @@ module PuppetLibrary
69
69
  module_infos.deep_merge
70
70
  end
71
71
 
72
- def get_module_metadata_with_dependencies(author, name)
72
+ def get_module_metadata_with_dependencies(author, name, version)
73
+ raise ModuleNotFound if get_metadata(author, name).empty?
74
+
73
75
  full_name = "#{author}/#{name}"
76
+ versions = collect_dependencies_versions(full_name)
77
+ return versions if version.nil?
74
78
 
75
- collect_dependencies_versions(full_name).tap do |versions|
76
- raise ModuleNotFound if versions[full_name].empty?
79
+ versions[full_name] = versions[full_name].select do |v|
80
+ v["version"].start_with?(version)
77
81
  end
82
+
83
+ dependencies = versions[full_name].map do |v|
84
+ v["dependencies"].map {|(name, spec)| name}
85
+ end.flatten
86
+ versions = Hash[versions.select do |name, info|
87
+ name == full_name || dependencies.include?(name)
88
+ end]
89
+ return versions
78
90
  end
79
91
 
80
92
  def collect_dependencies_versions(module_full_name, metadata = {})
@@ -15,25 +15,37 @@
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
- module PuppetLibrary::Http
19
- class Cache
18
+ module PuppetLibrary::Http::Cache
19
+ class InMemory
20
20
  ARBITRARY_CACHE_TTL_MILLIS = 10 * 1000
21
21
  def initialize(millis_to_live = ARBITRARY_CACHE_TTL_MILLIS)
22
22
  @reaper = Reaper.new(millis_to_live)
23
- @cache = {}
24
23
  end
25
24
 
26
25
  def get(key)
27
- entry = @cache[key]
26
+ entry = retrieve(key)
28
27
  if entry
29
28
  return entry.value unless @reaper.wants_to_kill? entry
30
29
  end
31
30
 
32
31
  value = yield
33
- @cache[key] = Entry.new(value)
32
+ save(key, Entry.new(value))
34
33
  return value
35
34
  end
36
35
 
36
+ def retrieve(key)
37
+ cache[key]
38
+ end
39
+
40
+ def save(key, entry)
41
+ cache[key] = entry
42
+ end
43
+
44
+ private
45
+ def cache
46
+ @cache ||= {}
47
+ end
48
+
37
49
  class Entry
38
50
  attr_accessor :value
39
51
 
@@ -0,0 +1,28 @@
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 'puppet_library/http/cache/in_memory'
19
+
20
+ module PuppetLibrary::Http::Cache
21
+ class NoOp < PuppetLibrary::Http::Cache::InMemory
22
+ def save(key, entry)
23
+ end
24
+
25
+ def retrieve(key)
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # Puppet Library
2
- # Copyright (C) 2013 drrb
2
+ # Copyright (C) 2014 drrb
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Puppet Library
3
- # Copyright (C) 2013 drrb
3
+ # Copyright (C) 2014 drrb
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -16,15 +16,21 @@
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  require 'puppet_library/http/http_client'
19
- require 'puppet_library/http/cache'
19
+ require 'puppet_library/http/cache/in_memory'
20
+ require 'puppet_library/http/cache/noop'
20
21
  require 'puppet_library/http/url'
21
22
 
22
23
  module PuppetLibrary::ModuleRepo
24
+ #include PuppetLibrary::Http
23
25
  class Proxy
24
- def initialize(url, http_client = PuppetLibrary::Http::HttpClient.new, query_cache = PuppetLibrary::Http::Cache.new)
26
+ def initialize(url,
27
+ query_cache = PuppetLibrary::Http::Cache::InMemory.new,
28
+ download_cache = PuppetLibrary::Http::Cache::NoOp.new,
29
+ http_client = PuppetLibrary::Http::HttpClient.new)
25
30
  @url = PuppetLibrary::Http::Url.normalize(url)
26
31
  @http_client = http_client
27
32
  @query_cache = query_cache
33
+ @download_cache = download_cache
28
34
  end
29
35
 
30
36
  def get_module(author, name, version)
@@ -71,7 +77,9 @@ module PuppetLibrary::ModuleRepo
71
77
  end
72
78
 
73
79
  def download_file(file)
74
- @http_client.download(url(file))
80
+ @download_cache.get(file) do
81
+ @http_client.download(url(file))
82
+ end
75
83
  end
76
84
 
77
85
  def get(relative_url)
@@ -50,8 +50,9 @@ module PuppetLibrary
50
50
 
51
51
  get "/api/v1/releases.json" do
52
52
  author, module_name = params[:module].split "/"
53
+ version = params[:version]
53
54
  begin
54
- @forge.get_module_metadata_with_dependencies(author, module_name).to_json
55
+ @forge.get_module_metadata_with_dependencies(author, module_name, version).to_json
55
56
  rescue ModuleNotFound
56
57
  status 410
57
58
  {"error" => "Module #{author}/#{module_name} not found"}.to_json
@@ -15,6 +15,8 @@
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 'rubygems/package'
19
+
18
20
  class Array
19
21
  # Like 'uniq' with a block, but also works on Ruby < 1.9
20
22
  def unique_by
@@ -29,3 +31,14 @@ class Array
29
31
  end
30
32
  end
31
33
  end
34
+
35
+ class Gem::Package::TarReader
36
+ # Old versions of RubyGems don't include Enumerable in here
37
+ def find
38
+ each do |entry|
39
+ if yield(entry)
40
+ return entry
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Puppet Library
3
- # Copyright (C) 2013 drrb
3
+ # Copyright (C) 2014 drrb
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -16,5 +16,5 @@
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  module PuppetLibrary
19
- VERSION = "0.1.0"
19
+ VERSION = "0.2.0"
20
20
  end
data/spec/forge_spec.rb CHANGED
@@ -90,56 +90,129 @@ module PuppetLibrary
90
90
  expect(module_repo).to receive(:get_metadata).with("nonexistant", "nonexistant").and_return([])
91
91
 
92
92
  expect {
93
- forge.get_module_metadata_with_dependencies("nonexistant", "nonexistant")
93
+ forge.get_module_metadata_with_dependencies("nonexistant", "nonexistant", "1.0.0")
94
94
  }.to raise_error ModuleNotFound
95
95
  end
96
96
  end
97
97
 
98
- context "when module versions found" do
99
- it "returns metadata for module and dependencies" do
100
- apache_metadata = [ {
98
+ context "when only different module versions found" do
99
+ it "returns an empty array" do
100
+ metadata = [ {
101
101
  "author" => "puppetlabs",
102
102
  "name" => "puppetlabs-apache",
103
103
  "description" => "Apache module",
104
104
  "version" => "1.0.0",
105
- "dependencies" => [
106
- { "name" => "puppetlabs/stdlib", "version_requirement" => ">= 2.4.0" },
107
- { "name" => "puppetlabs/concat", "version_requirement" => ">= 1.0.0" }
108
- ]
109
- }, {
110
- "author" => "puppetlabs",
111
- "name" => "puppetlabs-apache",
112
- "description" => "Apache module",
113
- "version" => "1.1.0",
114
- "dependencies" => [
115
- { "name" => "puppetlabs/stdlib", "version_requirement" => ">= 2.4.0" },
116
- { "name" => "puppetlabs/concat", "version_requirement" => ">= 1.0.0" }
117
- ]
118
- } ]
119
- stdlib_metadata = [ {
120
- "author" => "puppetlabs",
121
- "name" => "puppetlabs-stdlib",
122
- "description" => "Stdlib module",
123
- "version" => "2.0.0",
124
- "dependencies" => [ ]
105
+ "dependencies" => []
125
106
  } ]
126
- concat_metadata = [ {
127
- "author" => "puppetlabs",
128
- "name" => "puppetlabs-concat",
129
- "description" => "Concat module",
130
- "version" => "1.0.0",
131
- "dependencies" => [ ]
132
- } ]
133
- expect(module_repo).to receive(:get_metadata).with("puppetlabs", "apache").and_return(apache_metadata)
134
- expect(module_repo).to receive(:get_metadata).with("puppetlabs", "stdlib").and_return(stdlib_metadata)
135
- expect(module_repo).to receive(:get_metadata).with("puppetlabs", "concat").and_return(concat_metadata)
136
-
137
- result = forge.get_module_metadata_with_dependencies("puppetlabs", "apache")
138
- expect(result.keys.sort).to eq(["puppetlabs/apache", "puppetlabs/concat", "puppetlabs/stdlib"])
139
- expect(result["puppetlabs/apache"].size).to eq(2)
140
- expect(result["puppetlabs/apache"][0]["file"]).to eq("/modules/puppetlabs-apache-1.0.0.tar.gz")
141
- expect(result["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
142
- expect(result["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
107
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "apache").at_least(:once).and_return(metadata)
108
+
109
+ result = forge.get_module_metadata_with_dependencies("puppetlabs", "apache", "2.0.0")
110
+ expect(result).to eq({"puppetlabs/apache" => []})
111
+ end
112
+ end
113
+
114
+ context "when module versions found" do
115
+ context "when a version specified" do
116
+ it "returns metadata for that module version and its dependencies" do
117
+ apache_metadata = [ {
118
+ "author" => "puppetlabs",
119
+ "name" => "puppetlabs-apache",
120
+ "description" => "Apache module",
121
+ "version" => "1.0.0",
122
+ "dependencies" => [
123
+ { "name" => "puppetlabs/stdlib", "version_requirement" => ">= 2.4.0" },
124
+ { "name" => "puppetlabs/concat", "version_requirement" => ">= 1.0.0" }
125
+ ]
126
+ }, {
127
+ "author" => "puppetlabs",
128
+ "name" => "puppetlabs-apache",
129
+ "description" => "Apache module",
130
+ "version" => "1.1.0",
131
+ "dependencies" => [
132
+ { "name" => "puppetlabs/stdlib", "version_requirement" => ">= 2.4.0" },
133
+ { "name" => "puppetlabs/newthing", "version_requirement" => ">= 1.0.0" }
134
+ ]
135
+ } ]
136
+ stdlib_metadata = [ {
137
+ "author" => "puppetlabs",
138
+ "name" => "puppetlabs-stdlib",
139
+ "description" => "Stdlib module",
140
+ "version" => "2.4.0",
141
+ "dependencies" => [ ]
142
+ } ]
143
+ concat_metadata = [ {
144
+ "author" => "puppetlabs",
145
+ "name" => "puppetlabs-concat",
146
+ "description" => "Concat module",
147
+ "version" => "1.0.0",
148
+ "dependencies" => [ ]
149
+ } ]
150
+ newthing_metadata = [ {
151
+ "author" => "puppetlabs",
152
+ "name" => "puppetlabs-newthing",
153
+ "description" => "New module",
154
+ "version" => "1.0.0",
155
+ "dependencies" => [ ]
156
+ } ]
157
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "apache").at_least(:once).and_return(apache_metadata)
158
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "stdlib").and_return(stdlib_metadata)
159
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "concat").and_return(concat_metadata)
160
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "newthing").and_return(newthing_metadata)
161
+
162
+ result = forge.get_module_metadata_with_dependencies("puppetlabs", "apache", "1.0.0")
163
+ expect(result.keys.sort).to eq(["puppetlabs/apache", "puppetlabs/concat", "puppetlabs/stdlib"])
164
+ expect(result["puppetlabs/apache"].size).to eq(1)
165
+ expect(result["puppetlabs/apache"][0]["file"]).to eq("/modules/puppetlabs-apache-1.0.0.tar.gz")
166
+ expect(result["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
167
+ expect(result["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
168
+ end
169
+ end
170
+ context "when no version specified" do
171
+ it "returns metadata for all module versions and their dependencies" do
172
+ apache_metadata = [ {
173
+ "author" => "puppetlabs",
174
+ "name" => "puppetlabs-apache",
175
+ "description" => "Apache module",
176
+ "version" => "1.0.0",
177
+ "dependencies" => [
178
+ { "name" => "puppetlabs/stdlib", "version_requirement" => ">= 2.4.0" },
179
+ { "name" => "puppetlabs/concat", "version_requirement" => ">= 1.0.0" }
180
+ ]
181
+ }, {
182
+ "author" => "puppetlabs",
183
+ "name" => "puppetlabs-apache",
184
+ "description" => "Apache module",
185
+ "version" => "1.1.0",
186
+ "dependencies" => [
187
+ { "name" => "puppetlabs/stdlib", "version_requirement" => ">= 2.4.0" },
188
+ { "name" => "puppetlabs/concat", "version_requirement" => ">= 1.0.0" }
189
+ ]
190
+ } ]
191
+ stdlib_metadata = [ {
192
+ "author" => "puppetlabs",
193
+ "name" => "puppetlabs-stdlib",
194
+ "description" => "Stdlib module",
195
+ "version" => "2.0.0",
196
+ "dependencies" => [ ]
197
+ } ]
198
+ concat_metadata = [ {
199
+ "author" => "puppetlabs",
200
+ "name" => "puppetlabs-concat",
201
+ "description" => "Concat module",
202
+ "version" => "1.0.0",
203
+ "dependencies" => [ ]
204
+ } ]
205
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "apache").at_least(:once).and_return(apache_metadata)
206
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "stdlib").and_return(stdlib_metadata)
207
+ expect(module_repo).to receive(:get_metadata).with("puppetlabs", "concat").and_return(concat_metadata)
208
+
209
+ result = forge.get_module_metadata_with_dependencies("puppetlabs", "apache", nil)
210
+ expect(result.keys.sort).to eq(["puppetlabs/apache", "puppetlabs/concat", "puppetlabs/stdlib"])
211
+ expect(result["puppetlabs/apache"].size).to eq(2)
212
+ expect(result["puppetlabs/apache"][0]["file"]).to eq("/modules/puppetlabs-apache-1.0.0.tar.gz")
213
+ expect(result["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
214
+ expect(result["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
215
+ end
143
216
  end
144
217
  end
145
218
  end
@@ -17,10 +17,10 @@
17
17
 
18
18
  require 'spec_helper'
19
19
 
20
- module PuppetLibrary::Http
21
- describe Cache do
20
+ module PuppetLibrary::Http::Cache
21
+ describe InMemory do
22
22
 
23
- let(:cache) { Cache.new }
23
+ let(:cache) { InMemory.new }
24
24
 
25
25
  describe "#get" do
26
26
  context "the first time it's called" do
@@ -51,7 +51,7 @@ module PuppetLibrary::Http
51
51
 
52
52
  context "when the time limit has expired" do
53
53
  it "looks up the value again" do
54
- cache = Cache.new(0)
54
+ cache = InMemory.new(0)
55
55
 
56
56
  greeting = cache.get("greeting") { "hi" }
57
57
  greeting = cache.get("greeting") { "bye" }
@@ -0,0 +1,32 @@
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::Http::Cache
21
+ describe NoOp do
22
+ let(:cache) { NoOp.new }
23
+
24
+ describe "#get" do
25
+ it "never caches the content" do
26
+ name = cache.get("name") { "joe" }
27
+ name = cache.get("name") { "james" }
28
+ expect(name).to eq "james"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  # Puppet Library
2
- # Copyright (C) 2013 drrb
2
+ # Copyright (C) 2014 drrb
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
5
5
  # it under the terms of the GNU General Public License as published by
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Puppet Library
3
- # Copyright (C) 2013 drrb
3
+ # Copyright (C) 2014 drrb
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -20,11 +20,13 @@ require 'spec_helper'
20
20
  module PuppetLibrary::ModuleRepo
21
21
  describe Proxy do
22
22
  let(:http_client) { double('http_client') }
23
- let(:repo) { Proxy.new("http://puppetforge.example.com", 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) }
24
26
 
25
27
  describe "url" do
26
28
  it "defaults to HTTP, when protocol not specified" do
27
- repo = Proxy.new("forge.puppetlabs.com", http_client)
29
+ repo = Proxy.new("forge.puppetlabs.com", query_cache, download_cache, http_client)
28
30
 
29
31
  expect(http_client).to receive(:get).with(/http:\/\/forge.puppetlabs.com/).and_return('{"puppetlabs/apache":[]}')
30
32
 
@@ -32,7 +34,7 @@ module PuppetLibrary::ModuleRepo
32
34
  end
33
35
 
34
36
  it "copes with a trailing slash" do
35
- repo = Proxy.new("forge.puppetlabs.com/", http_client)
37
+ repo = Proxy.new("forge.puppetlabs.com/", query_cache, download_cache, http_client)
36
38
 
37
39
  expect(http_client).to receive(:get).with(/http:\/\/forge.puppetlabs.com\/api/).and_return('{"puppetlabs/apache":[]}')
38
40
 
@@ -53,6 +55,14 @@ module PuppetLibrary::ModuleRepo
53
55
  module_buffer = repo.get_module("puppetlabs", "apache", "1.2.3")
54
56
  expect(module_buffer).to eq "module buffer"
55
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
56
66
  end
57
67
 
58
68
  context "when the module doesn't exist" do
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Puppet Library
3
- # Copyright (C) 2013 drrb
3
+ # Copyright (C) 2014 drrb
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
data/spec/server_spec.rb CHANGED
@@ -115,7 +115,7 @@ module PuppetLibrary
115
115
  }
116
116
  ]
117
117
  }
118
- expect(forge).to receive(:get_module_metadata_with_dependencies).with("puppetlabs", "apache").and_return(metadata)
118
+ expect(forge).to receive(:get_module_metadata_with_dependencies).with("puppetlabs", "apache", nil).and_return(metadata)
119
119
 
120
120
  get "/api/v1/releases.json?module=puppetlabs/apache"
121
121
 
@@ -125,7 +125,7 @@ module PuppetLibrary
125
125
 
126
126
  context "when the module can't be found" do
127
127
  it "returns an error" do
128
- expect(forge).to receive(:get_module_metadata_with_dependencies).with("nonexistant", "nonexistant").and_raise(ModuleNotFound)
128
+ expect(forge).to receive(:get_module_metadata_with_dependencies).with("nonexistant", "nonexistant", nil).and_raise(ModuleNotFound)
129
129
 
130
130
  get "/api/v1/releases.json?module=nonexistant/nonexistant"
131
131
 
@@ -133,6 +133,14 @@ module PuppetLibrary
133
133
  expect(last_response.status).to eq(410)
134
134
  end
135
135
  end
136
+
137
+ context "when a version is specified" do
138
+ it "looks up the specified version" do
139
+ expect(forge).to receive(:get_module_metadata_with_dependencies).with("puppetlabs", "apache", "1.0.0")
140
+
141
+ get "/api/v1/releases.json?module=puppetlabs/apache&version=1.0.0"
142
+ end
143
+ end
136
144
  end
137
145
  end
138
146
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Puppet Library
3
- # Copyright (C) 2013 drrb
3
+ # Copyright (C) 2014 drrb
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
data/spec/util_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Puppet Library
3
- # Copyright (C) 2013 drrb
3
+ # Copyright (C) 2014 drrb
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-library
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-16 00:00:00.000000000 Z
11
+ date: 2014-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -190,6 +190,7 @@ files:
190
190
  - .licenseignore
191
191
  - .simplecov
192
192
  - .travis.yml
193
+ - CHANGELOG.yml
193
194
  - Gemfile
194
195
  - LICENSE.txt
195
196
  - README.md
@@ -199,7 +200,8 @@ files:
199
200
  - config.ru
200
201
  - lib/puppet_library.rb
201
202
  - lib/puppet_library/forge.rb
202
- - lib/puppet_library/http/cache.rb
203
+ - lib/puppet_library/http/cache/in_memory.rb
204
+ - lib/puppet_library/http/cache/noop.rb
203
205
  - lib/puppet_library/http/http_client.rb
204
206
  - lib/puppet_library/http/url.rb
205
207
  - lib/puppet_library/module_metadata.rb
@@ -212,7 +214,8 @@ files:
212
214
  - lib/puppet_library/version.rb
213
215
  - puppet-library.gemspec
214
216
  - spec/forge_spec.rb
215
- - spec/http/cache_spec.rb
217
+ - spec/http/cache/in_memory_spec.rb
218
+ - spec/http/cache/noop_spec.rb
216
219
  - spec/http/http_client_spec.rb
217
220
  - spec/http/url_spec.rb
218
221
  - spec/module_repo/directory_spec.rb
@@ -250,7 +253,8 @@ specification_version: 4
250
253
  summary: Puppet Library is a private Puppet module server that's compatible with librarian-puppet.
251
254
  test_files:
252
255
  - spec/forge_spec.rb
253
- - spec/http/cache_spec.rb
256
+ - spec/http/cache/in_memory_spec.rb
257
+ - spec/http/cache/noop_spec.rb
254
258
  - spec/http/http_client_spec.rb
255
259
  - spec/http/url_spec.rb
256
260
  - spec/module_repo/directory_spec.rb