puppet-library 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -18,16 +18,17 @@ require 'spec_helper'
|
|
18
18
|
|
19
19
|
module PuppetLibrary::Forge
|
20
20
|
describe GitRepository do
|
21
|
-
@@
|
22
|
-
@@versions = [ "0.9.0", "1.0.0-rc1", "1.0.0" ]
|
23
|
-
@@tags = @@versions + [ "xxx" ]
|
21
|
+
@@repo_dir = Tempdir.new("git-repo")
|
22
|
+
@@versions = [ "0.1.0", "0.9.0", "1.0.0-rc1", "1.0.0" ]
|
23
|
+
@@tags = @@versions.map {|version| "v#{version}"} + [ "xxx" ]
|
24
24
|
|
25
25
|
before :all do
|
26
26
|
def git(command)
|
27
|
-
git_command = "git --git-dir=#{@@
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
git_command = "git --git-dir=#{@@repo_dir.path}/.git --work-tree=#{@@repo_dir.path} #{command}"
|
28
|
+
pid, stdin, stdout, stderr = Open4.popen4(git_command)
|
29
|
+
ignored, status = Process::waitpid2 pid
|
30
|
+
unless status.success?
|
31
|
+
raise "Error running Git command: #{git_command}\n#{stdout.read}\n#{stderr.read}"
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
@@ -35,26 +36,66 @@ module PuppetLibrary::Forge
|
|
35
36
|
git "config user.name tester"
|
36
37
|
git "config user.email tester@example.com"
|
37
38
|
@@versions.zip(@@tags).each do |(version, tag)|
|
38
|
-
|
39
|
+
# Add some changes for the version
|
40
|
+
change_file_path = File.join(@@repo_dir.path, "changes.txt")
|
41
|
+
File.open(change_file_path, "a") do |change_file|
|
42
|
+
change_file.puts "Version #{version}"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Update the module file
|
46
|
+
modulefile_path = File.join(@@repo_dir.path, "Modulefile")
|
47
|
+
File.open(modulefile_path, "w") do |modulefile|
|
39
48
|
modulefile.write <<-MODULEFILE
|
40
49
|
name 'puppetlabs-apache'
|
41
50
|
version '#{version}'
|
42
51
|
author 'puppetlabs'
|
43
52
|
MODULEFILE
|
44
53
|
end
|
54
|
+
|
55
|
+
# A dodgy early version with no modulefile
|
56
|
+
File.delete modulefile_path if version == "0.1.0"
|
45
57
|
git "add ."
|
46
58
|
git "commit --message='Version #{version}'"
|
47
59
|
git "tag #{tag}"
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
51
|
-
|
52
|
-
|
63
|
+
let :forge do
|
64
|
+
cache_dir = Tempdir.new("git-repo-cache")
|
65
|
+
git = PuppetLibrary::Util::Git.new(@@repo_dir.path, cache_dir)
|
66
|
+
GitRepository.new(git, /[0-9.]+/)
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#configure" do
|
70
|
+
it "exposes a configuration API" do
|
71
|
+
forge = GitRepository.configure do
|
72
|
+
source @@repo_dir.path
|
73
|
+
include_tags /v123/
|
74
|
+
end
|
75
|
+
expect(forge.instance_eval "@version_tag_regex").to eq /v123/
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#prime" do
|
80
|
+
it "creates the repo cache" do
|
81
|
+
git = double('git')
|
82
|
+
forge = GitRepository.new(git, //)
|
83
|
+
|
84
|
+
expect(git).to receive(:update_cache!)
|
85
|
+
|
86
|
+
forge.prime
|
87
|
+
end
|
53
88
|
end
|
54
89
|
|
55
|
-
|
56
|
-
|
57
|
-
|
90
|
+
describe "#clear_cache" do
|
91
|
+
it "deletes the repo cache" do
|
92
|
+
git = double('git')
|
93
|
+
forge = GitRepository.new(git, //)
|
94
|
+
|
95
|
+
expect(git).to receive(:clear_cache!)
|
96
|
+
|
97
|
+
forge.clear_cache
|
98
|
+
end
|
58
99
|
end
|
59
100
|
|
60
101
|
describe "#get_module" do
|
@@ -123,6 +164,12 @@ module PuppetLibrary::Forge
|
|
123
164
|
expect(metadata.first["name"]).to eq "puppetlabs-apache"
|
124
165
|
expect(metadata.first["version"]).to eq "0.9.0"
|
125
166
|
end
|
167
|
+
|
168
|
+
it "doesn't include versions with no Modulefile" do
|
169
|
+
metadata = forge.get_all_metadata
|
170
|
+
dodgy_version = metadata.find {|m| m["version"] == "0.1.0" }
|
171
|
+
expect(dodgy_version).to be_nil
|
172
|
+
end
|
126
173
|
end
|
127
174
|
end
|
128
175
|
end
|
data/spec/forge/multi_spec.rb
CHANGED
@@ -38,6 +38,22 @@ module PuppetLibrary::Forge
|
|
38
38
|
return forge
|
39
39
|
end
|
40
40
|
|
41
|
+
describe "#prime" do
|
42
|
+
it "primes the subforges" do
|
43
|
+
expect(subforge_one).to receive(:prime)
|
44
|
+
expect(subforge_two).to receive(:prime)
|
45
|
+
multi_forge.prime
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#clear_cache" do
|
50
|
+
it "clears the subforges' caches" do
|
51
|
+
expect(subforge_one).to receive(:clear_cache)
|
52
|
+
expect(subforge_two).to receive(:clear_cache)
|
53
|
+
multi_forge.clear_cache
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
41
57
|
describe "#search_modules" do
|
42
58
|
context "when no modules match in any subforge" do
|
43
59
|
it "returns an empty array" do
|
data/spec/forge/proxy_spec.rb
CHANGED
@@ -24,6 +24,24 @@ module PuppetLibrary::Forge
|
|
24
24
|
let(:download_cache) { PuppetLibrary::Http::Cache::InMemory.new }
|
25
25
|
let(:forge) { Proxy.new("http://puppetforge.example.com", query_cache, download_cache, http_client) }
|
26
26
|
|
27
|
+
describe "#configure" do
|
28
|
+
it "exposes a configuration API" do
|
29
|
+
forge = Proxy.configure do
|
30
|
+
url "http://example.com"
|
31
|
+
end
|
32
|
+
expect(forge.instance_eval "@url").to eq "http://example.com"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#clear_cache" do
|
37
|
+
it "clears the caches" do
|
38
|
+
expect(query_cache).to receive(:clear)
|
39
|
+
expect(download_cache).to receive(:clear)
|
40
|
+
|
41
|
+
forge.clear_cache
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
27
45
|
describe "#search_modules" do
|
28
46
|
it "forwards the request directly" do
|
29
47
|
search_results = '["a","b","c"]'
|
data/spec/forge/source_spec.rb
CHANGED
@@ -18,8 +18,8 @@ require 'spec_helper'
|
|
18
18
|
|
19
19
|
module PuppetLibrary::Forge
|
20
20
|
describe Source do
|
21
|
-
let(:module_dir) { Tempdir.
|
22
|
-
let(:modulefile_path) { File.join(module_dir, "Modulefile") }
|
21
|
+
let(:module_dir) { Tempdir.new("module_dir") }
|
22
|
+
let(:modulefile_path) { File.join(module_dir.path, "Modulefile") }
|
23
23
|
let(:forge) { Source.new(module_dir) }
|
24
24
|
|
25
25
|
before do
|
@@ -28,10 +28,6 @@ module PuppetLibrary::Forge
|
|
28
28
|
add_module_dependency! "puppetlabs", "concat", ">= 1.0.1"
|
29
29
|
end
|
30
30
|
|
31
|
-
after do
|
32
|
-
rm_rf module_dir
|
33
|
-
end
|
34
|
-
|
35
31
|
def set_module!(author, name, version)
|
36
32
|
File.open(modulefile_path, "w") do |modulefile|
|
37
33
|
modulefile.puts <<-EOF
|
@@ -51,10 +47,19 @@ module PuppetLibrary::Forge
|
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
50
|
+
describe "#configure" do
|
51
|
+
it "exposes a configuration API" do
|
52
|
+
forge = Source.configure do
|
53
|
+
path module_dir.path
|
54
|
+
end
|
55
|
+
expect(forge.instance_eval "@module_dir.path").to eq module_dir.path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
54
59
|
describe "#initialize" do
|
55
60
|
context "when the module directory doesn't exist" do
|
56
61
|
before do
|
57
|
-
rm_rf module_dir
|
62
|
+
rm_rf module_dir.path
|
58
63
|
end
|
59
64
|
|
60
65
|
it "raises an error" do
|
@@ -66,11 +71,11 @@ module PuppetLibrary::Forge
|
|
66
71
|
|
67
72
|
context "when the module directory isn't readable" do
|
68
73
|
before do
|
69
|
-
chmod 0400, module_dir
|
74
|
+
chmod 0400, module_dir.path
|
70
75
|
end
|
71
76
|
|
72
77
|
after do
|
73
|
-
chmod 0777, module_dir
|
78
|
+
chmod 0777, module_dir.path
|
74
79
|
end
|
75
80
|
|
76
81
|
it "raises an error" do
|
@@ -19,13 +19,9 @@ require 'spec_helper'
|
|
19
19
|
|
20
20
|
module PuppetLibrary::Http::Cache
|
21
21
|
describe Disk do
|
22
|
-
let(:cache_dir) { Tempdir.new("modulecache")
|
22
|
+
let(:cache_dir) { Tempdir.new("modulecache") }
|
23
23
|
let(:cache) { Disk.new(cache_dir) }
|
24
24
|
|
25
|
-
after do
|
26
|
-
rm_rf cache_dir
|
27
|
-
end
|
28
|
-
|
29
25
|
describe "#get" do
|
30
26
|
context "the first time it's called" do
|
31
27
|
it "returns the value from the block" do
|
@@ -41,7 +37,7 @@ module PuppetLibrary::Http::Cache
|
|
41
37
|
|
42
38
|
result = cache.get("dir/my-file") { buffer }
|
43
39
|
|
44
|
-
path = File.join(cache_dir, "dir", "my-file")
|
40
|
+
path = File.join(cache_dir.path, "dir", "my-file")
|
45
41
|
expect(File.read(path)).to eq "hello"
|
46
42
|
end
|
47
43
|
end
|
@@ -53,5 +49,14 @@ module PuppetLibrary::Http::Cache
|
|
53
49
|
end
|
54
50
|
end
|
55
51
|
end
|
52
|
+
|
53
|
+
describe "#clear" do
|
54
|
+
it "clears the cache" do
|
55
|
+
cache.get("dir/my-file") { StringIO.new "1" }
|
56
|
+
cache.clear
|
57
|
+
result = cache.get("dir/my-file") { StringIO.new "2" }
|
58
|
+
expect(result.read).to eq "2"
|
59
|
+
end
|
60
|
+
end
|
56
61
|
end
|
57
62
|
end
|
@@ -59,5 +59,17 @@ module PuppetLibrary::Http::Cache
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
+
|
63
|
+
describe "#clear" do
|
64
|
+
it "clears the cache" do
|
65
|
+
cache.get { 1 }
|
66
|
+
result = cache.get { 2 }
|
67
|
+
expect(result).to eq 1
|
68
|
+
|
69
|
+
cache.clear
|
70
|
+
result = cache.get { 3 }
|
71
|
+
expect(result).to eq 3
|
72
|
+
end
|
73
|
+
end
|
62
74
|
end
|
63
75
|
end
|
@@ -17,18 +17,18 @@
|
|
17
17
|
|
18
18
|
RSpec::Matchers.define :be_cached do
|
19
19
|
match do |mod_file|
|
20
|
-
! Dir[File.join(cache_dir, mod_file)].empty?
|
20
|
+
! Dir[File.join(cache_dir.path, mod_file)].empty?
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
RSpec::Matchers.define :be_installed do
|
25
25
|
match do |mod_name|
|
26
|
-
File.directory?(File.join(project_dir, "modules", mod_name))
|
26
|
+
File.directory?(File.join(project_dir.path, "modules", mod_name))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def write_puppetfile(content)
|
31
|
-
File.open("#{project_dir}/Puppetfile", "w") do |puppetfile|
|
31
|
+
File.open("#{project_dir.path}/Puppetfile", "w") do |puppetfile|
|
32
32
|
puppetfile.puts content
|
33
33
|
end
|
34
34
|
end
|
data/spec/module_spec_helper.rb
CHANGED
@@ -59,12 +59,12 @@ module ModuleSpecHelper
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def add_module(author, name, version, &block)
|
62
|
-
writer = ModuleWriter.new(module_dir)
|
62
|
+
writer = ModuleWriter.new(module_dir.path)
|
63
63
|
writer.write_module(author, name, version, &block)
|
64
64
|
end
|
65
65
|
|
66
66
|
def add_file(file, content)
|
67
|
-
File.open(File.join(module_dir, file), "w") do |f|
|
67
|
+
File.open(File.join(module_dir.path, file), "w") do |f|
|
68
68
|
f.write content
|
69
69
|
end
|
70
70
|
end
|
data/spec/puppet_library_spec.rb
CHANGED
@@ -19,12 +19,12 @@ require 'spec_helper'
|
|
19
19
|
|
20
20
|
module PuppetLibrary
|
21
21
|
describe PuppetLibrary do
|
22
|
-
let
|
22
|
+
let :forge do
|
23
23
|
forge = double(Forge::Multi).as_null_object
|
24
24
|
allow(Forge::Multi).to receive(:new).and_return(forge)
|
25
25
|
return forge
|
26
26
|
end
|
27
|
-
let
|
27
|
+
let :server do
|
28
28
|
server = double(Server)
|
29
29
|
allow(Server).to receive(:new).with(forge).and_return(server)
|
30
30
|
return server
|
@@ -108,18 +108,19 @@ module PuppetLibrary
|
|
108
108
|
|
109
109
|
context "when using --config-file option" do
|
110
110
|
it "uses config values from config file as config defaults" do
|
111
|
+
forge_dir = Tempdir.new("forge")
|
111
112
|
config = {
|
112
113
|
"port" => 4567,
|
113
114
|
"daemonize" => true,
|
114
115
|
"server" => "thin",
|
115
116
|
"pidfile" => "/var/run/puppet-library.pid",
|
116
117
|
"forges" => [
|
117
|
-
{ "Directory" =>
|
118
|
+
{ "Directory" => forge_dir.path },
|
118
119
|
{ "Proxy" => "http://forge.puppetlabs.com" }
|
119
120
|
]
|
120
121
|
}
|
121
122
|
File.open(config_file.path, "w") { |f| f << config.to_yaml }
|
122
|
-
expect(Forge::Directory).to receive(:new)
|
123
|
+
expect(Forge::Directory).to receive(:new)
|
123
124
|
expect(Forge::Proxy).to receive(:new).with("http://forge.puppetlabs.com")
|
124
125
|
expect(forge).to receive(:add_forge).twice
|
125
126
|
expect(Rack::Server).to receive(:start).with(default_options_with(:Port => 4567, :daemonize => true, :pid => "/var/run/puppet-library.pid", :server => "thin"))
|
@@ -129,6 +130,8 @@ module PuppetLibrary
|
|
129
130
|
end
|
130
131
|
|
131
132
|
context "when using --proxy option" do
|
133
|
+
let(:proxy) { double('proxy').as_null_object }
|
134
|
+
|
132
135
|
it "adds a proxy module forge for each option specified" do
|
133
136
|
proxy1 = double('proxy1')
|
134
137
|
proxy2 = double('proxy2')
|
@@ -143,7 +146,7 @@ module PuppetLibrary
|
|
143
146
|
|
144
147
|
context "when no protocol is specified" do
|
145
148
|
it "defaults to HTTP" do
|
146
|
-
expect(Forge::Proxy).to receive(:new).with("http://forge.example.com")
|
149
|
+
expect(Forge::Proxy).to receive(:new).with("http://forge.example.com").and_return proxy
|
147
150
|
|
148
151
|
library.go(["--proxy", "forge.example.com"])
|
149
152
|
end
|
@@ -151,7 +154,7 @@ module PuppetLibrary
|
|
151
154
|
|
152
155
|
context "when the URL contains a trailing slash" do
|
153
156
|
it "removes the slash" do
|
154
|
-
expect(Forge::Proxy).to receive(:new).with("http://forge.example.com")
|
157
|
+
expect(Forge::Proxy).to receive(:new).with("http://forge.example.com").and_return proxy
|
155
158
|
|
156
159
|
library.go(["--proxy", "http://forge.example.com/"])
|
157
160
|
end
|
@@ -159,28 +162,42 @@ module PuppetLibrary
|
|
159
162
|
end
|
160
163
|
|
161
164
|
context "when using --cache-basedir option" do
|
165
|
+
let(:proxy) { double('proxy').as_null_object }
|
166
|
+
let(:cache_basedir) { Tempdir.new("cache") }
|
167
|
+
let(:cache_dir) { double(Dir) }
|
168
|
+
|
169
|
+
before do
|
170
|
+
expect(Dir).to receive(:new).with("#{cache_basedir.path}/forge1.example.com").and_return(cache_dir)
|
171
|
+
end
|
172
|
+
|
162
173
|
it "uses the specified directory to hold cache directories for all proxies" do
|
163
|
-
|
164
|
-
expect(
|
165
|
-
expect(forge).to receive(:add_forge).with(proxy1)
|
174
|
+
expect(Forge::Cache).to receive(:new).with("http://forge1.example.com", cache_dir).and_return(proxy)
|
175
|
+
expect(forge).to receive(:add_forge).with(proxy)
|
166
176
|
expect(Rack::Server).to receive(:start).with(default_options)
|
167
177
|
|
168
|
-
library.go(["--proxy", "http://forge1.example.com", "--cache-basedir",
|
178
|
+
library.go(["--proxy", "http://forge1.example.com", "--cache-basedir", cache_basedir.path])
|
169
179
|
end
|
170
180
|
|
171
181
|
it "expands the path specified" do
|
172
|
-
expect(Forge::Cache).to receive(:new).with("http://forge1.example.com",
|
182
|
+
expect(Forge::Cache).to receive(:new).with("http://forge1.example.com", cache_dir).and_return(proxy)
|
173
183
|
|
174
|
-
library.go(["--proxy", "http://forge1.example.com", "--cache-basedir", "/
|
184
|
+
library.go(["--proxy", "http://forge1.example.com", "--cache-basedir", "#{cache_basedir.path}/xxx/.."])
|
175
185
|
end
|
176
186
|
end
|
177
187
|
|
188
|
+
def dir(path)
|
189
|
+
dir = double(Dir)
|
190
|
+
allow(Dir).to receive(:new).with(/.*#{path}$/).and_return dir
|
191
|
+
dir
|
192
|
+
end
|
193
|
+
|
178
194
|
context "when using --module-dir option" do
|
179
195
|
it "adds a directory forge to the server for each module directory" do
|
180
196
|
directory_forge_1 = double("directory_forge_1")
|
181
197
|
directory_forge_2 = double("directory_forge_2")
|
182
|
-
|
183
|
-
expect(Forge::Directory).to receive(:new).with(
|
198
|
+
dir1, dir2 = dir("dir1"), dir("dir2")
|
199
|
+
expect(Forge::Directory).to receive(:new).with(dir1).and_return(directory_forge_1)
|
200
|
+
expect(Forge::Directory).to receive(:new).with(dir2).and_return(directory_forge_2)
|
184
201
|
expect(forge).to receive(:add_forge).with(directory_forge_1)
|
185
202
|
expect(forge).to receive(:add_forge).with(directory_forge_2)
|
186
203
|
expect(Rack::Server).to receive(:start).with(default_options)
|
@@ -193,8 +210,9 @@ module PuppetLibrary
|
|
193
210
|
it "adds a source forge to the server for each source directory" do
|
194
211
|
source_forge_1 = double("source_forge_1")
|
195
212
|
source_forge_2 = double("source_forge_2")
|
196
|
-
|
197
|
-
expect(Forge::Source).to receive(:new).with(
|
213
|
+
dir1, dir2 = dir("dir1"), dir("dir2")
|
214
|
+
expect(Forge::Source).to receive(:new).with(dir1).and_return(source_forge_1)
|
215
|
+
expect(Forge::Source).to receive(:new).with(dir2).and_return(source_forge_2)
|
198
216
|
expect(forge).to receive(:add_forge).with(source_forge_1)
|
199
217
|
expect(forge).to receive(:add_forge).with(source_forge_2)
|
200
218
|
expect(Rack::Server).to receive(:start).with(default_options)
|
@@ -18,10 +18,10 @@ require 'spec_helper'
|
|
18
18
|
|
19
19
|
module PuppetLibrary::PuppetModule
|
20
20
|
describe Modulefile do
|
21
|
-
let(:
|
21
|
+
let(:module_file) { Tempfile.new("Modulefile") }
|
22
22
|
|
23
23
|
def write_modulefile(content)
|
24
|
-
File.open(
|
24
|
+
File.open(module_file.path, "w") do |f|
|
25
25
|
f.write content
|
26
26
|
end
|
27
27
|
end
|
@@ -42,12 +42,8 @@ module PuppetLibrary::PuppetModule
|
|
42
42
|
EOF
|
43
43
|
end
|
44
44
|
|
45
|
-
after do
|
46
|
-
modulefile.unlink
|
47
|
-
end
|
48
|
-
|
49
45
|
describe "#read" do
|
50
|
-
let(:metadata) { Modulefile.read(
|
46
|
+
let(:metadata) { Modulefile.read(module_file.path) }
|
51
47
|
|
52
48
|
it "parses the name" do
|
53
49
|
expect(metadata.get_name).to eq "joe-ficticious"
|
@@ -81,7 +77,6 @@ module PuppetLibrary::PuppetModule
|
|
81
77
|
expect(metadata.get_license).to eq "Apache 2.0"
|
82
78
|
end
|
83
79
|
|
84
|
-
|
85
80
|
it "parses the dependencies" do
|
86
81
|
expect(metadata.get_dependencies).to eq [
|
87
82
|
{ "name" => "example/standard", "version_requirement" => '>= 2.3.4' },
|
@@ -97,7 +92,7 @@ module PuppetLibrary::PuppetModule
|
|
97
92
|
rating '10'
|
98
93
|
EOF
|
99
94
|
expect(Modulefile).to receive(:log).with(/rating/)
|
100
|
-
Modulefile.read(
|
95
|
+
Modulefile.read(module_file.path)
|
101
96
|
end
|
102
97
|
end
|
103
98
|
end
|
@@ -107,6 +102,50 @@ module PuppetLibrary::PuppetModule
|
|
107
102
|
metadata = Modulefile.parse("version '1.0.0'")
|
108
103
|
expect(metadata.get_version).to eq "1.0.0"
|
109
104
|
end
|
105
|
+
|
106
|
+
context "when a a value is missing" do
|
107
|
+
it "defaults to an empty string" do
|
108
|
+
modulefile = Modulefile.parse <<-EOF
|
109
|
+
name 'joe-ficticious'
|
110
|
+
version '1.2.3'
|
111
|
+
EOF
|
112
|
+
expect(modulefile.get_description).to eq ""
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#to_metadata" do
|
118
|
+
let :modulefile do
|
119
|
+
Modulefile.parse <<-EOF
|
120
|
+
name 'joe-ficticious'
|
121
|
+
version '1.2.3'
|
122
|
+
source 'git://example.com/joe/puppet-ficticious.git'
|
123
|
+
author 'joe'
|
124
|
+
license 'Apache 2.0'
|
125
|
+
summary 'Example module'
|
126
|
+
description 'Module for use in a test'
|
127
|
+
project_page 'https://example.com/joe/puppet-apache'
|
128
|
+
|
129
|
+
dependency 'example/standard', '>= 2.3.4'
|
130
|
+
dependency 'example/other', '>= 5.6.7'
|
131
|
+
EOF
|
132
|
+
end
|
133
|
+
|
134
|
+
it "converts the modulefile into a metadata hash" do
|
135
|
+
metadata = modulefile.to_metadata
|
136
|
+
expect(metadata["name"]).to eq "joe-ficticious"
|
137
|
+
expect(metadata["version"]).to eq "1.2.3"
|
138
|
+
expect(metadata["source"]).to eq "git://example.com/joe/puppet-ficticious.git"
|
139
|
+
expect(metadata["author"]).to eq "joe"
|
140
|
+
expect(metadata["license"]).to eq "Apache 2.0"
|
141
|
+
expect(metadata["summary"]).to eq "Example module"
|
142
|
+
expect(metadata["description"]).to eq "Module for use in a test"
|
143
|
+
expect(metadata["project_page"]).to eq "https://example.com/joe/puppet-apache"
|
144
|
+
expect(metadata["dependencies"]).to eq [
|
145
|
+
{ "name" => 'example/standard', "version_requirement" => ">= 2.3.4" },
|
146
|
+
{ "name" => 'example/other', "version_requirement" => ">= 5.6.7" }
|
147
|
+
]
|
148
|
+
end
|
110
149
|
end
|
111
150
|
end
|
112
151
|
end
|