puppet-library 0.10.0 → 0.11.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 +4 -4
- data/CHANGELOG.yml +11 -0
- data/README.md +16 -7
- data/Rakefile +21 -21
- data/TODO.yml +10 -6
- data/bin/puppet-library +0 -1
- data/config.ru +14 -16
- data/features/step_definitions/sinatra_steps.rb +3 -12
- data/lib/puppet_library/forge.rb +1 -0
- data/lib/puppet_library/forge/abstract.rb +2 -1
- data/lib/puppet_library/forge/cache.rb +11 -7
- data/lib/puppet_library/forge/directory.rb +15 -13
- data/lib/puppet_library/forge/forge.rb +25 -0
- data/lib/puppet_library/forge/git_repository.rb +42 -17
- data/lib/puppet_library/forge/multi.rb +11 -1
- data/lib/puppet_library/forge/proxy.rb +14 -9
- data/lib/puppet_library/forge/source.rb +12 -13
- data/lib/puppet_library/http/cache/disk.rb +26 -8
- data/lib/puppet_library/http/cache/in_memory.rb +13 -10
- data/lib/puppet_library/http/cache/noop.rb +4 -1
- data/lib/puppet_library/puppet_library.rb +10 -7
- data/lib/puppet_library/puppet_module/modulefile.rb +5 -1
- data/lib/puppet_library/server.rb +13 -9
- data/lib/puppet_library/util.rb +1 -0
- data/lib/puppet_library/util/config_api.rb +115 -0
- data/lib/puppet_library/util/git.rb +36 -8
- data/lib/puppet_library/util/logging.rb +49 -0
- data/lib/puppet_library/util/patches.rb +21 -0
- data/lib/puppet_library/util/temp_dir.rb +20 -5
- data/lib/puppet_library/version.rb +1 -1
- data/puppet-library.gemspec +2 -0
- data/spec/archive/archive_reader_spec.rb +2 -6
- data/spec/archive/archiver_spec.rb +5 -9
- data/spec/forge/cache_spec.rb +13 -7
- data/spec/forge/directory_spec.rb +31 -18
- data/spec/forge/git_repository_spec.rb +60 -13
- data/spec/forge/multi_spec.rb +16 -0
- data/spec/forge/proxy_spec.rb +18 -0
- data/spec/forge/source_spec.rb +14 -9
- data/spec/http/cache/disk_spec.rb +11 -6
- data/spec/http/cache/in_memory_spec.rb +12 -0
- data/spec/http/cache/noop_spec.rb +6 -0
- data/spec/integration_test_helper.rb +3 -3
- data/spec/module_spec_helper.rb +2 -2
- data/spec/puppet_library_spec.rb +34 -16
- data/spec/puppet_module/modulefile_spec.rb +48 -9
- data/spec/server_spec.rb +28 -1
- data/spec/spec_helper.rb +2 -14
- data/spec/util/config_api_spec.rb +77 -0
- data/spec/util/git_spec.rb +20 -20
- data/spec/util/patches_spec.rb +18 -0
- data/test/directory_forge_integration_test.rb +6 -8
- data/test/offline_git_repo_forge_integration_test.rb +9 -14
- data/test/offline_proxy_forge_integration_test.rb +11 -14
- data/test/online_git_repo_forge_integration_test.rb +7 -8
- data/test/online_proxy_forge_integration_test.rb +10 -13
- data/test/source_forge_integration_test.rb +7 -8
- metadata +35 -2
data/spec/server_spec.rb
CHANGED
@@ -24,10 +24,29 @@ module PuppetLibrary
|
|
24
24
|
include Rack::Test::Methods
|
25
25
|
|
26
26
|
let(:forge) { double(Forge) }
|
27
|
-
let
|
27
|
+
let :app do
|
28
|
+
allow(forge).to receive(:prime)
|
28
29
|
Server.new(forge)
|
29
30
|
end
|
30
31
|
|
32
|
+
describe "#new" do
|
33
|
+
it "primes the repositories" do
|
34
|
+
expect(forge).to receive(:prime)
|
35
|
+
app
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#configure" do
|
40
|
+
it "exposes a configuration API" do
|
41
|
+
repo_path = "."
|
42
|
+
Server.configure do
|
43
|
+
forge :directory do
|
44
|
+
path repo_path # make sure our API keeps the block's scope
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
31
50
|
describe "GET /" do
|
32
51
|
it "lists all the modules" do
|
33
52
|
modules = [
|
@@ -78,6 +97,14 @@ module PuppetLibrary
|
|
78
97
|
end
|
79
98
|
end
|
80
99
|
|
100
|
+
describe "POST /api/forge/clear-cache" do
|
101
|
+
it "clears the forges' caches" do
|
102
|
+
expect(forge).to receive(:clear_cache)
|
103
|
+
|
104
|
+
post "/api/forge/clear-cache"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
81
108
|
describe "GET /modules.json" do
|
82
109
|
it "renders the search result as JSON" do
|
83
110
|
search_results = [
|
data/spec/spec_helper.rb
CHANGED
@@ -24,21 +24,9 @@ require 'tempfile'
|
|
24
24
|
require 'fileutils'
|
25
25
|
|
26
26
|
include FileUtils
|
27
|
+
Tempdir = PuppetLibrary::Util::TempDir
|
27
28
|
|
28
|
-
|
29
|
-
attr_reader :path
|
30
|
-
|
31
|
-
def self.create(name)
|
32
|
-
Tempdir.new(name).path
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize(name)
|
36
|
-
file = Tempfile.new(name)
|
37
|
-
@path = file.path
|
38
|
-
file.unlink
|
39
|
-
FileUtils.mkdir @path
|
40
|
-
end
|
41
|
-
end
|
29
|
+
ENV["TESTING"] = "true"
|
42
30
|
|
43
31
|
class Tgz
|
44
32
|
def initialize(buffer)
|
@@ -0,0 +1,77 @@
|
|
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
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
module PuppetLibrary::Util
|
20
|
+
describe ConfigApi do
|
21
|
+
describe "#for" do
|
22
|
+
it "creates a config API" do
|
23
|
+
api = ConfigApi.for(self.class) do
|
24
|
+
required :name, "String"
|
25
|
+
end
|
26
|
+
|
27
|
+
config = api.configure do
|
28
|
+
name "Dave"
|
29
|
+
end
|
30
|
+
|
31
|
+
expect(config.get_name).to eq "Dave"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "sees the block's scope" do
|
35
|
+
api = ConfigApi.for(self.class) do
|
36
|
+
required :name, "String"
|
37
|
+
end
|
38
|
+
|
39
|
+
daves_name = "Dave"
|
40
|
+
config = api.configure do
|
41
|
+
name daves_name
|
42
|
+
end
|
43
|
+
|
44
|
+
expect(config.get_name).to eq "Dave"
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when a required parameter is missing" do
|
48
|
+
it "throws an exception" do
|
49
|
+
api = ConfigApi.for(self.class) do
|
50
|
+
required :name, "String"
|
51
|
+
end
|
52
|
+
|
53
|
+
expect {
|
54
|
+
api.configure do
|
55
|
+
end
|
56
|
+
}.to raise_error /name/
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when a parameter isn't valid, according to its validator" do
|
61
|
+
it "throws an exception" do
|
62
|
+
api = ConfigApi.for(self.class) do
|
63
|
+
required :name, "String" do |value|
|
64
|
+
raise "Invalid!"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
expect {
|
69
|
+
api.configure do
|
70
|
+
name "Dave"
|
71
|
+
end
|
72
|
+
}.to raise_error /Invalid!/
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/util/git_spec.rb
CHANGED
@@ -18,12 +18,12 @@ require 'spec_helper'
|
|
18
18
|
|
19
19
|
module PuppetLibrary::Util
|
20
20
|
describe Git do
|
21
|
-
@@
|
21
|
+
@@repo_dir = Tempdir.new("git-repo")
|
22
22
|
@@tags = [ "0.9.0", "1.0.0-rc1", "1.0.0", "xxx" ]
|
23
23
|
|
24
24
|
before :all do
|
25
25
|
def git(command)
|
26
|
-
git_command = "git --git-dir=#{@@
|
26
|
+
git_command = "git --git-dir=#{@@repo_dir.path}/.git --work-tree=#{@@repo_dir.path} #{command}"
|
27
27
|
`#{git_command}`
|
28
28
|
unless $?.success?
|
29
29
|
raise "Failed to run command: \"#{git_command}\""
|
@@ -34,7 +34,7 @@ module PuppetLibrary::Util
|
|
34
34
|
git "config user.name tester"
|
35
35
|
git "config user.email tester@example.com"
|
36
36
|
@@tags.each do |tag|
|
37
|
-
File.open(File.join(@@
|
37
|
+
File.open(File.join(@@repo_dir.path, "Modulefile"), "w") do |modulefile|
|
38
38
|
modulefile.write <<-MODULEFILE
|
39
39
|
name 'puppetlabs-apache'
|
40
40
|
version '#{tag}'
|
@@ -47,15 +47,15 @@ module PuppetLibrary::Util
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
let(:git) { Git.new(@@repo_path, cache_path) }
|
55
|
-
let(:cache_path) { Tempdir.create("git-cache") }
|
50
|
+
let(:git) { Git.new(@@repo_dir.path, cache_dir) }
|
51
|
+
let(:cache_dir) { Tempdir.new("git-cache") }
|
56
52
|
|
57
|
-
|
58
|
-
|
53
|
+
context "when a git command returns nonzero" do
|
54
|
+
it "raises an error" do
|
55
|
+
expect {
|
56
|
+
git.read_file("nonexistant.file", "0.9.0")
|
57
|
+
}.to raise_error /Error running Git command/
|
58
|
+
end
|
59
59
|
end
|
60
60
|
|
61
61
|
describe "#tags" do
|
@@ -82,17 +82,17 @@ module PuppetLibrary::Util
|
|
82
82
|
it "clones the git repository to the cache directory" do
|
83
83
|
git.update_cache!
|
84
84
|
|
85
|
-
expect(`git --git-dir #{
|
85
|
+
expect(`git --git-dir #{cache_dir.path}/.git remote -v`).to include @@repo_dir.path
|
86
86
|
end
|
87
87
|
|
88
88
|
it "creates Git's .git/FETCH_HEAD file so that we know that the cache was recently created" do
|
89
89
|
git.update_cache!
|
90
90
|
|
91
|
-
expect(File.exist?(File.join(
|
91
|
+
expect(File.exist?(File.join(cache_dir.path, ".git", "FETCH_HEAD"))).to be_true
|
92
92
|
end
|
93
93
|
|
94
94
|
it "copes with a missing .git/FETCH_HEAD file" do
|
95
|
-
fetch_file = File.join(
|
95
|
+
fetch_file = File.join(cache_dir.path, ".git", "FETCH_HEAD")
|
96
96
|
git.update_cache!
|
97
97
|
rm fetch_file
|
98
98
|
|
@@ -103,7 +103,7 @@ module PuppetLibrary::Util
|
|
103
103
|
|
104
104
|
it "doesn't update the cache if it was recently updated" do
|
105
105
|
git.update_cache!
|
106
|
-
new_head = Dir.chdir(@@
|
106
|
+
new_head = Dir.chdir(@@repo_dir.path) do
|
107
107
|
touch "xxx"
|
108
108
|
`git add xxx`
|
109
109
|
`git commit --message='Added file'`
|
@@ -112,13 +112,13 @@ module PuppetLibrary::Util
|
|
112
112
|
|
113
113
|
git.update_cache!
|
114
114
|
|
115
|
-
expect(`git --git-dir #{
|
115
|
+
expect(`git --git-dir #{cache_dir.path}/.git rev-parse HEAD`).not_to eq new_head
|
116
116
|
end
|
117
117
|
|
118
118
|
it "updates the cache if it's been long enough" do
|
119
119
|
git.update_cache!
|
120
|
-
git = Git.new(@@
|
121
|
-
new_head = Dir.chdir(@@
|
120
|
+
git = Git.new(@@repo_dir.path, cache_dir, 0) # zero second cache TTL
|
121
|
+
new_head = Dir.chdir(@@repo_dir.path) do
|
122
122
|
touch "xxx"
|
123
123
|
`git add xxx`
|
124
124
|
`git commit --message='Added file'`
|
@@ -127,7 +127,7 @@ module PuppetLibrary::Util
|
|
127
127
|
|
128
128
|
git.update_cache!
|
129
129
|
|
130
|
-
expect(`git --git-dir #{
|
130
|
+
expect(`git --git-dir #{cache_dir.path}/.git rev-parse HEAD`).to eq new_head
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -136,7 +136,7 @@ module PuppetLibrary::Util
|
|
136
136
|
git.update_cache!
|
137
137
|
git.clear_cache!
|
138
138
|
|
139
|
-
expect(File.exist?
|
139
|
+
expect(File.exist? cache_dir.path).to be_false
|
140
140
|
end
|
141
141
|
end
|
142
142
|
end
|
data/spec/util/patches_spec.rb
CHANGED
@@ -82,5 +82,23 @@ describe 'patches' do
|
|
82
82
|
expect(["1.10.0-badprerelease", "1.3", "1.10.0", "xxx", "1.10.0.rc1", "1.2.0"].version_sort).to eq ["xxx", "1.2.0", "1.3", "1.10.0-badprerelease", "1.10.0.rc1", "1.10.0"]
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
describe "#each_in_parallel" do
|
87
|
+
it "does something to each in parallel" do
|
88
|
+
array = [ "a", "b", "c" ]
|
89
|
+
array.each_in_parallel &:upcase!
|
90
|
+
|
91
|
+
expect(array).to eq [ "A", "B", "C" ]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe String do
|
97
|
+
describe "#snake_case_to_camel_case" do
|
98
|
+
it "converts snake case to camel case" do
|
99
|
+
camelized = "my_variable_name".snake_case_to_camel_case
|
100
|
+
expect(camelized).to eq "MyVariableName"
|
101
|
+
end
|
102
|
+
end
|
85
103
|
end
|
86
104
|
end
|
@@ -24,13 +24,13 @@ module PuppetLibrary
|
|
24
24
|
include ModuleSpecHelper
|
25
25
|
|
26
26
|
let(:port) { Ports.next! }
|
27
|
-
let(:module_dir) { Tempdir.
|
28
|
-
let(:project_dir) { Tempdir.
|
27
|
+
let(:module_dir) { Tempdir.new("module_dir") }
|
28
|
+
let(:project_dir) { Tempdir.new("project_dir") }
|
29
29
|
let(:start_dir) { pwd }
|
30
30
|
let(:disk_server) do
|
31
|
-
Server.configure do
|
32
|
-
|
33
|
-
|
31
|
+
Server.configure do
|
32
|
+
forge :directory do
|
33
|
+
path module_dir.path
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -55,12 +55,10 @@ module PuppetLibrary
|
|
55
55
|
# Start the servers
|
56
56
|
disk_server_runner
|
57
57
|
start_dir
|
58
|
-
cd project_dir
|
58
|
+
cd project_dir.path
|
59
59
|
end
|
60
60
|
|
61
61
|
after do
|
62
|
-
rm_rf module_dir
|
63
|
-
rm_rf project_dir
|
64
62
|
cd start_dir
|
65
63
|
end
|
66
64
|
|
@@ -21,13 +21,13 @@ require 'open-uri'
|
|
21
21
|
|
22
22
|
module PuppetLibrary
|
23
23
|
describe "offline git repo forge" do
|
24
|
-
@@
|
24
|
+
@@repo_dir = Tempdir.new("git-repo")
|
25
25
|
@@versions = [ "0.9.0", "1.0.0-rc1", "1.0.0" ]
|
26
26
|
@@tags = @@versions + [ "xxx" ]
|
27
27
|
|
28
28
|
before :all do
|
29
29
|
def git(command)
|
30
|
-
git_command = "git --git-dir=#{@@
|
30
|
+
git_command = "git --git-dir=#{@@repo_dir.path}/.git --work-tree=#{@@repo_dir.path} #{command}"
|
31
31
|
`#{git_command}`
|
32
32
|
unless $?.success?
|
33
33
|
raise "Failed to run command: \"#{git_command}\""
|
@@ -38,7 +38,7 @@ module PuppetLibrary
|
|
38
38
|
git "config user.name tester"
|
39
39
|
git "config user.email tester@example.com"
|
40
40
|
@@versions.zip(@@tags).each do |(version, tag)|
|
41
|
-
File.open(File.join(@@
|
41
|
+
File.open(File.join(@@repo_dir.path, "Modulefile"), "w") do |modulefile|
|
42
42
|
modulefile.write <<-MODULEFILE
|
43
43
|
name 'puppetlabs-apache'
|
44
44
|
version '#{version}'
|
@@ -51,20 +51,16 @@ module PuppetLibrary
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
after :all do
|
55
|
-
rm_rf @@repo_path
|
56
|
-
end
|
57
|
-
|
58
54
|
include ModuleSpecHelper
|
59
55
|
|
60
56
|
let(:port) { Ports.next! }
|
61
|
-
let(:project_dir) { Tempdir.
|
57
|
+
let(:project_dir) { Tempdir.new("project_dir") }
|
62
58
|
let(:start_dir) { pwd }
|
63
59
|
let(:git_server) do
|
64
|
-
Server.configure do
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
Server.configure do
|
61
|
+
forge :git_repository do
|
62
|
+
source @@repo_dir.path
|
63
|
+
include_tags /^[0-9.]+/
|
68
64
|
end
|
69
65
|
end
|
70
66
|
end
|
@@ -89,11 +85,10 @@ module PuppetLibrary
|
|
89
85
|
# Start the servers
|
90
86
|
git_server_runner
|
91
87
|
start_dir
|
92
|
-
cd project_dir
|
88
|
+
cd project_dir.path
|
93
89
|
end
|
94
90
|
|
95
91
|
after do
|
96
|
-
rm_rf project_dir
|
97
92
|
cd start_dir
|
98
93
|
end
|
99
94
|
|
@@ -25,14 +25,14 @@ module PuppetLibrary
|
|
25
25
|
|
26
26
|
let(:proxy_port) { Ports.next! }
|
27
27
|
let(:disk_port) { Ports.next! }
|
28
|
-
let(:module_dir) { Tempdir.
|
29
|
-
let(:project_dir) { Tempdir.
|
30
|
-
let(:cache_dir) { Tempdir.
|
28
|
+
let(:module_dir) { Tempdir.new("module_dir") }
|
29
|
+
let(:project_dir) { Tempdir.new("project_dir") }
|
30
|
+
let(:cache_dir) { Tempdir.new("cache_dir") }
|
31
31
|
let(:start_dir) { pwd }
|
32
32
|
let(:disk_server) do
|
33
|
-
Server.configure do
|
34
|
-
|
35
|
-
|
33
|
+
Server.configure do
|
34
|
+
forge :directory do
|
35
|
+
path module_dir.path
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -50,10 +50,10 @@ module PuppetLibrary
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
let(:proxy_server) do
|
53
|
-
Server.configure do
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
Server.configure do
|
54
|
+
forge :cache do
|
55
|
+
url "http://localhost:#{disk_port}"
|
56
|
+
path cache_dir.path
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -80,13 +80,10 @@ module PuppetLibrary
|
|
80
80
|
disk_server_runner
|
81
81
|
proxy_server_runner
|
82
82
|
start_dir
|
83
|
-
cd project_dir
|
83
|
+
cd project_dir.path
|
84
84
|
end
|
85
85
|
|
86
86
|
after do
|
87
|
-
rm_rf module_dir
|
88
|
-
rm_rf project_dir
|
89
|
-
rm_rf cache_dir
|
90
87
|
cd start_dir
|
91
88
|
end
|
92
89
|
|
@@ -25,13 +25,13 @@ module PuppetLibrary
|
|
25
25
|
include ModuleSpecHelper
|
26
26
|
|
27
27
|
let(:port) { Ports.next! }
|
28
|
-
let(:project_dir) { Tempdir.
|
28
|
+
let(:project_dir) { Tempdir.new("project_dir") }
|
29
29
|
let(:start_dir) { pwd }
|
30
30
|
let(:git_server) do
|
31
|
-
Server.configure do
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
Server.configure do
|
32
|
+
forge :git_repository do
|
33
|
+
source "https://github.com/puppetlabs/puppetlabs-stdlib.git"
|
34
|
+
include_tags /^[0-9.]+/
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -56,11 +56,10 @@ module PuppetLibrary
|
|
56
56
|
# Start the servers
|
57
57
|
git_server_runner
|
58
58
|
start_dir
|
59
|
-
cd project_dir
|
59
|
+
cd project_dir.path
|
60
60
|
end
|
61
61
|
|
62
62
|
after do
|
63
|
-
rm_rf project_dir
|
64
63
|
cd start_dir
|
65
64
|
end
|
66
65
|
|
@@ -71,7 +70,7 @@ module PuppetLibrary
|
|
71
70
|
EOF
|
72
71
|
|
73
72
|
# Install modules
|
74
|
-
system "librarian-puppet install" or fail "call to puppet-library failed"
|
73
|
+
system "librarian-puppet install --verbose" or fail "call to puppet-library failed"
|
75
74
|
expect("stdlib").to be_installed
|
76
75
|
|
77
76
|
# Search
|