berkshelf 3.0.0.beta7 → 3.0.0.beta8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +4 -1
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +0 -1
- data/Guardfile +0 -8
- data/README.md +33 -13
- data/berkshelf.gemspec +3 -3
- data/features/commands/install.feature +16 -88
- data/features/commands/search.feature +15 -0
- data/features/commands/shelf/show.feature +2 -2
- data/features/commands/shelf/uninstall.feature +1 -1
- data/features/commands/show.feature +3 -3
- data/features/commands/update.feature +29 -1
- data/features/commands/upload.feature +172 -7
- data/features/commands/vendor.feature +32 -0
- data/features/json_formatter.feature +26 -24
- data/features/lifecycle.feature +285 -0
- data/features/lockfile.feature +9 -7
- data/features/step_definitions/chef_server_steps.rb +1 -0
- data/features/step_definitions/cli_steps.rb +2 -2
- data/features/step_definitions/filesystem_steps.rb +2 -4
- data/gem_graph.png +0 -0
- data/generator_files/chefignore +0 -2
- data/lib/berkshelf.rb +39 -14
- data/lib/berkshelf/berksfile.rb +161 -113
- data/lib/berkshelf/cached_cookbook.rb +2 -2
- data/lib/berkshelf/cli.rb +15 -3
- data/lib/berkshelf/commands/shelf.rb +3 -7
- data/lib/berkshelf/community_rest.rb +9 -9
- data/lib/berkshelf/config.rb +3 -3
- data/lib/berkshelf/cookbook_generator.rb +0 -8
- data/lib/berkshelf/cookbook_store.rb +1 -2
- data/lib/berkshelf/dependency.rb +25 -138
- data/lib/berkshelf/downloader.rb +41 -7
- data/lib/berkshelf/errors.rb +113 -214
- data/lib/berkshelf/formatters/base.rb +42 -0
- data/lib/berkshelf/formatters/human.rb +145 -0
- data/lib/berkshelf/formatters/json.rb +149 -133
- data/lib/berkshelf/formatters/null.rb +8 -18
- data/lib/berkshelf/init_generator.rb +1 -1
- data/lib/berkshelf/installer.rb +115 -104
- data/lib/berkshelf/location.rb +22 -121
- data/lib/berkshelf/locations/base.rb +75 -0
- data/lib/berkshelf/locations/git.rb +196 -0
- data/lib/berkshelf/locations/github.rb +8 -0
- data/lib/berkshelf/locations/path.rb +78 -0
- data/lib/berkshelf/lockfile.rb +452 -290
- data/lib/berkshelf/logger.rb +9 -3
- data/lib/berkshelf/mixin/logging.rb +4 -9
- data/lib/berkshelf/resolver.rb +12 -12
- data/lib/berkshelf/source.rb +13 -1
- data/lib/berkshelf/version.rb +1 -1
- data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -7
- data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -6
- data/spec/spec_helper.rb +5 -6
- data/spec/support/matchers/file_system_matchers.rb +4 -0
- data/spec/support/shared_examples/formatter.rb +11 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +25 -28
- data/spec/unit/berkshelf/cli_spec.rb +19 -11
- data/spec/unit/berkshelf/dependency_spec.rb +4 -164
- data/spec/unit/berkshelf/formatters/base_spec.rb +35 -0
- data/spec/unit/berkshelf/formatters/human_spec.rb +7 -0
- data/spec/unit/berkshelf/formatters/json_spec.rb +7 -0
- data/spec/unit/berkshelf/formatters/null_spec.rb +7 -11
- data/spec/unit/berkshelf/location_spec.rb +16 -144
- data/spec/unit/berkshelf/locations/base_spec.rb +80 -0
- data/spec/unit/berkshelf/locations/git_spec.rb +249 -0
- data/spec/unit/berkshelf/locations/path_spec.rb +107 -0
- data/spec/unit/berkshelf/lockfile_parser_spec.rb +3 -3
- data/spec/unit/berkshelf/lockfile_spec.rb +55 -11
- data/spec/unit/berkshelf/logger_spec.rb +2 -2
- data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -9
- data/spec/unit/berkshelf/source_spec.rb +32 -13
- data/spec/unit/berkshelf_spec.rb +6 -9
- metadata +33 -33
- data/.ruby-version +0 -1
- data/berkshelf-complete.sh +0 -75
- data/lib/berkshelf/formatters.rb +0 -110
- data/lib/berkshelf/formatters/human_readable.rb +0 -142
- data/lib/berkshelf/git.rb +0 -204
- data/lib/berkshelf/locations/git_location.rb +0 -135
- data/lib/berkshelf/locations/github_location.rb +0 -55
- data/lib/berkshelf/locations/mercurial_location.rb +0 -114
- data/lib/berkshelf/locations/path_location.rb +0 -88
- data/lib/berkshelf/mercurial.rb +0 -146
- data/lib/berkshelf/mixin.rb +0 -7
- data/spec/support/mercurial.rb +0 -123
- data/spec/unit/berkshelf/formatters_spec.rb +0 -114
- data/spec/unit/berkshelf/git_spec.rb +0 -312
- data/spec/unit/berkshelf/locations/git_location_spec.rb +0 -126
- data/spec/unit/berkshelf/locations/mercurial_location_spec.rb +0 -131
- data/spec/unit/berkshelf/locations/path_location_spec.rb +0 -25
- data/spec/unit/berkshelf/mercurial_spec.rb +0 -172
data/lib/berkshelf/mixin.rb
DELETED
data/spec/support/mercurial.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
module Berkshelf
|
2
|
-
module RSpec
|
3
|
-
module Mercurial
|
4
|
-
require 'buff/shell_out'
|
5
|
-
include Buff::ShellOut
|
6
|
-
|
7
|
-
require_relative 'path_helpers'
|
8
|
-
include Berkshelf::RSpec::PathHelpers
|
9
|
-
|
10
|
-
def mercurial_origin_for(repo, options = {})
|
11
|
-
File.join("file://localhost", generate_fake_mercurial_remote(repo, options))
|
12
|
-
end
|
13
|
-
|
14
|
-
def generate_fake_mercurial_remote(uri, options = {})
|
15
|
-
repo_path = remotes.join(uri)
|
16
|
-
|
17
|
-
FileUtils.mkdir repo_path
|
18
|
-
|
19
|
-
Dir.chdir(repo_path) do
|
20
|
-
ENV['HGUSER'] = 'test_user'
|
21
|
-
shell_out "hg init"
|
22
|
-
shell_out "echo \"# a change!\" >> content_file"
|
23
|
-
if options[:is_cookbook]
|
24
|
-
shell_out "echo \"#cookbook\" >> metadata.rb"
|
25
|
-
end
|
26
|
-
shell_out "hg add ."
|
27
|
-
shell_out "hg commit -m \"A commit.\""
|
28
|
-
options[:tags].each do |tag|
|
29
|
-
shell_out "echo \"#{tag}\" > content_file"
|
30
|
-
shell_out "hg commit -m \"#{tag} content\""
|
31
|
-
shell_out "hg tag \"#{tag}\""
|
32
|
-
end if options.has_key? :tags
|
33
|
-
options[:branches].each do |branch|
|
34
|
-
shell_out "hg branch #{branch}"
|
35
|
-
shell_out "echo \"#{branch}\" > content_file"
|
36
|
-
shell_out "hg commit -m \"#{branch} content\""
|
37
|
-
shell_out "hg up default"
|
38
|
-
end if options.has_key? :branches
|
39
|
-
end
|
40
|
-
repo_path.to_path
|
41
|
-
end
|
42
|
-
|
43
|
-
# Calculate the id for the given mercurial rev.
|
44
|
-
#
|
45
|
-
# @param [#to_s] repo
|
46
|
-
# the repository to show the rev for
|
47
|
-
# @param [#to_s] rev
|
48
|
-
# the revision to identify
|
49
|
-
#
|
50
|
-
# @return [String]
|
51
|
-
def id_for_rev(repo, rev)
|
52
|
-
Dir.chdir remote_path(repo) do
|
53
|
-
shell_out("hg id -r '#{rev}'").stdout.split(' ').first.strip
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# The clone path the given repo.
|
58
|
-
#
|
59
|
-
# @param [#to_s] repo
|
60
|
-
# the name of the local repo
|
61
|
-
#
|
62
|
-
# @return [Pathname]
|
63
|
-
# the path to the clone
|
64
|
-
def clone_path(repo)
|
65
|
-
clones.join(repo.to_s)
|
66
|
-
end
|
67
|
-
|
68
|
-
# The clone path the remote repo.
|
69
|
-
#
|
70
|
-
# @param [#to_s] repo
|
71
|
-
# the name of the remote repo
|
72
|
-
#
|
73
|
-
# @return [Pathname]
|
74
|
-
# the path to the clone
|
75
|
-
def remote_path(repo)
|
76
|
-
remotes.join(repo.to_s)
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
# The path to store the local git clones.
|
82
|
-
#
|
83
|
-
# @return [Pathname]
|
84
|
-
def clones
|
85
|
-
ensure_and_return(tmp_path.join('clones'))
|
86
|
-
end
|
87
|
-
|
88
|
-
# The path to store the git remotes.
|
89
|
-
#
|
90
|
-
# @return [Pathname]
|
91
|
-
def remotes
|
92
|
-
ensure_and_return(tmp_path.join('remotes'))
|
93
|
-
end
|
94
|
-
|
95
|
-
# Generate a cookbook by the given name.
|
96
|
-
#
|
97
|
-
# @param [#to_s] name
|
98
|
-
# the name of the cookbook to create
|
99
|
-
# @param [Hash] options
|
100
|
-
# the list ooptions to pass to the generator
|
101
|
-
def generate_mercurial_cookbook(name, options = {})
|
102
|
-
options = {
|
103
|
-
skip_vagrant: true,
|
104
|
-
skip_test_kitchen: true,
|
105
|
-
force: true,
|
106
|
-
}.merge(options)
|
107
|
-
|
108
|
-
Berkshelf::Cli.new.invoke(:cookbook, [name.to_s], options)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Make sure the given path exists and return the path
|
112
|
-
#
|
113
|
-
# @param [#to_s] path
|
114
|
-
# the path to create and return
|
115
|
-
#
|
116
|
-
# @return [Pathname]
|
117
|
-
def ensure_and_return(path)
|
118
|
-
FileUtils.mkdir(path) unless File.exist?(path)
|
119
|
-
return Pathname.new(path).expand_path
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Berkshelf::Formatters do
|
4
|
-
before do
|
5
|
-
@original = Berkshelf::Formatters.class_variable_get :@@formatters
|
6
|
-
Berkshelf::Formatters.class_variable_set :@@formatters, {}
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
Berkshelf::Formatters.class_variable_set :@@formatters, @original
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:format_id) { :rspec }
|
14
|
-
let(:format_klass) { Class.new { include Berkshelf::Formatters::AbstractFormatter } }
|
15
|
-
|
16
|
-
describe '::register' do
|
17
|
-
it 'adds the class of the includer to the list of registered formatters with the id' do
|
18
|
-
Berkshelf::Formatters.register(format_id, format_klass)
|
19
|
-
|
20
|
-
expect(Berkshelf::Formatters.formatters).to have_key(format_id)
|
21
|
-
expect(Berkshelf::Formatters.formatters[format_id]).to eq(format_klass)
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when given a string instead of a symbol as the ID' do
|
25
|
-
it 'converts the string to a symbol and registers it' do
|
26
|
-
Berkshelf::Formatters.register('rspec', format_klass)
|
27
|
-
|
28
|
-
expect(Berkshelf::Formatters.formatters).to have_key(:rspec)
|
29
|
-
expect(Berkshelf::Formatters.formatters[:rspec]).to eq(format_klass)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when a formatter of the given ID has already been registered' do
|
34
|
-
it 'raises an InternalError' do
|
35
|
-
Berkshelf::Formatters.register(format_id, format_klass)
|
36
|
-
|
37
|
-
expect {
|
38
|
-
Berkshelf::Formatters.register(format_id, format_klass)
|
39
|
-
}.to raise_error(Berkshelf::InternalError)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '::formatters' do
|
45
|
-
before do
|
46
|
-
Berkshelf::Formatters.register(format_id, format_klass)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "returns a hash where formatter ID's are keys and values are formatter classes" do
|
50
|
-
expect(Berkshelf::Formatters.formatters).to be_a(Hash)
|
51
|
-
expect(Berkshelf::Formatters.formatters).to have(1).item
|
52
|
-
expect(Berkshelf::Formatters.formatters.keys.first).to eq(format_id)
|
53
|
-
expect(Berkshelf::Formatters.formatters.values.first).to eq(format_klass)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '::get' do
|
58
|
-
before { Berkshelf::Formatters.register(format_id, format_klass) }
|
59
|
-
|
60
|
-
it 'returns the class constant of the given formatter ID' do
|
61
|
-
expect(Berkshelf::Formatters[format_id]).to eq(format_klass)
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'when the ID has not been registered' do
|
65
|
-
it 'returns nil' do
|
66
|
-
expect(Berkshelf::Formatters[:not_there]).to be_nil
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe Berkshelf::Formatters::AbstractFormatter do
|
72
|
-
describe '::register_formatter' do
|
73
|
-
it 'delegates to Formatters' do
|
74
|
-
Berkshelf::Formatters.should_receive(:register).with(:rspec, format_klass)
|
75
|
-
|
76
|
-
format_klass.register_formatter(:rspec)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
subject do
|
81
|
-
Class.new { include Berkshelf::Formatters::AbstractFormatter }.new
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'has abstract methods for all the messaging modes' do
|
85
|
-
expect {
|
86
|
-
subject.install('my_coobook','1.2.3','http://community')
|
87
|
-
}.to raise_error(Berkshelf::AbstractFunction)
|
88
|
-
|
89
|
-
expect {
|
90
|
-
subject.use('my_coobook','1.2.3')
|
91
|
-
}.to raise_error(Berkshelf::AbstractFunction)
|
92
|
-
|
93
|
-
expect {
|
94
|
-
subject.use('my_coobook','1.2.3','http://community')
|
95
|
-
}.to raise_error(Berkshelf::AbstractFunction)
|
96
|
-
|
97
|
-
expect {
|
98
|
-
subject.upload('my_coobook','1.2.3','http://chef_server')
|
99
|
-
}.to raise_error(Berkshelf::AbstractFunction)
|
100
|
-
|
101
|
-
expect {
|
102
|
-
subject.msg('something you to know')
|
103
|
-
}.to raise_error(Berkshelf::AbstractFunction)
|
104
|
-
|
105
|
-
expect {
|
106
|
-
subject.error('whoa this is bad')
|
107
|
-
}.to raise_error(Berkshelf::AbstractFunction)
|
108
|
-
|
109
|
-
expect {
|
110
|
-
subject.fetch(double('dependency'))
|
111
|
-
}.to raise_error(Berkshelf::AbstractFunction)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,312 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Berkshelf::Git do
|
4
|
-
let(:git) { Berkshelf::Git }
|
5
|
-
|
6
|
-
describe '::find_git' do
|
7
|
-
it 'finds git' do
|
8
|
-
expect(Berkshelf::Git.find_git).to_not be_nil
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'raises an error if git cannot be not found' do
|
12
|
-
ENV.should_receive(:[]).with('PATH').and_return(String.new)
|
13
|
-
|
14
|
-
expect {
|
15
|
-
Berkshelf::Git.find_git
|
16
|
-
}.to raise_error(Berkshelf::GitNotFound)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '::clone' do
|
21
|
-
let(:target) { clone_path('nginx') }
|
22
|
-
|
23
|
-
it 'clones the repository to the target path' do
|
24
|
-
origin_uri = git_origin_for('nginx')
|
25
|
-
Berkshelf::Git.clone(origin_uri, target)
|
26
|
-
|
27
|
-
expect(target).to exist
|
28
|
-
expect(target).to be_directory
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '::checkout' do
|
33
|
-
let(:repo_path) { clone_path('nginx') }
|
34
|
-
let(:repo) {
|
35
|
-
origin_uri = git_origin_for('nginx', tags: ['1.0.1', '1.0.2'], branches: ['topic', 'next_topic'])
|
36
|
-
git.clone(origin_uri, repo_path)
|
37
|
-
}
|
38
|
-
|
39
|
-
shared_examples 'able to checkout git ref' do |test_ref|
|
40
|
-
it 'checks out the specified ref of the given repository' do
|
41
|
-
git.checkout(repo, ref)
|
42
|
-
|
43
|
-
Dir.chdir repo_path do
|
44
|
-
test_ref ||= ref
|
45
|
-
expect(%x[git rev-parse #{test_ref}]).to eq(%x[git rev-parse HEAD])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'with sha commit id' do
|
51
|
-
let(:ref) { sha_for_ref('nginx', '1.0.1') }
|
52
|
-
|
53
|
-
it_behaves_like 'able to checkout git ref'
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'with tags' do
|
57
|
-
let(:ref) { '1.0.1' }
|
58
|
-
|
59
|
-
it_behaves_like 'able to checkout git ref'
|
60
|
-
|
61
|
-
context 'after checking out another tag' do
|
62
|
-
let(:other_tag) { '1.0.2' }
|
63
|
-
before do
|
64
|
-
git.checkout(repo, other_tag)
|
65
|
-
Dir.chdir repo_path do
|
66
|
-
shell_out "echo 'uncommitted change' >> content_file"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
it_behaves_like 'able to checkout git ref'
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'with branches' do
|
75
|
-
let(:ref) { 'topic' }
|
76
|
-
|
77
|
-
it_behaves_like 'able to checkout git ref', 'origin/topic'
|
78
|
-
|
79
|
-
context 'after checking out another branch' do
|
80
|
-
let(:other_branch) { 'next_topic' }
|
81
|
-
before do
|
82
|
-
git.checkout(repo, other_branch)
|
83
|
-
Dir.chdir repo_path do
|
84
|
-
shell_out "echo 'uncommitted change' >> content_file"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it_behaves_like 'able to checkout git ref', 'origin/topic'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe '::rev_parse' do
|
94
|
-
let(:repo_path) { clone_path('nginx') }
|
95
|
-
before(:each) do |example|
|
96
|
-
origin_uri = git_origin_for('nginx', tags: ['1.1.1'])
|
97
|
-
Berkshelf::Git.clone(origin_uri, repo_path)
|
98
|
-
Berkshelf::Git.checkout(repo_path, sha_for_ref('nginx', '1.1.1'))
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'returns the ref for HEAD' do
|
102
|
-
rev = Berkshelf::Git.rev_parse(repo_path)
|
103
|
-
ref = sha_for_ref('nginx', '1.1.1')
|
104
|
-
|
105
|
-
expect(rev).to eql(ref)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe '::show_ref' do
|
110
|
-
let(:repo_path) { clone_path('nginx') }
|
111
|
-
let(:tags) { ['1.0.1'] }
|
112
|
-
let(:branches) { ['topic'] }
|
113
|
-
let!(:repo) {
|
114
|
-
origin_uri = git_origin_for('nginx', tags: tags, branches: branches)
|
115
|
-
git.clone(origin_uri, repo_path)
|
116
|
-
}
|
117
|
-
|
118
|
-
it 'returns the commit id for the given tag' do
|
119
|
-
show = git.show_ref(repo_path, '1.0.1')
|
120
|
-
ref = sha_for_ref('nginx', '1.0.1')
|
121
|
-
|
122
|
-
expect(show).to eq(ref)
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'returns the commit id for the given branch' do
|
126
|
-
show = git.show_ref(repo_path, 'topic')
|
127
|
-
ref = sha_for_ref('nginx', 'topic')
|
128
|
-
expect(show).to eq(ref)
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'with an ambiguous ref' do
|
132
|
-
let(:tags) { ['topic'] }
|
133
|
-
let(:branches) { ['topic'] }
|
134
|
-
|
135
|
-
it 'raises an error' do
|
136
|
-
expect {
|
137
|
-
git.show_ref(repo_path, 'topic')
|
138
|
-
}.to raise_error(Berkshelf::AmbiguousGitRef)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe '::revision_from_ref' do
|
144
|
-
let(:repo_path) { clone_path('nginx') }
|
145
|
-
let(:tags) { ['1.0.1'] }
|
146
|
-
let(:branches) { ['topic'] }
|
147
|
-
let!(:repo) {
|
148
|
-
origin_uri = git_origin_for('nginx', tags: tags, branches: branches)
|
149
|
-
git.clone(origin_uri, repo_path)
|
150
|
-
}
|
151
|
-
|
152
|
-
context 'with sha commit id' do
|
153
|
-
let(:revision) { sha_for_ref('nginx', '1.0.1') }
|
154
|
-
it 'returns the passed revision' do
|
155
|
-
rev = git.revision_from_ref(repo_path, revision)
|
156
|
-
expect(rev).to eq(revision)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context 'with tag' do
|
161
|
-
let(:revision) { sha_for_ref('nginx', '1.0.1') }
|
162
|
-
it 'returns the revision' do
|
163
|
-
rev = git.revision_from_ref(repo_path, '1.0.1')
|
164
|
-
expect(rev).to eq(revision)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'with branch' do
|
169
|
-
let(:revision) { sha_for_ref('nginx', 'topic') }
|
170
|
-
it 'returns the revision' do
|
171
|
-
rev = git.revision_from_ref(repo_path, 'topic')
|
172
|
-
expect(rev).to eq(revision)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context 'with an invalid ref' do
|
177
|
-
let(:ref) { 'foobar' }
|
178
|
-
it 'raises an error' do
|
179
|
-
expect {
|
180
|
-
git.revision_from_ref(repo_path, ref)
|
181
|
-
}.to raise_error(Berkshelf::InvalidGitRef)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
let(:readonly_uri) { 'git://github.com/reset/thor-foodcritic.git' }
|
187
|
-
let(:https_uri) { 'https://github.com/reset/solve.git' }
|
188
|
-
let(:http_uri) { 'http://github.com/reset/solve.git' }
|
189
|
-
let(:invalid_uri) { '/something/on/disk' }
|
190
|
-
|
191
|
-
describe '::validate_uri' do
|
192
|
-
context 'given a valid Git read-only URI' do
|
193
|
-
it 'returns true' do
|
194
|
-
expect(Berkshelf::Git.validate_uri(readonly_uri)).to be_true
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context 'given a valid Git HTTPS URI' do
|
199
|
-
it 'returns true' do
|
200
|
-
expect(Berkshelf::Git.validate_uri(https_uri)).to be_true
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'given a valid Github SSH URI' do
|
205
|
-
it 'returns true' do
|
206
|
-
expect(Berkshelf::Git.validate_uri('git@github.com:reset/solve.git')).to be_true
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context "given a valid SSH URI without an 'organization'" do
|
211
|
-
it 'returns true' do
|
212
|
-
expect(Berkshelf::Git.validate_uri('gituser@githost:solve.git')).to be_true
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context 'given a valid git+ssh URI without an username' do
|
217
|
-
it 'returns true' do
|
218
|
-
expect(Berkshelf::Git.validate_uri('git+ssh://host.com/repo')).to be_true
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
context 'given a valid git+ssh URI with an username' do
|
223
|
-
it 'returns true' do
|
224
|
-
expect(Berkshelf::Git.validate_uri('git+ssh://user@host.com/repo')).to be_true
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context 'given a valid URI with a dash in the hostname' do
|
229
|
-
it 'returns true' do
|
230
|
-
expect(Berkshelf::Git.validate_uri('git://user@git-host.com/repo')).to be_true
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context 'given a valid URI with host being a subdomain' do
|
235
|
-
it 'returns true' do
|
236
|
-
expect(Berkshelf::Git.validate_uri('git://user@git.host.com/repo')).to be_true
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
context 'given a valid git+ssh URI with home directory expansion' do
|
241
|
-
it 'returns true' do
|
242
|
-
expect(Berkshelf::Git.validate_uri('git+ssh://user@host.com/~repo')).to be_true
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
context 'given an invalid URI' do
|
247
|
-
it 'returns false' do
|
248
|
-
expect(Berkshelf::Git.validate_uri(invalid_uri)).to be_false
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
context 'given a HTTP URI' do
|
253
|
-
it 'returns true' do
|
254
|
-
expect(Berkshelf::Git.validate_uri(http_uri)).to be_true
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
context 'given an integer' do
|
259
|
-
it 'returns false' do
|
260
|
-
expect(Berkshelf::Git.validate_uri(123)).to be_false
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
describe '::validate_uri!' do
|
266
|
-
context 'given a valid Git read-only URI' do
|
267
|
-
it 'returns true' do
|
268
|
-
expect(Berkshelf::Git.validate_uri!(readonly_uri)).to be_true
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
context 'given a valid Git HTTPS URI' do
|
273
|
-
it 'returns true' do
|
274
|
-
expect(Berkshelf::Git.validate_uri!(https_uri)).to be_true
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
context 'given a valid Git SSH URI' do
|
279
|
-
it 'returns true' do
|
280
|
-
expect(Berkshelf::Git.validate_uri!('git@github.com:reset/solve.git')).to be_true
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
context "given a valid SSH URI without an 'organization'" do
|
285
|
-
it 'returns true' do
|
286
|
-
expect(Berkshelf::Git.validate_uri('gituser@githost:solve.git')).to be_true
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
context 'given an invalid URI' do
|
291
|
-
it 'raises InvalidGitURI' do
|
292
|
-
expect {
|
293
|
-
Berkshelf::Git.validate_uri!(invalid_uri)
|
294
|
-
}.to raise_error(Berkshelf::InvalidGitURI)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
context 'given a HTTP URI' do
|
299
|
-
it 'raises InvalidGitURI' do
|
300
|
-
expect(Berkshelf::Git.validate_uri!(http_uri)).to be_true
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
context 'given an integer' do
|
305
|
-
it 'raises InvalidGitURI' do
|
306
|
-
expect {
|
307
|
-
Berkshelf::Git.validate_uri!(123)
|
308
|
-
}.to raise_error(Berkshelf::InvalidGitURI)
|
309
|
-
end
|
310
|
-
end
|
311
|
-
end
|
312
|
-
end
|