berkshelf 1.4.6 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +1 -5
- data/CONTRIBUTING.md +3 -1
- data/Gemfile +11 -1
- data/README.md +16 -0
- data/Thorfile +3 -1
- data/berkshelf.gemspec +26 -38
- data/features/apply_command.feature +32 -0
- data/features/configure_command.feature +31 -0
- data/features/contingent_command.feature +5 -5
- data/features/default_locations.feature +2 -2
- data/features/groups_install.feature +19 -20
- data/features/info_command.feature +13 -13
- data/features/install_command.feature +86 -83
- data/features/json_formatter.feature +60 -23
- data/features/list_command.feature +5 -11
- data/features/lockfile.feature +286 -6
- data/features/open_command.feature +8 -4
- data/features/outdated_command.feature +8 -15
- data/features/package_command.feature +39 -0
- data/features/show_command.feature +8 -9
- data/features/step_definitions/chef_server_steps.rb +20 -2
- data/features/step_definitions/cli_steps.rb +10 -2
- data/features/step_definitions/configure_cli_steps.rb +7 -0
- data/features/step_definitions/filesystem_steps.rb +19 -14
- data/features/step_definitions/json_steps.rb +22 -5
- data/features/step_definitions/utility_steps.rb +13 -1
- data/features/support/env.rb +10 -23
- data/features/update_command.feature +105 -24
- data/features/upload_command.feature +0 -14
- data/features/vendor_install.feature +3 -3
- data/generator_files/Vagrantfile.erb +11 -11
- data/lib/berkshelf.rb +6 -5
- data/lib/berkshelf/berksfile.rb +267 -99
- data/lib/berkshelf/cli.rb +70 -34
- data/lib/berkshelf/cli_commands/test_command.rb +11 -0
- data/lib/berkshelf/community_rest.rb +1 -1
- data/lib/berkshelf/config.rb +19 -2
- data/lib/berkshelf/cookbook_source.rb +41 -12
- data/lib/berkshelf/cookbook_store.rb +8 -4
- data/lib/berkshelf/errors.rb +61 -29
- data/lib/berkshelf/formatters.rb +13 -19
- data/lib/berkshelf/formatters/human_readable.rb +8 -0
- data/lib/berkshelf/formatters/json.rb +12 -1
- data/lib/berkshelf/formatters/null.rb +23 -0
- data/lib/berkshelf/init_generator.rb +22 -11
- data/lib/berkshelf/location.rb +8 -10
- data/lib/berkshelf/locations/chef_api_location.rb +4 -5
- data/lib/berkshelf/locations/git_location.rb +14 -12
- data/lib/berkshelf/locations/path_location.rb +16 -1
- data/lib/berkshelf/locations/site_location.rb +1 -3
- data/lib/berkshelf/lockfile.rb +230 -33
- data/lib/berkshelf/resolver.rb +2 -1
- data/lib/berkshelf/ui.rb +4 -8
- data/lib/berkshelf/version.rb +1 -1
- data/lib/thor/monkies/shell.rb +2 -5
- data/spec/fixtures/cassettes/Berkshelf_Resolver/{ClassMethods/_initialize → _initialize}/adds_the_dependencies_of_the_source_as_sources.yml +0 -0
- data/spec/fixtures/cookbooks/example_cookbook/.gitignore +2 -0
- data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +26 -0
- data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +5 -0
- data/spec/fixtures/lockfiles/default.lock +11 -0
- data/spec/{config/knife.rb → knife.rb.sample} +2 -2
- data/spec/spec_helper.rb +15 -3
- data/spec/support/chef_api.rb +19 -5
- data/spec/support/chef_server.rb +4 -3
- data/spec/support/knife.rb +18 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +332 -235
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +40 -42
- data/spec/unit/berkshelf/chef/cookbook/chefignore_spec.rb +11 -15
- data/spec/unit/berkshelf/community_rest_spec.rb +16 -14
- data/spec/unit/berkshelf/config_spec.rb +36 -20
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +6 -10
- data/spec/unit/berkshelf/cookbook_source_spec.rb +244 -183
- data/spec/unit/berkshelf/cookbook_store_spec.rb +72 -76
- data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +2 -2
- data/spec/unit/berkshelf/downloader_spec.rb +137 -157
- data/spec/unit/berkshelf/errors_spec.rb +1 -1
- data/spec/unit/berkshelf/formatters/null_spec.rb +17 -0
- data/spec/unit/berkshelf/formatters_spec.rb +83 -90
- data/spec/unit/berkshelf/git_spec.rb +219 -207
- data/spec/unit/berkshelf/init_generator_spec.rb +73 -73
- data/spec/unit/berkshelf/location_spec.rb +143 -162
- data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +94 -89
- data/spec/unit/berkshelf/locations/git_location_spec.rb +75 -59
- data/spec/unit/berkshelf/locations/path_location_spec.rb +46 -30
- data/spec/unit/berkshelf/locations/site_location_spec.rb +4 -4
- data/spec/unit/berkshelf/lockfile_spec.rb +185 -1
- data/spec/unit/berkshelf/logger_spec.rb +6 -24
- data/spec/unit/berkshelf/mixin/logging_spec.rb +6 -8
- data/spec/unit/berkshelf/resolver_spec.rb +36 -38
- data/spec/unit/berkshelf/ui_spec.rb +9 -10
- data/spec/unit/berkshelf_spec.rb +41 -40
- data/spec/unit/chef/config_spec.rb +9 -11
- metadata +55 -203
- data/spec/config/berkshelf.pem +0 -27
- data/spec/config/validator.pem +0 -27
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Berkshelf::Formatters::Null do
|
4
|
+
before { Berkshelf.set_format(:null) }
|
5
|
+
|
6
|
+
[:install, :package, :foo, :bar, :bacon].each do |meth|
|
7
|
+
it "does not raise an error for :#{meth}" do
|
8
|
+
expect {
|
9
|
+
subject.send(meth)
|
10
|
+
}.to_not raise_error(Berkshelf::AbstractFunction)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns nil for :#{meth}" do
|
14
|
+
expect(subject.send(meth)).to be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,119 +1,112 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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)
|
9
19
|
|
10
|
-
|
11
|
-
Formatters.
|
20
|
+
expect(Berkshelf::Formatters.formatters).to have_key(format_id)
|
21
|
+
expect(Berkshelf::Formatters.formatters[format_id]).to eq(format_klass)
|
12
22
|
end
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
let(:format_klass) { Class.new }
|
18
|
-
|
19
|
-
describe "::register" do
|
20
|
-
it "adds the class of the includer to the list of registered formatters with the id" do
|
21
|
-
subject.register(format_id, format_klass)
|
22
|
-
|
23
|
-
subject.formatters.should have_key(format_id)
|
24
|
-
subject.formatters[format_id].should eql(format_klass)
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when given a string instead of a symbol as the ID" do
|
28
|
-
it "converts the string to a symbol and registers it" do
|
29
|
-
subject.register("rspec", format_klass)
|
30
|
-
|
31
|
-
subject.formatters.should have_key(:rspec)
|
32
|
-
subject.formatters[:rspec].should eql(format_klass)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when a formatter of the given ID has already been registered" do
|
37
|
-
it "raises an InternalError" do
|
38
|
-
subject.register(format_id, format_klass)
|
39
|
-
|
40
|
-
lambda {
|
41
|
-
subject.register(format_id, format_klass)
|
42
|
-
}.should raise_error(Berkshelf::InternalError)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
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)
|
46
27
|
|
47
|
-
|
48
|
-
|
49
|
-
subject.register(format_id, format_klass)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "returns a hash where formatter ID's are keys and values are formatter classes" do
|
53
|
-
subject.formatters.should be_a(Hash)
|
54
|
-
subject.formatters.should have(1).item
|
55
|
-
subject.formatters.keys.first.should eql(format_id)
|
56
|
-
subject.formatters.values.first.should eql(format_klass)
|
57
|
-
end
|
28
|
+
expect(Berkshelf::Formatters.formatters).to have_key(:rspec)
|
29
|
+
expect(Berkshelf::Formatters.formatters[:rspec]).to eq(format_klass)
|
58
30
|
end
|
31
|
+
end
|
59
32
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
it "returns the class constant of the given formatter ID" do
|
66
|
-
subject[format_id].should eql(format_klass)
|
67
|
-
end
|
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)
|
68
36
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
37
|
+
expect {
|
38
|
+
Berkshelf::Formatters.register(format_id, format_klass)
|
39
|
+
}.to raise_error(Berkshelf::InternalError)
|
74
40
|
end
|
75
41
|
end
|
76
42
|
end
|
77
43
|
|
78
|
-
describe
|
79
|
-
before
|
80
|
-
|
81
|
-
|
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)
|
82
54
|
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.get' do
|
58
|
+
before { Berkshelf::Formatters.register(format_id, format_klass) }
|
83
59
|
|
84
|
-
|
85
|
-
Formatters.
|
60
|
+
it 'returns the class constant of the given formatter ID' do
|
61
|
+
expect(Berkshelf::Formatters[format_id]).to eq(format_klass)
|
86
62
|
end
|
87
63
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
include Formatters::AbstractFormatter
|
92
|
-
end
|
64
|
+
context 'when the ID has not been registered' do
|
65
|
+
it 'returns nil' do
|
66
|
+
expect(Berkshelf::Formatters[:not_there]).to be_nil
|
93
67
|
end
|
68
|
+
end
|
69
|
+
end
|
94
70
|
|
95
|
-
|
96
|
-
|
97
|
-
|
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)
|
98
75
|
|
99
|
-
|
100
|
-
end
|
76
|
+
format_klass.register_formatter(:rspec)
|
101
77
|
end
|
102
78
|
end
|
103
79
|
|
80
|
+
|
81
|
+
|
104
82
|
subject do
|
105
|
-
Class.new
|
106
|
-
include Formatters::AbstractFormatter
|
107
|
-
end.new
|
83
|
+
Class.new { include Berkshelf::Formatters::AbstractFormatter }.new
|
108
84
|
end
|
109
85
|
|
110
|
-
it
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
86
|
+
it 'has abstract methods for all the messaging modes' do
|
87
|
+
expect {
|
88
|
+
subject.install('my_coobook','1.2.3','http://community')
|
89
|
+
}.to raise_error(Berkshelf::AbstractFunction)
|
90
|
+
|
91
|
+
expect {
|
92
|
+
subject.use('my_coobook','1.2.3')
|
93
|
+
}.to raise_error(Berkshelf::AbstractFunction)
|
94
|
+
|
95
|
+
expect {
|
96
|
+
subject.use('my_coobook','1.2.3','http://community')
|
97
|
+
}.to raise_error(Berkshelf::AbstractFunction)
|
98
|
+
|
99
|
+
expect {
|
100
|
+
subject.upload('my_coobook','1.2.3','http://chef_server')
|
101
|
+
}.to raise_error(Berkshelf::AbstractFunction)
|
102
|
+
|
103
|
+
expect {
|
104
|
+
subject.msg('something you to know')
|
105
|
+
}.to raise_error(Berkshelf::AbstractFunction)
|
106
|
+
|
107
|
+
expect {
|
108
|
+
subject.error('whoa this is bad')
|
109
|
+
}.to raise_error(Berkshelf::AbstractFunction)
|
117
110
|
end
|
118
111
|
end
|
119
112
|
end
|
@@ -1,299 +1,311 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Berkshelf::Git do
|
4
|
-
|
5
|
-
subject { Berkshelf::Git }
|
6
|
-
let(:git) { Berkshelf::Git }
|
4
|
+
let(:git) { Berkshelf::Git }
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
describe '.find_git' do
|
7
|
+
it 'finds git' do
|
8
|
+
expect(Berkshelf::Git.find_git).to_not be_nil
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
it 'raises an error if git cannot be not found' do
|
12
|
+
ENV.should_receive(:[]).with('PATH').and_return(String.new)
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
14
|
+
expect {
|
15
|
+
Berkshelf::Git.find_git
|
16
|
+
}.to raise_error(Berkshelf::GitNotFound)
|
20
17
|
end
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
20
|
+
describe '.clone' do
|
21
|
+
let(:target) { clone_target_for('nginx') }
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
it 'clones the repository to the target path' do
|
24
|
+
origin_uri = git_origin_for('nginx')
|
25
|
+
Berkshelf::Git.clone(origin_uri, target)
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
27
|
+
expect(target).to exist
|
28
|
+
expect(target).to be_directory
|
32
29
|
end
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
describe '.checkout' do
|
33
|
+
let(:repo_path) { clone_target_for('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
|
+
}
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
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)
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
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])
|
49
46
|
end
|
50
47
|
end
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
50
|
+
context 'with sha commit id' do
|
51
|
+
let(:ref) { git_sha_for_ref('nginx', '1.0.1') }
|
54
52
|
|
55
|
-
|
56
|
-
|
53
|
+
it_behaves_like 'able to checkout git ref'
|
54
|
+
end
|
57
55
|
|
58
|
-
|
59
|
-
|
56
|
+
context 'with tags' do
|
57
|
+
let(:ref) { '1.0.1' }
|
60
58
|
|
61
|
-
|
59
|
+
it_behaves_like 'able to checkout git ref'
|
62
60
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
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
|
+
run! "echo 'uncommitted change' >> content_file"
|
70
67
|
end
|
71
|
-
|
72
|
-
it_behaves_like 'able to checkout git ref'
|
73
68
|
end
|
69
|
+
|
70
|
+
it_behaves_like 'able to checkout git ref'
|
74
71
|
end
|
72
|
+
end
|
75
73
|
|
76
|
-
|
77
|
-
|
74
|
+
context 'with branches' do
|
75
|
+
let(:ref) { 'topic' }
|
78
76
|
|
79
|
-
|
77
|
+
it_behaves_like 'able to checkout git ref', 'origin/topic'
|
80
78
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
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
|
+
run! "echo 'uncommitted change' >> content_file"
|
88
85
|
end
|
89
|
-
|
90
|
-
it_behaves_like 'able to checkout git ref', 'origin/topic'
|
91
86
|
end
|
87
|
+
|
88
|
+
it_behaves_like 'able to checkout git ref', 'origin/topic'
|
92
89
|
end
|
93
90
|
end
|
91
|
+
end
|
94
92
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
93
|
+
describe '.rev_parse' do
|
94
|
+
let(:repo_path) { clone_target_for('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, git_sha_for_ref('nginx', '1.1.1'))
|
99
|
+
end
|
102
100
|
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
it 'returns the ref for HEAD' do
|
102
|
+
rev = Berkshelf::Git.rev_parse(repo_path)
|
103
|
+
ref = git_sha_for_ref('nginx', '1.1.1')
|
104
|
+
|
105
|
+
expect(rev).to eql(ref)
|
106
106
|
end
|
107
|
+
end
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
109
|
+
describe '.show_ref' do
|
110
|
+
let(:repo_path) { clone_target_for('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
|
+
}
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
it 'returns the commit id for the given tag' do
|
119
|
+
show = git.show_ref(repo_path, '1.0.1')
|
120
|
+
ref = git_sha_for_ref('nginx', '1.0.1')
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
end
|
122
|
+
expect(show).to eq(ref)
|
123
|
+
end
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
it 'returns the commit id for the given branch' do
|
126
|
+
show = git.show_ref(repo_path, 'topic')
|
127
|
+
ref = git_sha_for_ref('nginx', 'topic')
|
128
|
+
expect(show).to eq(ref)
|
129
|
+
end
|
128
130
|
|
129
|
-
|
130
|
-
|
131
|
-
|
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)
|
132
139
|
end
|
133
140
|
end
|
141
|
+
end
|
134
142
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
143
|
+
describe '.revision_from_ref' do
|
144
|
+
let(:repo_path) { clone_target_for('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) { git_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)
|
149
157
|
end
|
158
|
+
end
|
150
159
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
160
|
+
context 'with tag' do
|
161
|
+
let(:revision) { git_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)
|
156
165
|
end
|
166
|
+
end
|
157
167
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
168
|
+
context 'with branch' do
|
169
|
+
let(:revision) { git_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)
|
163
173
|
end
|
174
|
+
end
|
164
175
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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)
|
170
182
|
end
|
171
183
|
end
|
184
|
+
end
|
172
185
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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' }
|
177
190
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
end
|
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
|
183
195
|
end
|
196
|
+
end
|
184
197
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
end
|
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
|
189
201
|
end
|
202
|
+
end
|
190
203
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
end
|
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
|
195
207
|
end
|
208
|
+
end
|
196
209
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
end
|
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
|
201
213
|
end
|
214
|
+
end
|
202
215
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
end
|
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
|
207
219
|
end
|
220
|
+
end
|
208
221
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
end
|
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
|
213
225
|
end
|
226
|
+
end
|
214
227
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
end
|
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
|
219
231
|
end
|
232
|
+
end
|
220
233
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
end
|
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
|
225
237
|
end
|
238
|
+
end
|
226
239
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
end
|
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
|
231
243
|
end
|
244
|
+
end
|
232
245
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
end
|
246
|
+
context 'given an invalid URI' do
|
247
|
+
it 'returns false' do
|
248
|
+
expect(Berkshelf::Git.validate_uri(invalid_uri)).to be_false
|
237
249
|
end
|
250
|
+
end
|
238
251
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
end
|
252
|
+
context 'given a HTTP URI' do
|
253
|
+
it 'returns true' do
|
254
|
+
expect(Berkshelf::Git.validate_uri(http_uri)).to be_true
|
243
255
|
end
|
256
|
+
end
|
244
257
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
end
|
258
|
+
context 'given an integer' do
|
259
|
+
it 'returns false' do
|
260
|
+
expect(Berkshelf::Git.validate_uri(123)).to be_false
|
249
261
|
end
|
250
262
|
end
|
263
|
+
end
|
251
264
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
end
|
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
|
257
269
|
end
|
270
|
+
end
|
258
271
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
end
|
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
|
263
275
|
end
|
276
|
+
end
|
264
277
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
end
|
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
|
269
281
|
end
|
282
|
+
end
|
270
283
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
end
|
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
|
275
287
|
end
|
288
|
+
end
|
276
289
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
end
|
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)
|
283
295
|
end
|
296
|
+
end
|
284
297
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
end
|
298
|
+
context 'given a HTTP URI' do
|
299
|
+
it 'raises InvalidGitURI' do
|
300
|
+
expect(Berkshelf::Git.validate_uri!(http_uri)).to be_true
|
289
301
|
end
|
302
|
+
end
|
290
303
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
end
|
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)
|
297
309
|
end
|
298
310
|
end
|
299
311
|
end
|