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
@@ -1,138 +1,143 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Berkshelf::ChefAPILocation, :chef_server do
|
4
|
-
let(:test_chef_api) {
|
5
|
-
let(:node_name) {
|
6
|
-
let(:client_key) { fixtures_path.join(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
client_key: client_key
|
22
|
-
)
|
23
|
-
end
|
4
|
+
let(:test_chef_api) { 'https://chefserver:8081' }
|
5
|
+
let(:node_name) { 'reset' }
|
6
|
+
let(:client_key) { fixtures_path.join('reset.pem').to_s }
|
7
|
+
|
8
|
+
let(:valid_uri) { test_chef_api }
|
9
|
+
let(:invalid_uri) { 'notauri' }
|
10
|
+
let(:constraint) { double('constraint') }
|
11
|
+
|
12
|
+
describe '.initialize' do
|
13
|
+
subject do
|
14
|
+
Berkshelf::ChefAPILocation.new('nginx',
|
15
|
+
constraint,
|
16
|
+
chef_api: test_chef_api,
|
17
|
+
node_name: node_name,
|
18
|
+
client_key: client_key
|
19
|
+
)
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
it 'sets the uri attribute to the value of the chef_api option' do
|
23
|
+
expect(subject.uri).to eq(test_chef_api)
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
it 'sets the node_name attribute to the value of the node_name option' do
|
27
|
+
expect(subject.node_name).to eq(node_name)
|
28
|
+
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
it 'sets the client_key attribute to the value of the client_key option' do
|
31
|
+
expect(subject.client_key).to eq(client_key)
|
32
|
+
end
|
36
33
|
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
it 'sets the downloaded status to false' do
|
35
|
+
expect(subject).to_not be_downloaded
|
36
|
+
end
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
38
|
+
context 'when an invalid Chef API URI is given' do
|
39
|
+
it 'raises Berkshelf::InvalidChefAPILocation' do
|
40
|
+
expect {
|
41
|
+
Berkshelf::ChefAPILocation.new("nginx", constraint, chef_api: invalid_uri, node_name: node_name, client_key: client_key)
|
42
|
+
}.to raise_error(Berkshelf::InvalidChefAPILocation, "'notauri' is not a valid Chef API URI.")
|
47
43
|
end
|
44
|
+
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
46
|
+
context 'when no option for node_name is supplied' do
|
47
|
+
it 'raises Berkshelf::InvalidChefAPILocation' do
|
48
|
+
expect {
|
49
|
+
Berkshelf::ChefAPILocation.new('nginx', constraint, chef_api: invalid_uri, client_key: client_key)
|
50
|
+
}.to raise_error(Berkshelf::InvalidChefAPILocation)
|
55
51
|
end
|
52
|
+
end
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
54
|
+
context 'when no option for client_key is supplied' do
|
55
|
+
it 'raises Berkshelf::InvalidChefAPILocation' do
|
56
|
+
expect {
|
57
|
+
Berkshelf::ChefAPILocation.new('nginx', constraint, chef_api: invalid_uri, node_name: node_name)
|
58
|
+
}.to raise_error(Berkshelf::InvalidChefAPILocation)
|
63
59
|
end
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
62
|
+
context 'given the symbol :config for the value of chef_api:' do
|
63
|
+
subject do
|
64
|
+
Berkshelf::ChefAPILocation.new('nginx', constraint, chef_api: :config)
|
65
|
+
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
it 'uses the value of Berkshelf::Chef.instance.chef.chef_server_url for the uri attribute' do
|
68
|
+
expect(subject.uri).to eq(Berkshelf::Config.instance.chef.chef_server_url)
|
69
|
+
end
|
71
70
|
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
it 'uses the value of Berkshelf::Chef.instance.chef.node_name for the node_name attribute' do
|
72
|
+
expect(subject.node_name).to eq(Berkshelf::Config.instance.chef.node_name)
|
73
|
+
end
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
end
|
75
|
+
it 'uses the value of Berkshelf::Chef.instance.chef.client_key for the client_key attribute' do
|
76
|
+
expect(subject.client_key).to eq(Berkshelf::Config.instance.chef.client_key)
|
79
77
|
end
|
80
78
|
end
|
79
|
+
end
|
81
80
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
describe '.validate_uri' do
|
82
|
+
it 'returns false if the given URI is invalid' do
|
83
|
+
expect(Berkshelf::ChefAPILocation.validate_uri(invalid_uri)).to be_false
|
84
|
+
end
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
end
|
86
|
+
it 'returns true if the given URI is valid' do
|
87
|
+
expect(Berkshelf::ChefAPILocation.validate_uri(valid_uri)).to be_true
|
90
88
|
end
|
89
|
+
end
|
91
90
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
91
|
+
describe '.validate_uri!' do
|
92
|
+
it 'raises Berkshelf::InvalidChefAPILocation if the given URI is invalid' do
|
93
|
+
expect {
|
94
|
+
Berkshelf::ChefAPILocation.validate_uri!(invalid_uri)
|
95
|
+
}.to raise_error(Berkshelf::InvalidChefAPILocation, "'notauri' is not a valid Chef API URI.")
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
end
|
98
|
+
it 'returns true if the given URI is valid' do
|
99
|
+
expect(Berkshelf::ChefAPILocation.validate_uri!(valid_uri)).to be_true
|
102
100
|
end
|
103
101
|
end
|
104
102
|
|
103
|
+
|
104
|
+
|
105
105
|
subject do
|
106
|
-
|
106
|
+
Berkshelf::ChefAPILocation.new('nginx',
|
107
|
+
nil,
|
108
|
+
chef_api: test_chef_api,
|
109
|
+
node_name: node_name,
|
110
|
+
client_key: client_key
|
111
|
+
)
|
107
112
|
end
|
108
113
|
|
109
|
-
describe
|
114
|
+
describe '#target_cookbook' do
|
110
115
|
let(:cookbook_version) { double('cookbook_version') }
|
111
116
|
|
112
|
-
context
|
117
|
+
context 'when a version constraint is present' do
|
113
118
|
let(:constraint) { double('constraint') }
|
114
119
|
|
115
|
-
it
|
120
|
+
it 'returns the best solution for the constraint' do
|
116
121
|
subject.stub(:version_constraint).and_return(constraint)
|
117
122
|
subject.stub_chain(:conn, :cookbook, :satisfy).with(subject.name, constraint).and_return(cookbook_version)
|
118
|
-
|
119
|
-
subject.target_cookbook.
|
123
|
+
|
124
|
+
expect(subject.target_cookbook).to eq(cookbook_version)
|
120
125
|
end
|
121
126
|
end
|
122
127
|
|
123
|
-
context
|
124
|
-
it
|
128
|
+
context 'when a version constraint is not present' do
|
129
|
+
it 'returns the latest version of the cookbook' do
|
125
130
|
subject.stub(:version_constraint).and_return(nil)
|
126
131
|
subject.stub_chain(:conn, :cookbook, :latest_version).with(subject.name).and_return(cookbook_version)
|
127
132
|
|
128
|
-
subject.target_cookbook.
|
133
|
+
expect(subject.target_cookbook).to eq(cookbook_version)
|
129
134
|
end
|
130
135
|
end
|
131
136
|
end
|
132
137
|
|
133
|
-
describe
|
134
|
-
it
|
135
|
-
subject.to_s.
|
138
|
+
describe '#to_s' do
|
139
|
+
it 'returns a string containing the location key and the Chef API URI' do
|
140
|
+
expect(subject.to_s).to eq("chef_api: '#{test_chef_api}'")
|
136
141
|
end
|
137
142
|
end
|
138
143
|
end
|
@@ -3,130 +3,146 @@ require 'spec_helper'
|
|
3
3
|
describe Berkshelf::GitLocation do
|
4
4
|
let(:complacent_constraint) { double('comp-vconstraint', satisfies?: true) }
|
5
5
|
|
6
|
-
describe
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
lambda {
|
12
|
-
subject.new("nginx", complacent_constraint, git: "/something/on/disk")
|
13
|
-
}.should raise_error(Berkshelf::InvalidGitURI)
|
14
|
-
end
|
6
|
+
describe '.initialize' do
|
7
|
+
it 'raises InvalidGitURI if given an invalid Git URI for options[:git]' do
|
8
|
+
expect {
|
9
|
+
Berkshelf::GitLocation.new('berkshelf-cookbook-fixture', complacent_constraint, git: '/something/on/disk')
|
10
|
+
}.to raise_error(Berkshelf::InvalidGitURI)
|
15
11
|
end
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
14
|
+
describe '.tmpdir' do
|
15
|
+
it 'creates a temporary directory within the Berkshelf temporary directory' do
|
16
|
+
expect(Berkshelf::GitLocation.tmpdir).to include(Berkshelf.tmp_dir)
|
21
17
|
end
|
22
18
|
end
|
23
19
|
|
24
|
-
subject { described_class.new("nginx", complacent_constraint, git: "git://github.com/opscode-cookbooks/nginx.git") }
|
25
20
|
|
26
|
-
|
27
|
-
|
21
|
+
|
22
|
+
subject { Berkshelf::GitLocation.new('berkshelf-cookbook-fixture', complacent_constraint, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
|
23
|
+
|
24
|
+
describe '#download' do
|
25
|
+
context 'when a local revision is present' do
|
28
26
|
let(:cached) { double('cached') }
|
29
27
|
|
30
28
|
before do
|
29
|
+
Berkshelf::Git.stub(:rev_parse).and_return('abcd1234')
|
31
30
|
Berkshelf::GitLocation.any_instance.stub(:cached?).and_return(true)
|
32
31
|
Berkshelf::GitLocation.any_instance.stub(:validate_cached).with(cached).and_return(cached)
|
33
32
|
Berkshelf::CachedCookbook.stub(:from_store_path).with(any_args()).and_return(cached)
|
34
33
|
end
|
35
34
|
|
36
|
-
it
|
35
|
+
it 'returns the cached cookbook' do
|
37
36
|
expect(subject.download(tmp_path)).to eq(cached)
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
it
|
42
|
-
subject.download(tmp_path).
|
40
|
+
it 'returns an instance of Berkshelf::CachedCookbook' do
|
41
|
+
expect(subject.download(tmp_path)).to be_a(Berkshelf::CachedCookbook)
|
43
42
|
end
|
44
43
|
|
45
|
-
it
|
44
|
+
it 'downloads the cookbook to the given destination' do
|
46
45
|
cached_cookbook = subject.download(tmp_path)
|
47
|
-
|
46
|
+
ref = subject.ref
|
48
47
|
|
49
|
-
tmp_path.
|
50
|
-
directory "#{cached_cookbook.cookbook_name}-#{
|
51
|
-
file
|
48
|
+
expect(tmp_path).to have_structure {
|
49
|
+
directory "#{cached_cookbook.cookbook_name}-#{ref}" do
|
50
|
+
file 'metadata.rb'
|
52
51
|
end
|
53
52
|
}
|
54
53
|
end
|
55
54
|
|
56
|
-
it
|
55
|
+
it 'sets the downloaded status to true' do
|
57
56
|
subject.download(tmp_path)
|
58
|
-
|
59
|
-
subject.should be_downloaded
|
57
|
+
expect(subject).to be_downloaded
|
60
58
|
end
|
61
59
|
|
62
|
-
context
|
63
|
-
subject {
|
60
|
+
context 'given no ref/branch/tag options is given' do
|
61
|
+
subject { Berkshelf::GitLocation.new('berkshelf-cookbook-fixture', complacent_constraint, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
|
64
62
|
|
65
|
-
it
|
63
|
+
it 'sets the branch attribute to the HEAD revision of the cloned repo' do
|
66
64
|
subject.download(tmp_path)
|
67
|
-
|
68
|
-
subject.branch.should_not be_nil
|
65
|
+
expect(subject.branch).to_not be_nil
|
69
66
|
end
|
70
67
|
end
|
71
68
|
|
72
|
-
context
|
73
|
-
subject {
|
69
|
+
context 'given a git repo that does not exist' do
|
70
|
+
subject { Berkshelf::GitLocation.new('doesnot_exist', complacent_constraint, git: 'git://github.com/RiotGames/thisrepo_does_not_exist.git') }
|
74
71
|
|
75
|
-
it
|
72
|
+
it 'raises a GitError' do
|
76
73
|
Berkshelf::Git.stub(:git).and_raise(Berkshelf::GitError.new(''))
|
77
|
-
|
74
|
+
expect {
|
78
75
|
subject.download(tmp_path)
|
79
|
-
}.
|
76
|
+
}.to raise_error(Berkshelf::GitError)
|
80
77
|
end
|
81
78
|
end
|
82
79
|
|
83
|
-
context
|
80
|
+
context 'given a git repo that does not contain a cookbook' do
|
84
81
|
let(:fake_remote) { local_git_origin_path_for('not_a_cookbook') }
|
85
|
-
subject {
|
82
|
+
subject { Berkshelf::GitLocation.new('doesnot_exist', complacent_constraint, git: "file://#{fake_remote}.git") }
|
86
83
|
|
87
|
-
it
|
84
|
+
it 'raises a CookbookNotFound error' do
|
88
85
|
subject.stub(:clone).and_return {
|
89
86
|
FileUtils.mkdir_p(fake_remote)
|
90
|
-
Dir.chdir(fake_remote) { |dir| `git init; echo hi > README; git add README; git commit README -m
|
87
|
+
Dir.chdir(fake_remote) { |dir| `git init; echo hi > README; git add README; git commit README -m 'README'`; dir }
|
91
88
|
}
|
92
89
|
|
93
|
-
|
90
|
+
expect {
|
94
91
|
subject.download(tmp_path)
|
95
|
-
}.
|
92
|
+
}.to raise_error(Berkshelf::CookbookNotFound)
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
99
|
-
context
|
96
|
+
context 'given the content at the Git repo does not satisfy the version constraint' do
|
100
97
|
subject do
|
101
|
-
|
98
|
+
Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
|
102
99
|
double('constraint', satisfies?: false),
|
103
|
-
git:
|
100
|
+
git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git'
|
104
101
|
)
|
105
102
|
end
|
106
103
|
|
107
|
-
it
|
108
|
-
|
104
|
+
it 'raises a CookbookValidationFailure error' do
|
105
|
+
expect {
|
109
106
|
subject.download(tmp_path)
|
110
|
-
}.
|
107
|
+
}.to raise_error(Berkshelf::CookbookValidationFailure)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'given a value for tag' do
|
112
|
+
let(:tag) { '1.0.0' }
|
113
|
+
|
114
|
+
subject do
|
115
|
+
Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
|
116
|
+
complacent_constraint,
|
117
|
+
git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git',
|
118
|
+
tag: tag
|
119
|
+
)
|
120
|
+
end
|
121
|
+
let(:cached) { subject.download(tmp_path) }
|
122
|
+
let(:sha) { subject.ref }
|
123
|
+
let(:expected_path) { tmp_path.join("#{cached.cookbook_name}-#{sha}") }
|
124
|
+
|
125
|
+
it 'returns a cached cookbook with a path that contains the ref' do
|
126
|
+
expect(cached.path).to eq(expected_path)
|
111
127
|
end
|
112
128
|
end
|
113
129
|
|
114
|
-
context
|
115
|
-
let(:
|
130
|
+
context 'give a value for branch' do
|
131
|
+
let(:branch) { 'master' }
|
116
132
|
|
117
133
|
subject do
|
118
|
-
|
134
|
+
Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
|
119
135
|
complacent_constraint,
|
120
|
-
git:
|
121
|
-
|
136
|
+
git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git',
|
137
|
+
branch: branch
|
122
138
|
)
|
123
139
|
end
|
124
|
-
let(:
|
125
|
-
let(:
|
126
|
-
let(:expected_path) { tmp_path.join("#{
|
140
|
+
let(:cached) { subject.download(tmp_path) }
|
141
|
+
let(:sha) { subject.ref }
|
142
|
+
let(:expected_path) { tmp_path.join("#{cached.cookbook_name}-#{sha}") }
|
127
143
|
|
128
|
-
it
|
129
|
-
|
144
|
+
it 'returns a cached cookbook with a path that contains the ref' do
|
145
|
+
expect(cached.path).to eq(expected_path)
|
130
146
|
end
|
131
147
|
end
|
132
148
|
end
|
@@ -2,58 +2,74 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Berkshelf::PathLocation do
|
4
4
|
let(:complacent_constraint) { double('comp-vconstraint', satisfies?: true) }
|
5
|
-
let(:path) { fixtures_path.join(
|
5
|
+
let(:path) { fixtures_path.join('cookbooks', 'example_cookbook').to_s }
|
6
6
|
|
7
|
-
describe
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
obj.path.should eql(path)
|
13
|
-
end
|
7
|
+
describe '.new' do
|
8
|
+
it 'assigns the value of :path to @path' do
|
9
|
+
location = Berkshelf::PathLocation.new('nginx', complacent_constraint, path: path)
|
10
|
+
expect(location.path).to eq(path)
|
14
11
|
end
|
15
12
|
end
|
16
13
|
|
17
|
-
subject { described_class.new("nginx", complacent_constraint, path: path) }
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
|
16
|
+
subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: path) }
|
17
|
+
|
18
|
+
describe '#download' do
|
19
|
+
it 'returns an instance of CachedCookbook' do
|
20
|
+
expect(subject.download(tmp_path)).to be_a(Berkshelf::CachedCookbook)
|
22
21
|
end
|
23
22
|
|
24
|
-
it
|
23
|
+
it 'sets the downloaded status to true' do
|
25
24
|
subject.download(tmp_path)
|
26
|
-
|
27
|
-
subject.should be_downloaded
|
25
|
+
expect(subject).to be_downloaded
|
28
26
|
end
|
29
27
|
|
30
|
-
context
|
31
|
-
subject {
|
28
|
+
context 'given a path that does not exist' do
|
29
|
+
subject { Berkshelf::PathLocation.new('doesnot_exist', complacent_constraint, path: tmp_path.join('doesntexist_noway')) }
|
32
30
|
|
33
|
-
it
|
34
|
-
|
31
|
+
it 'raises a CookbookNotFound error' do
|
32
|
+
expect {
|
35
33
|
subject.download(tmp_path)
|
36
|
-
}.
|
34
|
+
}.to raise_error(Berkshelf::CookbookNotFound)
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
|
-
context
|
41
|
-
subject {
|
38
|
+
context 'given a path that does not contain a cookbook' do
|
39
|
+
subject { Berkshelf::PathLocation.new('doesnot_exist', complacent_constraint, path: fixtures_path) }
|
42
40
|
|
43
|
-
it
|
44
|
-
|
41
|
+
it 'raises a CookbookNotFound error' do
|
42
|
+
expect {
|
45
43
|
subject.download(tmp_path)
|
46
|
-
}.
|
44
|
+
}.to raise_error(Berkshelf::CookbookNotFound)
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
|
-
context
|
51
|
-
subject {
|
48
|
+
context 'given the content at path does not satisfy the version constraint' do
|
49
|
+
subject { Berkshelf::PathLocation.new('nginx', double('constraint', satisfies?: false), path: path) }
|
52
50
|
|
53
|
-
it
|
54
|
-
|
51
|
+
it 'raises a CookbookValidationFailure error' do
|
52
|
+
expect {
|
55
53
|
subject.download(double('path'))
|
56
|
-
}.
|
54
|
+
}.to raise_error(Berkshelf::CookbookValidationFailure)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#to_s' do
|
60
|
+
context 'for a remote path' do
|
61
|
+
subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: path) }
|
62
|
+
|
63
|
+
it 'includes the path information' do
|
64
|
+
expect(subject.to_s).to match(/path\:.+example_cookbook/)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'for a store path' do
|
69
|
+
subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: File.join(Berkshelf.berkshelf_path, 'cookbooks/example_cookbook')) }
|
70
|
+
|
71
|
+
it 'does not include the path information' do
|
72
|
+
expect(subject.to_s).to_not match(/path\:.+/)
|
57
73
|
end
|
58
74
|
end
|
59
75
|
end
|