puppet-library 0.9.1 → 0.10.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 +7 -7
- data/CHANGELOG.yml +1 -0
- data/README.md +9 -4
- data/Rakefile +44 -23
- data/TODO.yml +3 -4
- data/config.ru +28 -3
- data/lib/puppet_library/forge/cache.rb +19 -0
- data/lib/puppet_library/forge/directory.rb +16 -0
- data/lib/puppet_library/forge/git_repository.rb +57 -49
- data/lib/puppet_library/forge/proxy.rb +18 -4
- data/lib/puppet_library/forge/source.rb +10 -0
- data/lib/puppet_library/puppet_library.rb +1 -1
- data/lib/puppet_library/server.rb +12 -3
- data/lib/puppet_library/util/git.rb +103 -0
- data/lib/puppet_library/util/patches.rb +104 -0
- data/lib/puppet_library/util/temp_dir.rb +42 -0
- data/lib/puppet_library/util.rb +4 -70
- data/lib/puppet_library/version.rb +1 -1
- data/spec/archive/archive_reader_spec.rb +9 -2
- data/spec/archive/archiver_spec.rb +4 -0
- data/spec/forge/cache_spec.rb +4 -0
- data/spec/forge/directory_spec.rb +4 -0
- data/spec/forge/git_repository_spec.rb +5 -2
- data/spec/forge/source_spec.rb +4 -0
- data/spec/integration_test_helper.rb +42 -0
- data/spec/util/git_spec.rb +143 -0
- data/spec/util/patches_spec.rb +86 -0
- data/spec/util/temp_dir_spec.rb +35 -0
- data/test/directory_forge_integration_test.rb +96 -0
- data/test/offline_git_repo_forge_integration_test.rb +122 -0
- data/test/offline_proxy_forge_integration_test.rb +126 -0
- data/test/online_git_repo_forge_integration_test.rb +89 -0
- data/test/online_proxy_forge_integration_test.rb +93 -0
- data/test/source_forge_integration_test.rb +96 -0
- metadata +292 -118
- data/spec/util_spec.rb +0 -43
- data/test/librarian_puppet_integration_test.rb +0 -349
@@ -0,0 +1,104 @@
|
|
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 'rubygems/package'
|
19
|
+
|
20
|
+
# Early versions of Rubygems have problems with version numbers with dashes
|
21
|
+
# (e.g. "1.0.0-rc1"). This adds the behaviour or new RG versions to all
|
22
|
+
# versions, hopefully without breaking newer versions. In most cases we want to
|
23
|
+
# fail silently with bad version numbers so that we don't crash the server
|
24
|
+
# because of weird stuff from a remote forge or elsewhere.
|
25
|
+
module Gem
|
26
|
+
def Version.new(version)
|
27
|
+
super(version.to_s.gsub("-",".pre."))
|
28
|
+
rescue ArgumentError
|
29
|
+
# If it starts with numbers, use those
|
30
|
+
if version =~ /^\d+(\.\d+)*/
|
31
|
+
super(version[/^\d+(\.\d+)*/])
|
32
|
+
# Somebody's really made a mess of this version number
|
33
|
+
else
|
34
|
+
super("0")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def Dependency.new(name, spec)
|
39
|
+
super(name, spec.to_s.gsub("-", ".pre."))
|
40
|
+
rescue ArgumentError
|
41
|
+
# If it starts with numbers, use those
|
42
|
+
if spec =~ /^([~><= ]+)?\d+(\.\d+)*/
|
43
|
+
super(name, spec[/^([~><= ]+)?\d+(\.\d+)*/])
|
44
|
+
# Somebody's really made a mess of this version number
|
45
|
+
else
|
46
|
+
super(name, ">= 0")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Array
|
52
|
+
# Like 'uniq' with a block, but also works on Ruby < 1.9
|
53
|
+
def unique_by
|
54
|
+
attr_to_element = {}
|
55
|
+
select do |element|
|
56
|
+
attribute = yield(element)
|
57
|
+
is_duplicate = attr_to_element.include? attribute
|
58
|
+
unless is_duplicate
|
59
|
+
attr_to_element[attribute] = element
|
60
|
+
end
|
61
|
+
!is_duplicate
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def version_sort
|
66
|
+
version_sort_by { |e| e }
|
67
|
+
end
|
68
|
+
|
69
|
+
def version_sort_by
|
70
|
+
sort_by do |element|
|
71
|
+
version = yield(element)
|
72
|
+
Gem::Version.new(version)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def deep_merge
|
77
|
+
inject({}) do |merged, map|
|
78
|
+
merged.deep_merge(map)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Hash
|
84
|
+
def deep_merge(other)
|
85
|
+
merge(other) do |key, old_val, new_val|
|
86
|
+
if old_val.instance_of? Array
|
87
|
+
old_val + new_val
|
88
|
+
else
|
89
|
+
new_val
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class Gem::Package::TarReader
|
96
|
+
# Old versions of RubyGems don't include Enumerable in here
|
97
|
+
def find
|
98
|
+
each do |entry|
|
99
|
+
if yield(entry)
|
100
|
+
return entry
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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 'fileutils'
|
19
|
+
|
20
|
+
module PuppetLibrary::Util
|
21
|
+
class TempDir
|
22
|
+
attr_reader :path
|
23
|
+
|
24
|
+
def self.use(name, &block)
|
25
|
+
path = create(name)
|
26
|
+
Dir.chdir(path, &block)
|
27
|
+
ensure
|
28
|
+
FileUtils.rm_rf path
|
29
|
+
end
|
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
|
42
|
+
end
|
data/lib/puppet_library/util.rb
CHANGED
@@ -15,75 +15,9 @@
|
|
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
|
-
|
19
|
-
|
20
|
-
module Gem
|
21
|
-
def Version.new(version)
|
22
|
-
begin
|
23
|
-
super(version.to_s.gsub("-",".pre."))
|
24
|
-
rescue ArgumentError => e
|
25
|
-
# If it starts with numbers, use those
|
26
|
-
if version =~ /^\d+(\.\d+)*/
|
27
|
-
super(version[/^\d+(\.\d+)*/])
|
28
|
-
# Somebody's really made a mess of this version number
|
29
|
-
else
|
30
|
-
super("0")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
18
|
+
module PuppetLibrary::Util
|
34
19
|
end
|
35
20
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
attr_to_element = {}
|
40
|
-
select do |element|
|
41
|
-
attribute = yield(element)
|
42
|
-
is_duplicate = attr_to_element.include? attribute
|
43
|
-
unless is_duplicate
|
44
|
-
attr_to_element[attribute] = element
|
45
|
-
end
|
46
|
-
!is_duplicate
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def version_sort
|
51
|
-
version_sort_by { |e| e }
|
52
|
-
end
|
53
|
-
|
54
|
-
def version_sort_by
|
55
|
-
sort_by do |element|
|
56
|
-
version = yield(element)
|
57
|
-
Gem::Version.new(version)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def deep_merge
|
62
|
-
inject({}) do |merged, map|
|
63
|
-
merged.deep_merge(map)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class Hash
|
69
|
-
def deep_merge(other)
|
70
|
-
merge(other) do |key, old_val, new_val|
|
71
|
-
if old_val.instance_of? Array
|
72
|
-
old_val + new_val
|
73
|
-
else
|
74
|
-
new_val
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class Gem::Package::TarReader
|
81
|
-
# Old versions of RubyGems don't include Enumerable in here
|
82
|
-
def find
|
83
|
-
each do |entry|
|
84
|
-
if yield(entry)
|
85
|
-
return entry
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
21
|
+
require 'puppet_library/util/git'
|
22
|
+
require 'puppet_library/util/patches'
|
23
|
+
require 'puppet_library/util/temp_dir'
|
@@ -22,9 +22,12 @@ module PuppetLibrary::Archive
|
|
22
22
|
ArchiveReader.new(archive)
|
23
23
|
end
|
24
24
|
|
25
|
+
let :source_dir do
|
26
|
+
Tempdir.create("zipping")
|
27
|
+
end
|
28
|
+
|
25
29
|
let :archive do
|
26
|
-
|
27
|
-
archive = File.join(dir, "archive.tgz")
|
30
|
+
archive = File.join(source_dir, "archive.tgz")
|
28
31
|
write_tar_gzip!(archive) do |zip|
|
29
32
|
zip.add_file("arrive.txt", 0644) { |entry| entry.write "say hello" }
|
30
33
|
zip.add_file("later/depart.txt", 0644) { |entry| entry.write "say bye" }
|
@@ -32,6 +35,10 @@ module PuppetLibrary::Archive
|
|
32
35
|
archive
|
33
36
|
end
|
34
37
|
|
38
|
+
after do
|
39
|
+
rm_rf source_dir
|
40
|
+
end
|
41
|
+
|
35
42
|
def write_tar_gzip!(file_name)
|
36
43
|
tar = StringIO.new
|
37
44
|
|
data/spec/forge/cache_spec.rb
CHANGED
@@ -23,6 +23,10 @@ module PuppetLibrary::Forge
|
|
23
23
|
let(:http_client) { double(PuppetLibrary::Http::HttpClient) }
|
24
24
|
let(:forge) { Cache.new("http://forge.example.com", cache_dir, http_client) }
|
25
25
|
|
26
|
+
after do
|
27
|
+
rm_rf cache_dir
|
28
|
+
end
|
29
|
+
|
26
30
|
it "is a proxy" do
|
27
31
|
expect(forge).to be_a Proxy
|
28
32
|
end
|
@@ -52,7 +52,10 @@ module PuppetLibrary::Forge
|
|
52
52
|
rm_rf @@repo_path
|
53
53
|
end
|
54
54
|
|
55
|
-
let(:forge) { GitRepository.new(
|
55
|
+
let(:forge) { GitRepository.new(@@repo_path, /[0-9.]+/) }
|
56
|
+
after do
|
57
|
+
forge.destroy!
|
58
|
+
end
|
56
59
|
|
57
60
|
describe "#get_module" do
|
58
61
|
context "when the requested author is different from the configured author" do
|
@@ -115,7 +118,7 @@ module PuppetLibrary::Forge
|
|
115
118
|
|
116
119
|
describe "#get_all_metadata" do
|
117
120
|
it "generates the metadata for the each version" do
|
118
|
-
metadata = forge.
|
121
|
+
metadata = forge.get_all_metadata
|
119
122
|
expect(metadata).to have(3).versions
|
120
123
|
expect(metadata.first["name"]).to eq "puppetlabs-apache"
|
121
124
|
expect(metadata.first["version"]).to eq "0.9.0"
|
data/spec/forge/source_spec.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
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
|
+
RSpec::Matchers.define :be_cached do
|
19
|
+
match do |mod_file|
|
20
|
+
! Dir[File.join(cache_dir, mod_file)].empty?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec::Matchers.define :be_installed do
|
25
|
+
match do |mod_name|
|
26
|
+
File.directory?(File.join(project_dir, "modules", mod_name))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def write_puppetfile(content)
|
31
|
+
File.open("#{project_dir}/Puppetfile", "w") do |puppetfile|
|
32
|
+
puppetfile.puts content
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
module Ports
|
38
|
+
def self.next!
|
39
|
+
@port ||= 9000
|
40
|
+
@port += 1
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,143 @@
|
|
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 Git do
|
21
|
+
@@repo_path = Tempdir.create("git-repo")
|
22
|
+
@@tags = [ "0.9.0", "1.0.0-rc1", "1.0.0", "xxx" ]
|
23
|
+
|
24
|
+
before :all do
|
25
|
+
def git(command)
|
26
|
+
git_command = "git --git-dir=#{@@repo_path}/.git --work-tree=#{@@repo_path} #{command}"
|
27
|
+
`#{git_command}`
|
28
|
+
unless $?.success?
|
29
|
+
raise "Failed to run command: \"#{git_command}\""
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
git "init"
|
34
|
+
git "config user.name tester"
|
35
|
+
git "config user.email tester@example.com"
|
36
|
+
@@tags.each do |tag|
|
37
|
+
File.open(File.join(@@repo_path, "Modulefile"), "w") do |modulefile|
|
38
|
+
modulefile.write <<-MODULEFILE
|
39
|
+
name 'puppetlabs-apache'
|
40
|
+
version '#{tag}'
|
41
|
+
author 'puppetlabs'
|
42
|
+
MODULEFILE
|
43
|
+
end
|
44
|
+
git "add ."
|
45
|
+
git "commit --message='Tagging #{tag}'"
|
46
|
+
git "tag #{tag}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
after :all do
|
51
|
+
rm_rf @@repo_path
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:git) { Git.new(@@repo_path, cache_path) }
|
55
|
+
let(:cache_path) { Tempdir.create("git-cache") }
|
56
|
+
|
57
|
+
after do
|
58
|
+
git.clear_cache!
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#tags" do
|
62
|
+
it "lists the tags" do
|
63
|
+
@@tags.each { |tag| expect(git.tags).to include tag }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#on_tag" do
|
68
|
+
it "yields to the block in a directory containing the tag" do
|
69
|
+
git.on_tag("1.0.0") do
|
70
|
+
expect(File.read("Modulefile")).to include "version '1.0.0'"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#read_file" do
|
76
|
+
it "returns the content of the specified file as it was at the specified tag" do
|
77
|
+
expect(git.read_file("Modulefile", "0.9.0")).to include "version '0.9.0'"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#update_cache!" do
|
82
|
+
it "clones the git repository to the cache directory" do
|
83
|
+
git.update_cache!
|
84
|
+
|
85
|
+
expect(`git --git-dir #{cache_path}/.git remote -v`).to include @@repo_path
|
86
|
+
end
|
87
|
+
|
88
|
+
it "creates Git's .git/FETCH_HEAD file so that we know that the cache was recently created" do
|
89
|
+
git.update_cache!
|
90
|
+
|
91
|
+
expect(File.exist?(File.join(cache_path, ".git", "FETCH_HEAD"))).to be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "copes with a missing .git/FETCH_HEAD file" do
|
95
|
+
fetch_file = File.join(cache_path, ".git", "FETCH_HEAD")
|
96
|
+
git.update_cache!
|
97
|
+
rm fetch_file
|
98
|
+
|
99
|
+
git.update_cache!
|
100
|
+
|
101
|
+
expect(File.exist? fetch_file).to be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
it "doesn't update the cache if it was recently updated" do
|
105
|
+
git.update_cache!
|
106
|
+
new_head = Dir.chdir(@@repo_path) do
|
107
|
+
touch "xxx"
|
108
|
+
`git add xxx`
|
109
|
+
`git commit --message='Added file'`
|
110
|
+
`git rev-parse HEAD`
|
111
|
+
end
|
112
|
+
|
113
|
+
git.update_cache!
|
114
|
+
|
115
|
+
expect(`git --git-dir #{cache_path}/.git rev-parse HEAD`).not_to eq new_head
|
116
|
+
end
|
117
|
+
|
118
|
+
it "updates the cache if it's been long enough" do
|
119
|
+
git.update_cache!
|
120
|
+
git = Git.new(@@repo_path, cache_path, 0) # zero second cache TTL
|
121
|
+
new_head = Dir.chdir(@@repo_path) do
|
122
|
+
touch "xxx"
|
123
|
+
`git add xxx`
|
124
|
+
`git commit --message='Added file'`
|
125
|
+
`git rev-parse HEAD`
|
126
|
+
end
|
127
|
+
|
128
|
+
git.update_cache!
|
129
|
+
|
130
|
+
expect(`git --git-dir #{cache_path}/.git rev-parse HEAD`).to eq new_head
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#clear_cache!" do
|
135
|
+
it "deletes the cache directory" do
|
136
|
+
git.update_cache!
|
137
|
+
git.clear_cache!
|
138
|
+
|
139
|
+
expect(File.exist? cache_path).to be_false
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,86 @@
|
|
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
|
+
describe 'patches' do
|
21
|
+
describe Gem::Version do
|
22
|
+
describe "#new" do
|
23
|
+
context "when the version number contains a dash" do
|
24
|
+
it "replaces the dash with '.pre.'" do
|
25
|
+
expect(Gem::Version.new("1.0.0-rc1")).to eq Gem::Version.new("1.0.0.pre.rc1")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
context "when the version number has trailing garbage" do
|
29
|
+
it "uses the numbers at the beginning" do
|
30
|
+
expect(Gem::Version.new("123 xyz")).to eq Gem::Version.new("123")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context "when the version is completely garbage" do
|
34
|
+
it "pretends the version number is zero" do
|
35
|
+
expect(Gem::Version.new("xyz")).to eq Gem::Version.new("0")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
describe Gem::Dependency do
|
41
|
+
describe "#new" do
|
42
|
+
context "when the version contains a dash" do
|
43
|
+
it "replaces the dash with '.pre.'" do
|
44
|
+
expect(Gem::Dependency.new("x", "1.0.0-rc1")).to eq Gem::Dependency.new("x", "1.0.0.pre.rc1")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
context "when the version number has trailing garbage" do
|
48
|
+
it "uses the numbers at the beginning" do
|
49
|
+
[ "", "~>", "<", ">", ">=", "<=", "=" ].each do |operator|
|
50
|
+
expect(Gem::Dependency.new("x", " #{operator} 123 xyz")).to eq Gem::Dependency.new("x", "#{operator} 123")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
context "when the version is completely garbage" do
|
55
|
+
it "pretends the version number is greater than or equal zero" do
|
56
|
+
[ "", "<", ">", ">=", "<=", "=" ].each do |operator|
|
57
|
+
expect(Gem::Dependency.new("x", " #{operator} xyz")).to eq Gem::Dependency.new("x", ">= 0")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe Array do
|
65
|
+
describe "#unique_by" do
|
66
|
+
it "behaves like #uniq with a block, but works with Ruby < 1.9" do
|
67
|
+
son = { "name" => "john", "age" => 10 }
|
68
|
+
dad = { "name" => "john", "age" => 40 }
|
69
|
+
mom = { "name" => "jane", "age" => 40 }
|
70
|
+
|
71
|
+
family = [son, dad, mom]
|
72
|
+
expect(family.unique_by {|p| p["name"]}).to eq [son, mom]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#version_sort" do
|
77
|
+
it "sorts according to version numbers" do
|
78
|
+
expect(["2.0.0", "1.10.0", "1.2.0"].version_sort).to eq ["1.2.0", "1.10.0", "2.0.0"]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "copes with odd versions" do
|
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
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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::Util
|
21
|
+
describe TempDir do
|
22
|
+
describe "#use" do
|
23
|
+
it "creates a directory and changes to it for the life of the block" do
|
24
|
+
dir_path = nil
|
25
|
+
dir_existed_in_block = false
|
26
|
+
TempDir.use("xxx") do |path|
|
27
|
+
dir_existed_in_block = File.directory? path
|
28
|
+
dir_path = path
|
29
|
+
end
|
30
|
+
expect(dir_existed_in_block).to be_true
|
31
|
+
expect(File.exist? dir_path).to be_false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|