puppet-library 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +23 -5
- data/Rakefile +18 -4
- data/TODO.yml +14 -3
- data/config.ru +7 -3
- data/lib/puppet_library.rb +5 -1
- data/lib/puppet_library/forge.rb +100 -0
- data/lib/puppet_library/http/cache.rb +61 -0
- data/lib/puppet_library/http/http_client.rb +35 -0
- data/lib/puppet_library/http/url.rb +27 -0
- data/lib/puppet_library/module_metadata.rb +9 -4
- data/lib/puppet_library/module_repo/proxy.rb +87 -0
- data/lib/puppet_library/puppet_library.rb +30 -20
- data/lib/puppet_library/server.rb +10 -67
- data/lib/puppet_library/util.rb +2 -2
- data/lib/puppet_library/version.rb +1 -1
- data/puppet-library.gemspec +3 -1
- data/spec/forge_spec.rb +147 -0
- data/spec/http/cache_spec.rb +63 -0
- data/spec/http/http_client_spec.rb +44 -0
- data/spec/http/url_spec.rb +39 -0
- data/spec/module_repo/directory_spec.rb +9 -5
- data/spec/module_repo/proxy_spec.rb +105 -0
- data/spec/module_spec_helper.rb +3 -1
- data/spec/puppet_library_spec.rb +64 -15
- data/spec/server_spec.rb +45 -77
- data/spec/spec_helper.rb +2 -0
- data/test/librarian_puppet_integration_test.rb +111 -0
- metadata +47 -2
@@ -0,0 +1,63 @@
|
|
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
|
21
|
+
describe Cache do
|
22
|
+
|
23
|
+
let(:cache) { Cache.new }
|
24
|
+
|
25
|
+
describe "#get" do
|
26
|
+
context "the first time it's called" do
|
27
|
+
it "returns the value from the provided block" do
|
28
|
+
greeting = cache.get("greeting") { "hello" }
|
29
|
+
|
30
|
+
expect(greeting).to eq "hello"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "the second time it's called" do
|
35
|
+
it "returns the cached value" do
|
36
|
+
cache.get("greeting") { "hello" }
|
37
|
+
greeting = cache.get("greeting") { "hi" }
|
38
|
+
|
39
|
+
expect(greeting).to eq "hello"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the cached value is falsey" do
|
44
|
+
it "returns the cached value" do
|
45
|
+
cache.get("greeting") { false }
|
46
|
+
greeting = cache.get("greeting") { true }
|
47
|
+
|
48
|
+
expect(greeting).to be false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the time limit has expired" do
|
53
|
+
it "looks up the value again" do
|
54
|
+
cache = Cache.new(0)
|
55
|
+
|
56
|
+
greeting = cache.get("greeting") { "hi" }
|
57
|
+
greeting = cache.get("greeting") { "bye" }
|
58
|
+
expect(greeting).to eq "bye"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
21
|
+
describe HttpClient do
|
22
|
+
let(:client) { HttpClient.new }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(client).to receive(:open_uri).with("http:://example.com").and_return(StringIO.new("Content"))
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#get" do
|
29
|
+
it "calls open() on the provided URL and reads the result" do
|
30
|
+
content = client.get("http:://example.com")
|
31
|
+
|
32
|
+
expect(content).to eq "Content"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#download" do
|
37
|
+
it "calls open() on the provided URL" do
|
38
|
+
content = client.download("http:://example.com")
|
39
|
+
|
40
|
+
expect(content.read).to eq "Content"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
21
|
+
describe Url do
|
22
|
+
describe "#normalize" do
|
23
|
+
it "leaves normal URLs alone" do
|
24
|
+
result = Url.normalize "http://localhost"
|
25
|
+
expect(result).to eq "http://localhost"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "adds http:// to URI with no scheme" do
|
29
|
+
result = Url.normalize "localhost"
|
30
|
+
expect(result).to eq "http://localhost"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "removes a trailing slash" do
|
34
|
+
result = Url.normalize "http://localhost/"
|
35
|
+
expect(result).to eq "http://localhost"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -19,16 +19,18 @@ require 'spec_helper'
|
|
19
19
|
module PuppetLibrary::ModuleRepo
|
20
20
|
describe Directory do
|
21
21
|
include ModuleSpecHelper
|
22
|
+
include FileUtils
|
22
23
|
|
23
|
-
let(:module_dir) { "
|
24
|
+
let(:module_dir) { Tempfile.new("module_dir").path }
|
24
25
|
let(:module_repo) { Directory.new(module_dir) }
|
25
26
|
|
26
27
|
before do
|
27
|
-
|
28
|
+
rm_rf module_dir
|
29
|
+
mkdir_p module_dir
|
28
30
|
end
|
29
31
|
|
30
32
|
after do
|
31
|
-
|
33
|
+
rm_rf module_dir
|
32
34
|
end
|
33
35
|
|
34
36
|
describe "#get_module" do
|
@@ -71,8 +73,10 @@ module PuppetLibrary::ModuleRepo
|
|
71
73
|
metadata_list = module_repo.get_metadata("puppetlabs", "apache")
|
72
74
|
expect(metadata_list.size).to eq 2
|
73
75
|
metadata_list = metadata_list.sort_by {|m| m["version"] }
|
74
|
-
expect(metadata_list[0]).to eq
|
75
|
-
expect(metadata_list[
|
76
|
+
expect(metadata_list[0]["name"]).to eq "puppetlabs-apache"
|
77
|
+
expect(metadata_list[0]["version"]).to eq "1.0.0"
|
78
|
+
expect(metadata_list[1]["name"]).to eq "puppetlabs-apache"
|
79
|
+
expect(metadata_list[1]["version"]).to eq "1.1.0"
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
@@ -0,0 +1,105 @@
|
|
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(:repo) { Proxy.new("http://puppetforge.example.com", http_client) }
|
24
|
+
|
25
|
+
describe "url" do
|
26
|
+
it "defaults to HTTP, when protocol not specified" do
|
27
|
+
repo = Proxy.new("forge.puppetlabs.com", http_client)
|
28
|
+
|
29
|
+
expect(http_client).to receive(:get).with(/http:\/\/forge.puppetlabs.com/).and_return('{"puppetlabs/apache":[]}')
|
30
|
+
|
31
|
+
repo.get_metadata("puppetlabs", "apache")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "copes with a trailing slash" do
|
35
|
+
repo = Proxy.new("forge.puppetlabs.com/", http_client)
|
36
|
+
|
37
|
+
expect(http_client).to receive(:get).with(/http:\/\/forge.puppetlabs.com\/api/).and_return('{"puppetlabs/apache":[]}')
|
38
|
+
|
39
|
+
repo.get_metadata("puppetlabs", "apache")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#get_module" do
|
44
|
+
context "when the module exists" do
|
45
|
+
it "downloads the module" do
|
46
|
+
expect(http_client).to receive(:get).
|
47
|
+
with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
48
|
+
and_return('{"puppetlabs/apache":[{"file":"/system/releases/p/puppetlabs/puppetlabs-apache-1.2.3.tar.gz","version":"1.2.3","dependencies":[]}]}')
|
49
|
+
expect(http_client).to receive(:download).
|
50
|
+
with("http://puppetforge.example.com/system/releases/p/puppetlabs/puppetlabs-apache-1.2.3.tar.gz").
|
51
|
+
and_return("module buffer")
|
52
|
+
|
53
|
+
module_buffer = repo.get_module("puppetlabs", "apache", "1.2.3")
|
54
|
+
expect(module_buffer).to eq "module buffer"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the module doesn't exist" do
|
59
|
+
it "returns nil" do
|
60
|
+
expect(http_client).to receive(:get).
|
61
|
+
with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
62
|
+
and_return('{"puppetlabs/apache":[{"file":"/system/releases/p/puppetlabs/puppetlabs-apache-1.2.3.tar.gz","version":"1.2.3","dependencies":[]}]}')
|
63
|
+
|
64
|
+
module_buffer = repo.get_module("puppetlabs", "apache", "9.9.9")
|
65
|
+
expect(module_buffer).to be_nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#get_metadata" do
|
71
|
+
context "when the module doesn't exist" do
|
72
|
+
it "returns an empty array" do
|
73
|
+
expect(http_client).to receive(:get).
|
74
|
+
with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
75
|
+
and_raise(OpenURI::HTTPError.new("404 Not Found", "Module not found"))
|
76
|
+
|
77
|
+
metadata = repo.get_metadata("puppetlabs", "apache")
|
78
|
+
expect(metadata).to be_empty
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when versions of the module exist" do
|
83
|
+
it "returns an array of the versions" do
|
84
|
+
expect(http_client).to receive(:get).
|
85
|
+
with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
86
|
+
and_return('{"puppetlabs/apache":[{"version":"1.0.0","dependencies":[["puppetlabs/concat",">= 1.0.0"],["puppetlabs/stdlib","~> 2.0.0"]]},{"version":"2.0.0","dependencies":[]}]}')
|
87
|
+
|
88
|
+
metadata = repo.get_metadata("puppetlabs", "apache")
|
89
|
+
expect(metadata.size).to eq 2
|
90
|
+
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" }] })
|
91
|
+
expect(metadata.last).to eq({ "name" => "puppetlabs-apache", "author" => "puppetlabs", "version" => "2.0.0", "dependencies" => [] })
|
92
|
+
end
|
93
|
+
|
94
|
+
it "caches requests" do
|
95
|
+
expect(http_client).to receive(:get).
|
96
|
+
once.with("http://puppetforge.example.com/api/v1/releases.json?module=puppetlabs/apache").
|
97
|
+
and_return('{"puppetlabs/apache":[{"version":"1.0.0","dependencies":[["puppetlabs/concat",">= 1.0.0"],["puppetlabs/stdlib","~> 2.0.0"]]},{"version":"2.0.0","dependencies":[]}]}')
|
98
|
+
|
99
|
+
repo.get_metadata("puppetlabs", "apache")
|
100
|
+
repo.get_metadata("puppetlabs", "apache")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/spec/module_spec_helper.rb
CHANGED
@@ -42,8 +42,10 @@ module ModuleSpecHelper
|
|
42
42
|
archive.add_file("#{fqn}/metadata.json", 0644) do |file|
|
43
43
|
content = {
|
44
44
|
"name" => full_name,
|
45
|
-
"version" => version
|
45
|
+
"version" => version,
|
46
|
+
"dependencies" => []
|
46
47
|
}
|
48
|
+
yield(content) if block_given?
|
47
49
|
file.write content.to_json
|
48
50
|
end
|
49
51
|
end
|
data/spec/puppet_library_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
# Puppet Library
|
3
|
-
# Copyright (C)
|
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
|
@@ -24,14 +24,19 @@ module PuppetLibrary
|
|
24
24
|
allow(ModuleRepo::Multi).to receive(:new).and_return(module_repo)
|
25
25
|
return module_repo
|
26
26
|
end
|
27
|
+
let(:forge) do
|
28
|
+
forge = double(Forge)
|
29
|
+
allow(Forge).to receive(:new).and_return(forge)
|
30
|
+
return forge
|
31
|
+
end
|
27
32
|
let(:server) do
|
28
33
|
server = double(Server)
|
29
|
-
allow(Server).to receive(:new).and_return(server)
|
34
|
+
allow(Server).to receive(:new).with(forge).and_return(server)
|
30
35
|
return server
|
31
36
|
end
|
32
37
|
let(:log) { double('log').as_null_object }
|
33
38
|
let(:library) { PuppetLibrary.new(log) }
|
34
|
-
let(:default_options) {{ :app => server, :Host =>
|
39
|
+
let(:default_options) {{ :app => server, :Host => nil, :Port => nil, :server => nil }}
|
35
40
|
before do
|
36
41
|
allow(Rack::Server).to receive(:start)
|
37
42
|
end
|
@@ -45,7 +50,7 @@ module PuppetLibrary
|
|
45
50
|
end
|
46
51
|
|
47
52
|
describe "#go" do
|
48
|
-
context "when
|
53
|
+
context "when using a bad option" do
|
49
54
|
it "prints the usage" do
|
50
55
|
expect(log).to receive(:puts).with(/invalid option: --die\nUsage:/)
|
51
56
|
|
@@ -53,7 +58,7 @@ module PuppetLibrary
|
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
56
|
-
context "when
|
61
|
+
context "when using no options" do
|
57
62
|
it "runs the server with the default options" do
|
58
63
|
expect(Rack::Server).to receive(:start).with(default_options)
|
59
64
|
|
@@ -61,7 +66,7 @@ module PuppetLibrary
|
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
|
-
context "when
|
69
|
+
context "when using --port option" do
|
65
70
|
it "runs the server with the specified port" do
|
66
71
|
expect(Rack::Server).to receive(:start).with(default_options_with(:Port => "8080"))
|
67
72
|
|
@@ -69,7 +74,15 @@ module PuppetLibrary
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
72
|
-
context "when
|
77
|
+
context "when using --server option" do
|
78
|
+
it "runs the app on the specified server" do
|
79
|
+
expect(Rack::Server).to receive(:start).with(default_options_with(:server => "thin"))
|
80
|
+
|
81
|
+
library.go(["--server", "thin"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when using --bind-host option" do
|
73
86
|
it "runs the server with the specified bind host" do
|
74
87
|
expect(Rack::Server).to receive(:start).with(default_options_with(:Host => "localhost"))
|
75
88
|
|
@@ -77,18 +90,54 @@ module PuppetLibrary
|
|
77
90
|
end
|
78
91
|
end
|
79
92
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
93
|
+
context "when using --proxy option" do
|
94
|
+
it "adds a proxy module repository for each option specified" do
|
95
|
+
proxy1 = double('proxy1')
|
96
|
+
proxy2 = double('proxy2')
|
97
|
+
expect(ModuleRepo::Proxy).to receive(:new).with("http://forge1.example.com").and_return(proxy1)
|
98
|
+
expect(ModuleRepo::Proxy).to receive(:new).with("http://forge2.example.com").and_return(proxy2)
|
99
|
+
expect(Forge).to receive(:new).with(module_repo).and_return(forge)
|
100
|
+
expect(module_repo).to receive(:add_repo).twice
|
101
|
+
expect(Rack::Server).to receive(:start).with(default_options)
|
102
|
+
|
103
|
+
library.go(["--proxy", "http://forge1.example.com", "--proxy", "http://forge2.example.com"])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when using --module-dir option" do
|
108
|
+
it "adds a module repository to the server for each module directory" do
|
109
|
+
directory_repo_1 = double("directory_repo_1")
|
110
|
+
directory_repo_2 = double("directory_repo_2")
|
111
|
+
expect(ModuleRepo::Directory).to receive(:new).with("dir1").and_return(directory_repo_1)
|
112
|
+
expect(ModuleRepo::Directory).to receive(:new).with("dir2").and_return(directory_repo_2)
|
113
|
+
expect(Forge).to receive(:new).with(module_repo).and_return(forge)
|
114
|
+
expect(module_repo).to receive(:add_repo).with(directory_repo_1)
|
115
|
+
expect(module_repo).to receive(:add_repo).with(directory_repo_2)
|
116
|
+
expect(Rack::Server).to receive(:start).with(default_options)
|
117
|
+
|
118
|
+
library.go(["--module-dir", "dir1", "--module-dir", "dir2"])
|
119
|
+
end
|
120
|
+
end
|
84
121
|
|
85
|
-
|
122
|
+
context "when no proxy URLs or module directories specified" do
|
123
|
+
it "proxies the Puppet Forge" do
|
124
|
+
proxy = double("proxy")
|
125
|
+
expect(ModuleRepo::Proxy).to receive(:new).with("http://forge.puppetlabs.com").and_return(proxy)
|
126
|
+
expect(Forge).to receive(:new).with(module_repo).and_return(forge)
|
127
|
+
expect(module_repo).to receive(:add_repo).with(proxy)
|
128
|
+
expect(Rack::Server).to receive(:start).with(default_options)
|
129
|
+
|
130
|
+
library.go([])
|
131
|
+
end
|
86
132
|
end
|
87
133
|
|
88
134
|
it "logs the server options" do
|
89
|
-
expect(log).to receive(:puts).with(/Port:
|
90
|
-
expect(log).to receive(:puts).with(/Host:
|
91
|
-
|
135
|
+
expect(log).to receive(:puts).with(/Port: default/)
|
136
|
+
expect(log).to receive(:puts).with(/Host: default/)
|
137
|
+
expect(log).to receive(:puts).with(/Server: default/)
|
138
|
+
expect(log).to receive(:puts).with(/Repositories:/)
|
139
|
+
expect(log).to receive(:puts).with(/- PuppetLibrary::ModuleRepo::Directory: \.\/modules/)
|
140
|
+
library.go(["--module-dir", "./modules"])
|
92
141
|
end
|
93
142
|
end
|
94
143
|
end
|
data/spec/server_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
# Puppet Library
|
3
|
-
# Copyright (C)
|
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
|
@@ -22,30 +22,17 @@ require 'rack/test'
|
|
22
22
|
module PuppetLibrary
|
23
23
|
describe Server do
|
24
24
|
include Rack::Test::Methods
|
25
|
-
include ModuleSpecHelper
|
26
25
|
|
27
|
-
let(:
|
28
|
-
let(:module_repo) { double(ModuleRepo) }
|
26
|
+
let(:forge) { double(Forge) }
|
29
27
|
let(:app) do
|
30
|
-
Server.new(
|
31
|
-
end
|
32
|
-
|
33
|
-
before do
|
34
|
-
FileUtils.mkdir_p module_dir
|
35
|
-
end
|
36
|
-
|
37
|
-
after do
|
38
|
-
FileUtils.rm_rf module_dir
|
28
|
+
Server.new(forge)
|
39
29
|
end
|
40
30
|
|
41
31
|
describe "GET /modules/<author>-<module>-<version>.tar.gz" do
|
42
32
|
context "when the module is on the server" do
|
43
|
-
before do
|
44
|
-
add_module("puppetlabs", "apache", "1.0.0")
|
45
|
-
end
|
46
33
|
it "serves the module" do
|
47
34
|
file_buffer = StringIO.new("module content")
|
48
|
-
expect(
|
35
|
+
expect(forge).to receive(:get_module_buffer).with("puppetlabs", "apache", "1.0.0").and_return(file_buffer)
|
49
36
|
|
50
37
|
get "/modules/puppetlabs-apache-1.0.0.tar.gz"
|
51
38
|
|
@@ -58,7 +45,7 @@ module PuppetLibrary
|
|
58
45
|
|
59
46
|
context "when the module is not on the server" do
|
60
47
|
it "returns an error" do
|
61
|
-
expect(
|
48
|
+
expect(forge).to receive(:get_module_buffer).with("puppetlabs", "apache", "1.0.0").and_raise(ModuleNotFound)
|
62
49
|
|
63
50
|
get "/modules/puppetlabs-apache-1.0.0.tar.gz"
|
64
51
|
|
@@ -70,32 +57,27 @@ module PuppetLibrary
|
|
70
57
|
|
71
58
|
describe "GET /<author>/<module>.json" do
|
72
59
|
it "gets module metadata for all versions" do
|
73
|
-
metadata =
|
74
|
-
"author" => "puppetlabs",
|
75
|
-
"name" => "puppetlabs-apache",
|
76
|
-
"description" => "Apache module",
|
77
|
-
"version" => "1.0.0"
|
78
|
-
}, {
|
60
|
+
metadata = {
|
79
61
|
"author" => "puppetlabs",
|
80
|
-
"
|
81
|
-
"
|
82
|
-
"
|
83
|
-
|
84
|
-
|
62
|
+
"full_name" => "puppetlabs/apache",
|
63
|
+
"name" => "apache",
|
64
|
+
"desc" => "Puppet module for Apache",
|
65
|
+
"releases" => [
|
66
|
+
{ "version" => "0.10.0" },
|
67
|
+
{ "version" => "0.9.0" },
|
68
|
+
]
|
69
|
+
}
|
70
|
+
expect(forge).to receive(:get_module_metadata).with("puppetlabs", "apache").and_return(metadata)
|
85
71
|
|
86
72
|
get "/puppetlabs/apache.json"
|
87
73
|
|
88
|
-
expect(last_response.body).to
|
89
|
-
expect(last_response.body).to include('"full_name":"puppetlabs/apache"')
|
90
|
-
expect(last_response.body).to include('"name":"apache"')
|
91
|
-
expect(last_response.body).to include('"desc":"Apache module"')
|
92
|
-
expect(last_response.body).to include('"releases":[{"version":"1.0.0"},{"version":"1.1.0"}]')
|
74
|
+
expect(last_response.body).to eq metadata.to_json
|
93
75
|
expect(last_response).to be_ok
|
94
76
|
end
|
95
77
|
|
96
78
|
context "when no modules found" do
|
97
79
|
it "returns an error" do
|
98
|
-
expect(
|
80
|
+
expect(forge).to receive(:get_module_metadata).with("nonexistant", "nonexistant").and_raise(ModuleNotFound)
|
99
81
|
|
100
82
|
get "/nonexistant/nonexistant.json"
|
101
83
|
|
@@ -107,57 +89,43 @@ module PuppetLibrary
|
|
107
89
|
|
108
90
|
describe "GET /api/v1/releases.json" do
|
109
91
|
it "gets metadata for module and dependencies" do
|
110
|
-
|
111
|
-
"
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
"
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
92
|
+
metadata = {
|
93
|
+
"puppetlabs/apache" => [
|
94
|
+
{
|
95
|
+
"file" => "/system/releases/p/puppetlabs/puppetlabs-apache-0.9.0.tar.gz",
|
96
|
+
"version" => "0.9.0",
|
97
|
+
"dependencies" => [
|
98
|
+
[ "puppetlabs/concat", ">= 1.0.0" ],
|
99
|
+
[ "puppetlabs/stdlib", ">= 2.4.0" ]
|
100
|
+
]
|
101
|
+
}
|
102
|
+
],
|
103
|
+
"puppetlabs/stdlib" => [
|
104
|
+
{
|
105
|
+
"file" => "/system/releases/p/puppetlabs/puppetlabs-stdlib-3.0.0.tar.gz",
|
106
|
+
"version" => "3.0.0",
|
107
|
+
"dependencies" => [ ]
|
108
|
+
}
|
109
|
+
],
|
110
|
+
"puppetlabs/concat" => [
|
111
|
+
{
|
112
|
+
"file" => "/system/releases/p/puppetlabs/puppetlabs-concat-1.0.0-rc1.tar.gz",
|
113
|
+
"version" => "1.0.0-rc1",
|
114
|
+
"dependencies" => [ ]
|
115
|
+
}
|
127
116
|
]
|
128
|
-
}
|
129
|
-
|
130
|
-
"author" => "puppetlabs",
|
131
|
-
"name" => "puppetlabs-stdlib",
|
132
|
-
"description" => "Stdlib module",
|
133
|
-
"version" => "2.0.0",
|
134
|
-
"dependencies" => [ ]
|
135
|
-
} ]
|
136
|
-
concat_metadata = [ {
|
137
|
-
"author" => "puppetlabs",
|
138
|
-
"name" => "puppetlabs-concat",
|
139
|
-
"description" => "Concat module",
|
140
|
-
"version" => "1.0.0",
|
141
|
-
"dependencies" => [ ]
|
142
|
-
} ]
|
143
|
-
expect(module_repo).to receive(:get_metadata).with("puppetlabs", "apache").and_return(apache_metadata)
|
144
|
-
expect(module_repo).to receive(:get_metadata).with("puppetlabs", "stdlib").and_return(stdlib_metadata)
|
145
|
-
expect(module_repo).to receive(:get_metadata).with("puppetlabs", "concat").and_return(concat_metadata)
|
117
|
+
}
|
118
|
+
expect(forge).to receive(:get_module_metadata_with_dependencies).with("puppetlabs", "apache").and_return(metadata)
|
146
119
|
|
147
120
|
get "/api/v1/releases.json?module=puppetlabs/apache"
|
148
121
|
|
149
|
-
|
150
|
-
expect(response.keys.sort).to eq(["puppetlabs/apache", "puppetlabs/concat", "puppetlabs/stdlib"])
|
151
|
-
expect(response["puppetlabs/apache"].size).to eq(2)
|
152
|
-
expect(response["puppetlabs/apache"][0]["file"]).to eq("/modules/puppetlabs-apache-1.0.0.tar.gz")
|
153
|
-
expect(response["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
|
154
|
-
expect(response["puppetlabs/apache"][0]["version"]).to eq("1.0.0")
|
122
|
+
expect(last_response.body).to eq metadata.to_json
|
155
123
|
expect(last_response).to be_ok
|
156
124
|
end
|
157
125
|
|
158
126
|
context "when the module can't be found" do
|
159
127
|
it "returns an error" do
|
160
|
-
expect(
|
128
|
+
expect(forge).to receive(:get_module_metadata_with_dependencies).with("nonexistant", "nonexistant").and_raise(ModuleNotFound)
|
161
129
|
|
162
130
|
get "/api/v1/releases.json?module=nonexistant/nonexistant"
|
163
131
|
|