berkshelf 2.0.18 → 3.0.0.beta1
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.
- data/.ruby-version +1 -1
- data/.travis.yml +4 -1
- data/CHANGELOG.md +2 -26
- data/Gemfile +12 -2
- data/README.md +9 -1
- data/berkshelf.gemspec +9 -18
- data/bin/berks +3 -13
- data/features/apply_command.feature +11 -9
- data/features/berksfile.feature +8 -10
- data/features/config.feature +1 -2
- data/features/configure_command.feature +13 -14
- data/features/contingent_command.feature +13 -1
- data/features/cookbook_command.feature +2 -4
- data/features/groups_install.feature +10 -2
- data/features/help.feature +1 -1
- data/features/init_command.feature +5 -7
- data/features/install_command.feature +157 -228
- data/features/json_formatter.feature +27 -15
- data/features/licenses.feature +18 -12
- data/features/list_command.feature +6 -1
- data/features/lockfile.feature +116 -72
- data/features/outdated_command.feature +3 -47
- data/features/package_command.feature +10 -7
- data/features/shelf/show.feature +2 -2
- data/features/shelf/uninstall.feature +2 -2
- data/features/show_command.feature +10 -3
- data/features/step_definitions/chef/config_steps.rb +12 -0
- data/features/step_definitions/chef_server_steps.rb +16 -16
- data/features/step_definitions/cli_steps.rb +3 -79
- data/features/step_definitions/config_steps.rb +43 -0
- data/features/step_definitions/environment_steps.rb +7 -0
- data/features/step_definitions/filesystem_steps.rb +12 -57
- data/features/step_definitions/gem_steps.rb +1 -2
- data/features/step_definitions/json_steps.rb +3 -1
- data/features/step_definitions/lockfile_steps.rb +4 -0
- data/features/step_definitions/utility_steps.rb +0 -19
- data/features/support/aruba.rb +12 -0
- data/features/support/env.rb +52 -57
- data/features/update_command.feature +37 -23
- data/features/upload_command.feature +96 -160
- data/generator_files/Berksfile.erb +2 -1
- data/generator_files/Vagrantfile.erb +3 -0
- data/generator_files/default_test.rb.erb +1 -1
- data/generator_files/helpers.rb.erb +1 -1
- data/lib/berkshelf.rb +43 -24
- data/lib/berkshelf/api_client.rb +67 -0
- data/lib/berkshelf/api_client/remote_cookbook.rb +42 -0
- data/lib/berkshelf/berksfile.rb +232 -420
- data/lib/berkshelf/cached_cookbook.rb +22 -10
- data/lib/berkshelf/chef/config.rb +1 -0
- data/lib/berkshelf/cli.rb +66 -68
- data/lib/berkshelf/commands/shelf.rb +1 -1
- data/lib/berkshelf/community_rest.rb +10 -17
- data/lib/berkshelf/config.rb +23 -27
- data/lib/berkshelf/cookbook_generator.rb +3 -4
- data/lib/berkshelf/cookbook_store.rb +74 -17
- data/lib/berkshelf/core_ext/file.rb +2 -2
- data/lib/berkshelf/core_ext/pathname.rb +7 -5
- data/lib/berkshelf/{cookbook_source.rb → dependency.rb} +47 -67
- data/lib/berkshelf/downloader.rb +49 -106
- data/lib/berkshelf/errors.rb +64 -71
- data/lib/berkshelf/formatters.rb +11 -9
- data/lib/berkshelf/formatters/human_readable.rb +9 -9
- data/lib/berkshelf/formatters/json.rb +14 -4
- data/lib/berkshelf/init_generator.rb +3 -3
- data/lib/berkshelf/installer.rb +136 -0
- data/lib/berkshelf/location.rb +91 -131
- data/lib/berkshelf/locations/git_location.rb +9 -11
- data/lib/berkshelf/locations/github_location.rb +1 -1
- data/lib/berkshelf/locations/path_location.rb +10 -27
- data/lib/berkshelf/lockfile.rb +92 -70
- data/lib/berkshelf/logger.rb +4 -7
- data/lib/berkshelf/mixin/config.rb +21 -4
- data/lib/berkshelf/resolver.rb +60 -150
- data/lib/berkshelf/resolver/graph.rb +44 -0
- data/lib/berkshelf/source.rb +55 -0
- data/lib/berkshelf/source_uri.rb +38 -0
- data/lib/berkshelf/version.rb +1 -1
- data/spec/config/knife.rb +1 -1
- data/spec/fixtures/cassettes/Berkshelf_Resolver/_initialize/adds_the_dependencies_of_the_dependency_as_dependencies.yml +3694 -0
- data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +1 -1
- data/spec/fixtures/lockfiles/default.lock +1 -1
- data/spec/spec_helper.rb +20 -121
- data/spec/support/chef_api.rb +3 -4
- data/spec/support/chef_server.rb +20 -11
- data/spec/support/git.rb +127 -0
- data/spec/support/kitchen.rb +12 -0
- data/spec/support/path_helpers.rb +69 -0
- data/spec/unit/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
- data/spec/unit/berkshelf/api_client_spec.rb +57 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +206 -324
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +73 -38
- data/spec/unit/berkshelf/community_rest_spec.rb +30 -71
- data/spec/unit/berkshelf/config_spec.rb +3 -14
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +1 -2
- data/spec/unit/berkshelf/cookbook_store_spec.rb +12 -7
- data/spec/unit/berkshelf/dependency_spec.rb +285 -0
- data/spec/unit/berkshelf/downloader_spec.rb +4 -183
- data/spec/unit/berkshelf/formatters/null_spec.rb +1 -1
- data/spec/unit/berkshelf/formatters_spec.rb +4 -2
- data/spec/unit/berkshelf/git_spec.rb +15 -15
- data/spec/unit/berkshelf/installer_spec.rb +39 -0
- data/spec/unit/berkshelf/location_spec.rb +87 -114
- data/spec/unit/berkshelf/locations/git_location_spec.rb +41 -53
- data/spec/unit/berkshelf/locations/path_location_spec.rb +13 -23
- data/spec/unit/berkshelf/lockfile_spec.rb +38 -40
- data/spec/unit/berkshelf/resolver/graph_spec.rb +44 -0
- data/spec/unit/berkshelf/resolver_spec.rb +34 -83
- data/spec/unit/berkshelf/source_spec.rb +23 -0
- data/spec/unit/berkshelf/source_uri_spec.rb +29 -0
- metadata +149 -188
- checksums.yaml +0 -7
- data/features/default_locations.feature +0 -127
- data/features/step_definitions/berksfile_steps.rb +0 -8
- data/features/step_definitions/configure_cli_steps.rb +0 -19
- data/features/vendor_install.feature +0 -19
- data/lib/berkshelf/core_ext/openuri.rb +0 -36
- data/lib/berkshelf/core_ext/rbzip2.rb +0 -8
- data/lib/berkshelf/locations/chef_api_location.rb +0 -228
- data/lib/berkshelf/locations/site_location.rb +0 -92
- data/lib/berkshelf/test.rb +0 -35
- data/spec/knife.rb.sample +0 -12
- data/spec/support/test_generators.rb +0 -27
- data/spec/unit/berkshelf/cli_spec.rb +0 -16
- data/spec/unit/berkshelf/cookbook_source_spec.rb +0 -358
- data/spec/unit/berkshelf/core_ext/pathname_spec.rb +0 -46
- data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +0 -139
- data/spec/unit/berkshelf/locations/site_location_spec.rb +0 -19
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Berkshelf::GitLocation do
|
|
4
|
-
let(:
|
|
4
|
+
let(:constraint) { double('comp-vconstraint', satisfies?: true) }
|
|
5
|
+
let(:dependency) { double('dep', name: "berkshelf-cookbook-fixture", version_constraint: constraint) }
|
|
5
6
|
|
|
6
|
-
describe
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
describe "ClassMethods" do
|
|
8
|
+
describe "::new" do
|
|
9
|
+
it 'raises InvalidGitURI if given an invalid Git URI for options[:git]' do
|
|
10
|
+
expect {
|
|
11
|
+
described_class.new(dependency, git: '/something/on/disk')
|
|
12
|
+
}.to raise_error(Berkshelf::InvalidGitURI)
|
|
13
|
+
end
|
|
11
14
|
end
|
|
12
|
-
end
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
describe "::tmpdir" do
|
|
17
|
+
it 'creates a temporary directory within the Berkshelf temporary directory' do
|
|
18
|
+
expect(described_class.tmpdir).to include(Berkshelf.tmp_dir)
|
|
19
|
+
end
|
|
17
20
|
end
|
|
18
21
|
end
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
subject { Berkshelf::GitLocation.new('berkshelf-cookbook-fixture', complacent_constraint, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
|
|
23
|
+
let(:storage_path) { Berkshelf::CookbookStore.instance.storage_path }
|
|
24
|
+
subject { described_class.new(dependency, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
|
|
23
25
|
|
|
24
26
|
describe '#download' do
|
|
25
27
|
context 'when a local revision is present' do
|
|
@@ -27,25 +29,25 @@ describe Berkshelf::GitLocation do
|
|
|
27
29
|
|
|
28
30
|
before do
|
|
29
31
|
Berkshelf::Git.stub(:rev_parse).and_return('abcd1234')
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
described_class.any_instance.stub(:cached?).and_return(true)
|
|
33
|
+
described_class.any_instance.stub(:validate_cached).with(cached).and_return(cached)
|
|
32
34
|
Berkshelf::CachedCookbook.stub(:from_store_path).with(any_args()).and_return(cached)
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
it 'returns the cached cookbook' do
|
|
36
|
-
expect(subject.download
|
|
38
|
+
expect(subject.download).to eq(cached)
|
|
37
39
|
end
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
it 'returns an instance of Berkshelf::CachedCookbook' do
|
|
41
|
-
expect(subject.download
|
|
43
|
+
expect(subject.download).to be_a(Berkshelf::CachedCookbook)
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
it 'downloads the cookbook to the given destination' do
|
|
45
|
-
cached_cookbook = subject.download
|
|
47
|
+
cached_cookbook = subject.download
|
|
46
48
|
ref = subject.ref
|
|
47
49
|
|
|
48
|
-
expect(
|
|
50
|
+
expect(storage_path).to have_structure {
|
|
49
51
|
directory "#{cached_cookbook.cookbook_name}-#{ref}" do
|
|
50
52
|
file 'metadata.rb'
|
|
51
53
|
end
|
|
@@ -53,28 +55,28 @@ describe Berkshelf::GitLocation do
|
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
context 'given no ref/branch/tag options is given' do
|
|
56
|
-
subject {
|
|
58
|
+
subject { described_class.new(dependency, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
|
|
57
59
|
|
|
58
60
|
it 'sets the branch attribute to the HEAD revision of the cloned repo' do
|
|
59
|
-
subject.download
|
|
61
|
+
subject.download
|
|
60
62
|
expect(subject.branch).to_not be_nil
|
|
61
63
|
end
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
context 'given a git repo that does not exist' do
|
|
65
|
-
|
|
67
|
+
before { dependency.stub(name: "doesnot_exist") }
|
|
68
|
+
subject { described_class.new(dependency, git: 'git://github.com/RiotGames/thisrepo_does_not_exist.git') }
|
|
66
69
|
|
|
67
70
|
it 'raises a GitError' do
|
|
68
71
|
Berkshelf::Git.stub(:git).and_raise(Berkshelf::GitError.new(''))
|
|
69
|
-
expect {
|
|
70
|
-
subject.download(tmp_path)
|
|
71
|
-
}.to raise_error(Berkshelf::GitError)
|
|
72
|
+
expect { subject.download }.to raise_error(Berkshelf::GitError)
|
|
72
73
|
end
|
|
73
74
|
end
|
|
74
75
|
|
|
75
76
|
context 'given a git repo that does not contain a cookbook' do
|
|
76
|
-
let(:fake_remote) {
|
|
77
|
-
|
|
77
|
+
let(:fake_remote) { remote_path('not_a_cookbook') }
|
|
78
|
+
before { dependency.stub(name: "doesnot_exist") }
|
|
79
|
+
subject { described_class.new(dependency, git: "file://#{fake_remote}.git") }
|
|
78
80
|
|
|
79
81
|
it 'raises a CookbookNotFound error' do
|
|
80
82
|
subject.stub(:clone).and_return {
|
|
@@ -82,24 +84,16 @@ describe Berkshelf::GitLocation do
|
|
|
82
84
|
Dir.chdir(fake_remote) { |dir| `git init; echo hi > README; git add README; git commit README -m 'README'`; dir }
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
expect {
|
|
86
|
-
subject.download(tmp_path)
|
|
87
|
-
}.to raise_error(Berkshelf::CookbookNotFound)
|
|
87
|
+
expect { subject.download }.to raise_error(Berkshelf::CookbookNotFound)
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
context 'given the content at the Git repo does not satisfy the version constraint' do
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
double('constraint', satisfies?: false),
|
|
95
|
-
git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git'
|
|
96
|
-
)
|
|
97
|
-
end
|
|
92
|
+
before { constraint.stub(satisfies?: false) }
|
|
93
|
+
subject { described_class.new(dependency, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
|
|
98
94
|
|
|
99
95
|
it 'raises a CookbookValidationFailure error' do
|
|
100
|
-
expect {
|
|
101
|
-
subject.download(tmp_path)
|
|
102
|
-
}.to raise_error(Berkshelf::CookbookValidationFailure)
|
|
96
|
+
expect { subject.download }.to raise_error(Berkshelf::CookbookValidationFailure)
|
|
103
97
|
end
|
|
104
98
|
end
|
|
105
99
|
|
|
@@ -107,15 +101,12 @@ describe Berkshelf::GitLocation do
|
|
|
107
101
|
let(:tag) { '1.0.0' }
|
|
108
102
|
|
|
109
103
|
subject do
|
|
110
|
-
|
|
111
|
-
complacent_constraint,
|
|
112
|
-
git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git',
|
|
113
|
-
tag: tag
|
|
114
|
-
)
|
|
104
|
+
described_class.new(dependency, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git', tag: tag)
|
|
115
105
|
end
|
|
116
|
-
|
|
106
|
+
|
|
107
|
+
let(:cached) { subject.download }
|
|
117
108
|
let(:sha) { subject.ref }
|
|
118
|
-
let(:expected_path) {
|
|
109
|
+
let(:expected_path) { storage_path.join("#{cached.cookbook_name}-#{sha}") }
|
|
119
110
|
|
|
120
111
|
it 'returns a cached cookbook with a path that contains the ref' do
|
|
121
112
|
expect(cached.path).to eq(expected_path)
|
|
@@ -126,15 +117,12 @@ describe Berkshelf::GitLocation do
|
|
|
126
117
|
let(:branch) { 'master' }
|
|
127
118
|
|
|
128
119
|
subject do
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git',
|
|
132
|
-
branch: branch
|
|
133
|
-
)
|
|
120
|
+
described_class.new(dependency, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git',
|
|
121
|
+
branch: branch)
|
|
134
122
|
end
|
|
135
|
-
let(:cached) { subject.download
|
|
123
|
+
let(:cached) { subject.download }
|
|
136
124
|
let(:sha) { subject.ref }
|
|
137
|
-
let(:expected_path) {
|
|
125
|
+
let(:expected_path) { storage_path.join("#{cached.cookbook_name}-#{sha}") }
|
|
138
126
|
|
|
139
127
|
it 'returns a cached cookbook with a path that contains the ref' do
|
|
140
128
|
expect(cached.path).to eq(expected_path)
|
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Berkshelf::PathLocation do
|
|
4
|
-
let(:
|
|
4
|
+
let(:constraint) { double('comp-vconstraint', satisfies?: true) }
|
|
5
|
+
let(:dependency) { double('dep', name: "nginx", version_constraint: constraint) }
|
|
5
6
|
let(:path) { fixtures_path.join('cookbooks', 'example_cookbook').to_s }
|
|
6
7
|
|
|
7
|
-
describe
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: path) }
|
|
17
|
-
|
|
18
|
-
describe '#to_s' do
|
|
19
|
-
context 'for a remote path' do
|
|
20
|
-
subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: path) }
|
|
21
|
-
|
|
22
|
-
it 'includes the path information' do
|
|
23
|
-
expect(subject.to_s).to match(/path\:.+example_cookbook/)
|
|
8
|
+
describe "ClassMethods" do
|
|
9
|
+
describe "::new" do
|
|
10
|
+
it 'assigns the value of :path to #path' do
|
|
11
|
+
location = described_class.new(dependency, path: path)
|
|
12
|
+
expect(location.path).to eq(path)
|
|
24
13
|
end
|
|
25
14
|
end
|
|
15
|
+
end
|
|
26
16
|
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
let(:options) { { path: path } }
|
|
18
|
+
let(:instance) { described_class.new(dependency, options) }
|
|
29
19
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
describe "#download" do
|
|
21
|
+
it "returns a CachedCookbook" do
|
|
22
|
+
expect(instance.download).to be_a(Berkshelf::CachedCookbook)
|
|
33
23
|
end
|
|
34
24
|
end
|
|
35
25
|
end
|
|
@@ -15,19 +15,17 @@ describe Berkshelf::Lockfile do
|
|
|
15
15
|
}.to_not raise_error
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
it 'has the correct
|
|
19
|
-
expect(subject).to
|
|
20
|
-
expect(subject).to
|
|
18
|
+
it 'has the correct dependencies' do
|
|
19
|
+
expect(subject).to have_dependency 'build-essential'
|
|
20
|
+
expect(subject).to have_dependency 'chef-client'
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
24
|
subject { Berkshelf::Lockfile.new(berksfile) }
|
|
27
25
|
|
|
28
|
-
describe '#
|
|
26
|
+
describe '#dependencies' do
|
|
29
27
|
it 'returns an array' do
|
|
30
|
-
expect(subject.
|
|
28
|
+
expect(subject.dependencies).to be_a(Array)
|
|
31
29
|
end
|
|
32
30
|
end
|
|
33
31
|
|
|
@@ -41,26 +39,26 @@ describe Berkshelf::Lockfile do
|
|
|
41
39
|
end
|
|
42
40
|
end
|
|
43
41
|
|
|
44
|
-
describe '#
|
|
42
|
+
describe '#has_dependency?' do
|
|
45
43
|
it 'returns true if a matching cookbook is found' do
|
|
46
|
-
expect(subject.
|
|
44
|
+
expect(subject.has_dependency?('build-essential')).to be_true
|
|
47
45
|
end
|
|
48
46
|
|
|
49
47
|
it 'returns false if no matching cookbook is found' do
|
|
50
|
-
expect(subject.
|
|
48
|
+
expect(subject.has_dependency?('foo')).to be_false
|
|
51
49
|
end
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
describe '#update' do
|
|
55
|
-
it 'resets the
|
|
56
|
-
subject.should_receive(:
|
|
53
|
+
it 'resets the dependencies' do
|
|
54
|
+
subject.should_receive(:reset_dependencies!).once
|
|
57
55
|
subject.update([])
|
|
58
56
|
end
|
|
59
57
|
|
|
60
|
-
it 'appends each of the
|
|
61
|
-
|
|
62
|
-
subject.should_receive(:append).with(
|
|
63
|
-
subject.update([
|
|
58
|
+
it 'appends each of the dependencies' do
|
|
59
|
+
dependency = double('dependency')
|
|
60
|
+
subject.should_receive(:append).with(dependency).once
|
|
61
|
+
subject.update([dependency])
|
|
64
62
|
end
|
|
65
63
|
|
|
66
64
|
it 'saves the file' do
|
|
@@ -70,32 +68,32 @@ describe Berkshelf::Lockfile do
|
|
|
70
68
|
end
|
|
71
69
|
|
|
72
70
|
describe '#add' do
|
|
73
|
-
let(:
|
|
71
|
+
let(:dependency) { double('dependency', name: 'build-essential') }
|
|
74
72
|
|
|
75
|
-
it 'adds the new
|
|
76
|
-
subject.add(
|
|
77
|
-
expect(subject).to
|
|
73
|
+
it 'adds the new dependency to the @dependencies instance variable' do
|
|
74
|
+
subject.add(dependency)
|
|
75
|
+
expect(subject).to have_dependency(dependency)
|
|
78
76
|
end
|
|
79
77
|
|
|
80
|
-
it 'does not add duplicate
|
|
81
|
-
5.times { subject.add(
|
|
82
|
-
expect(subject).to
|
|
78
|
+
it 'does not add duplicate dependencies' do
|
|
79
|
+
5.times { subject.add(dependency) }
|
|
80
|
+
expect(subject).to have_dependency(dependency)
|
|
83
81
|
end
|
|
84
82
|
end
|
|
85
83
|
|
|
86
84
|
describe '#remove' do
|
|
87
|
-
let(:
|
|
85
|
+
let(:dependency) { double('dependency', name: 'build-essential') }
|
|
88
86
|
|
|
89
87
|
before do
|
|
90
|
-
subject.add(
|
|
88
|
+
subject.add(dependency)
|
|
91
89
|
end
|
|
92
90
|
|
|
93
|
-
it 'removes the
|
|
94
|
-
subject.remove(
|
|
95
|
-
expect(subject).to_not
|
|
91
|
+
it 'removes the dependency' do
|
|
92
|
+
subject.remove(dependency)
|
|
93
|
+
expect(subject).to_not have_dependency(dependency)
|
|
96
94
|
end
|
|
97
95
|
|
|
98
|
-
it 'raises an except if the
|
|
96
|
+
it 'raises an except if the dependency does not exist' do
|
|
99
97
|
expect {
|
|
100
98
|
subject.remove(nil)
|
|
101
99
|
}.to raise_error Berkshelf::CookbookNotFound
|
|
@@ -110,15 +108,15 @@ describe Berkshelf::Lockfile do
|
|
|
110
108
|
|
|
111
109
|
describe '#inspect' do
|
|
112
110
|
it 'returns a pretty-formatted, detailed string' do
|
|
113
|
-
expect(subject.inspect).to eq
|
|
111
|
+
expect(subject.inspect).to eq("#<#{described_class} Berksfile.lock, dependencies: [#<Berkshelf::Dependency: build-essential (>= 0.0.0), locked_version: 1.1.2, groups: [:default], location: default>, #<Berkshelf::Dependency: chef-client (>= 0.0.0), locked_version: 2.1.4, groups: [:default], location: default>]>")
|
|
114
112
|
end
|
|
115
113
|
end
|
|
116
114
|
|
|
117
115
|
describe '#to_hash' do
|
|
118
116
|
let(:hash) { subject.to_hash }
|
|
119
117
|
|
|
120
|
-
it 'has the `:
|
|
121
|
-
expect(hash).to have_key(:
|
|
118
|
+
it 'has the `:dependencies` key' do
|
|
119
|
+
expect(hash).to have_key(:dependencies)
|
|
122
120
|
end
|
|
123
121
|
end
|
|
124
122
|
|
|
@@ -144,22 +142,22 @@ describe Berkshelf::Lockfile do
|
|
|
144
142
|
end
|
|
145
143
|
end
|
|
146
144
|
|
|
147
|
-
describe '#
|
|
148
|
-
before { Berkshelf::Lockfile.send(:public, :
|
|
145
|
+
describe '#reset_dependencies!' do
|
|
146
|
+
before { Berkshelf::Lockfile.send(:public, :reset_dependencies!) }
|
|
149
147
|
|
|
150
|
-
it 'sets the
|
|
148
|
+
it 'sets the dependencies to an empty hash' do
|
|
151
149
|
expect {
|
|
152
|
-
subject.
|
|
153
|
-
}.to change { subject.
|
|
150
|
+
subject.reset_dependencies!
|
|
151
|
+
}.to change { subject.dependencies }.to([])
|
|
154
152
|
end
|
|
155
153
|
end
|
|
156
154
|
|
|
157
155
|
describe '#cookbook_name' do
|
|
158
156
|
before { Berkshelf::Lockfile.send(:public, :cookbook_name) }
|
|
159
157
|
|
|
160
|
-
it 'accepts a cookbook
|
|
161
|
-
|
|
162
|
-
expect(subject.cookbook_name(
|
|
158
|
+
it 'accepts a cookbook dependency' do
|
|
159
|
+
dependency = double('dependency', name: 'build-essential', is_a?: true)
|
|
160
|
+
expect(subject.cookbook_name(dependency)).to eq 'build-essential'
|
|
163
161
|
end
|
|
164
162
|
|
|
165
163
|
it 'accepts a string' do
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Berkshelf::Resolver::Graph do
|
|
4
|
+
subject { described_class.new }
|
|
5
|
+
|
|
6
|
+
describe "#populate" do
|
|
7
|
+
let(:sources) { Berkshelf::Source.new("http://localhost:26210") }
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
berks_dependency("ruby", "1.0.0", dependencies: { "elixir" => ">= 0.1.0" })
|
|
11
|
+
berks_dependency("ruby", "2.0.0")
|
|
12
|
+
berks_dependency("elixir", "1.0.0")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "adds each dependency to the graph" do
|
|
16
|
+
subject.populate(sources)
|
|
17
|
+
expect(subject.artifacts).to have(3).items
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "adds the dependencies of each dependency to the graph" do
|
|
21
|
+
subject.populate(sources)
|
|
22
|
+
expect(subject.artifacts("ruby", "1.0.0").dependencies).to have(1).item
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#universe" do
|
|
27
|
+
let(:sources) { Berkshelf::Source.new("http://localhost:26210") }
|
|
28
|
+
|
|
29
|
+
before do
|
|
30
|
+
berks_dependency("ruby", "1.0.0")
|
|
31
|
+
berks_dependency("elixir", "1.0.0")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "returns an array of APIClient::RemoteCookbook" do
|
|
35
|
+
result = subject.universe(sources)
|
|
36
|
+
expect(result).to be_a(Array)
|
|
37
|
+
result.each { |remote| expect(remote).to be_a(Berkshelf::APIClient::RemoteCookbook) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "contains the entire universe of dependencies" do
|
|
41
|
+
expect(subject.universe(sources)).to have(2).items
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -1,111 +1,62 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Berkshelf::Resolver
|
|
4
|
-
let(:
|
|
5
|
-
let(:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
downloaded?: true,
|
|
13
|
-
cached_cookbook: double('mysql-cookbook',
|
|
14
|
-
name: 'mysql-1.2.4',
|
|
15
|
-
cookbook_name: 'mysql',
|
|
16
|
-
version: '1.2.4',
|
|
17
|
-
dependencies: {"nginx" => ">= 0.1.0"}
|
|
18
|
-
),
|
|
19
|
-
location: double('location', validate_cached: true)
|
|
20
|
-
)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe '.initialize' do
|
|
24
|
-
it 'adds the specified sources to the sources hash' do
|
|
25
|
-
resolver = Berkshelf::Resolver.new(berksfile, sources: [source], skip_dependencies: true)
|
|
26
|
-
expect(resolver).to have_source(source.name)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'does not add dependencies if skipped' do
|
|
30
|
-
resolver = Berkshelf::Resolver.new(berksfile, sources: [source], skip_dependencies: true)
|
|
31
|
-
expect(resolver).to_not have_source('nginx')
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'adds the dependencies of the source as sources' do
|
|
35
|
-
resolver = Berkshelf::Resolver.new(berksfile, sources: [source])
|
|
36
|
-
expect(resolver).to have_source('nginx')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context 'location is not set' do
|
|
40
|
-
before(:each) do
|
|
41
|
-
source.stub(:location) { nil }
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'does not raise' do
|
|
45
|
-
expect { Berkshelf::Resolver.new(berksfile, sources: [source], skip_dependencies: true) }.to_not raise_error
|
|
3
|
+
describe Berkshelf::Resolver do
|
|
4
|
+
let(:berksfile) { double('berksfile') }
|
|
5
|
+
let(:demand) { Berkshelf::Dependency.new(berksfile, "mysql", constraint: "= 1.2.4") }
|
|
6
|
+
|
|
7
|
+
describe "ClassMethods" do
|
|
8
|
+
describe "::initialize" do
|
|
9
|
+
it 'adds the specified dependencies to the dependencies hash' do
|
|
10
|
+
resolver = described_class.new(berksfile, demand)
|
|
11
|
+
expect(resolver).to have_demand(demand)
|
|
46
12
|
end
|
|
47
13
|
end
|
|
48
14
|
end
|
|
49
15
|
|
|
50
|
-
|
|
51
16
|
subject { Berkshelf::Resolver.new(berksfile) }
|
|
52
17
|
|
|
53
|
-
describe
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
subject.add_source(source, false)
|
|
58
|
-
expect(subject.sources).to include(source)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it 'adds an artifact of the same name of the source to the graph' do
|
|
62
|
-
subject.graph.should_receive(:artifacts).with(source.name, source.cached_cookbook.version)
|
|
63
|
-
|
|
64
|
-
subject.add_source(source, false)
|
|
18
|
+
describe "#add_demand" do
|
|
19
|
+
it 'adds the demand to the instance of resolver' do
|
|
20
|
+
subject.add_demand(demand)
|
|
21
|
+
expect(subject.demands).to include(demand)
|
|
65
22
|
end
|
|
66
23
|
|
|
67
|
-
it '
|
|
68
|
-
subject.should_receive(:
|
|
69
|
-
|
|
70
|
-
subject.add_source(source)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it 'raises a DuplicateSourceDefined exception if a source of the same name is added' do
|
|
74
|
-
subject.should_receive(:has_source?).with(source).and_return(true)
|
|
24
|
+
it 'raises a DuplicateDemand exception if a demand of the same name is added' do
|
|
25
|
+
subject.should_receive(:has_demand?).with(demand).and_return(true)
|
|
75
26
|
|
|
76
27
|
expect {
|
|
77
|
-
subject.
|
|
78
|
-
}.to raise_error(Berkshelf::
|
|
28
|
+
subject.add_demand(demand)
|
|
29
|
+
}.to raise_error(Berkshelf::DuplicateDemand)
|
|
79
30
|
end
|
|
31
|
+
end
|
|
80
32
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
subject.add_source(source, false)
|
|
86
|
-
end
|
|
33
|
+
describe "#demands" do
|
|
34
|
+
it "returns an Array" do
|
|
35
|
+
expect(subject.demands).to be_a(Array)
|
|
87
36
|
end
|
|
88
37
|
end
|
|
89
38
|
|
|
90
|
-
describe
|
|
91
|
-
before { subject.
|
|
39
|
+
describe "#get_demand" do
|
|
40
|
+
before { subject.add_demand(demand) }
|
|
92
41
|
|
|
93
|
-
context 'given a string representation of the
|
|
94
|
-
it 'returns
|
|
95
|
-
expect(subject.
|
|
42
|
+
context 'given a string representation of the demand to retrieve' do
|
|
43
|
+
it 'returns a Berkshelf::Dependency of the same name' do
|
|
44
|
+
expect(subject.get_demand(demand.name)).to eq(demand)
|
|
96
45
|
end
|
|
97
46
|
end
|
|
98
47
|
end
|
|
99
48
|
|
|
100
|
-
describe '#
|
|
101
|
-
before { subject.
|
|
49
|
+
describe '#has_demand?' do
|
|
50
|
+
before { subject.add_demand(demand) }
|
|
102
51
|
|
|
103
|
-
it 'returns true if the
|
|
104
|
-
expect(subject.
|
|
52
|
+
it 'returns true if the demand exists' do
|
|
53
|
+
expect(subject.has_demand?(demand.name)).to be_true
|
|
105
54
|
end
|
|
106
55
|
|
|
107
|
-
it 'returns false if the
|
|
108
|
-
expect(subject.
|
|
56
|
+
it 'returns false if the demand does not exist' do
|
|
57
|
+
expect(subject.has_demand?('non-existent')).to be_false
|
|
109
58
|
end
|
|
110
59
|
end
|
|
60
|
+
|
|
61
|
+
describe "#resolve"
|
|
111
62
|
end
|