berkshelf 2.0.18 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/.ruby-version +1 -1
  2. data/.travis.yml +4 -1
  3. data/CHANGELOG.md +2 -26
  4. data/Gemfile +12 -2
  5. data/README.md +9 -1
  6. data/berkshelf.gemspec +9 -18
  7. data/bin/berks +3 -13
  8. data/features/apply_command.feature +11 -9
  9. data/features/berksfile.feature +8 -10
  10. data/features/config.feature +1 -2
  11. data/features/configure_command.feature +13 -14
  12. data/features/contingent_command.feature +13 -1
  13. data/features/cookbook_command.feature +2 -4
  14. data/features/groups_install.feature +10 -2
  15. data/features/help.feature +1 -1
  16. data/features/init_command.feature +5 -7
  17. data/features/install_command.feature +157 -228
  18. data/features/json_formatter.feature +27 -15
  19. data/features/licenses.feature +18 -12
  20. data/features/list_command.feature +6 -1
  21. data/features/lockfile.feature +116 -72
  22. data/features/outdated_command.feature +3 -47
  23. data/features/package_command.feature +10 -7
  24. data/features/shelf/show.feature +2 -2
  25. data/features/shelf/uninstall.feature +2 -2
  26. data/features/show_command.feature +10 -3
  27. data/features/step_definitions/chef/config_steps.rb +12 -0
  28. data/features/step_definitions/chef_server_steps.rb +16 -16
  29. data/features/step_definitions/cli_steps.rb +3 -79
  30. data/features/step_definitions/config_steps.rb +43 -0
  31. data/features/step_definitions/environment_steps.rb +7 -0
  32. data/features/step_definitions/filesystem_steps.rb +12 -57
  33. data/features/step_definitions/gem_steps.rb +1 -2
  34. data/features/step_definitions/json_steps.rb +3 -1
  35. data/features/step_definitions/lockfile_steps.rb +4 -0
  36. data/features/step_definitions/utility_steps.rb +0 -19
  37. data/features/support/aruba.rb +12 -0
  38. data/features/support/env.rb +52 -57
  39. data/features/update_command.feature +37 -23
  40. data/features/upload_command.feature +96 -160
  41. data/generator_files/Berksfile.erb +2 -1
  42. data/generator_files/Vagrantfile.erb +3 -0
  43. data/generator_files/default_test.rb.erb +1 -1
  44. data/generator_files/helpers.rb.erb +1 -1
  45. data/lib/berkshelf.rb +43 -24
  46. data/lib/berkshelf/api_client.rb +67 -0
  47. data/lib/berkshelf/api_client/remote_cookbook.rb +42 -0
  48. data/lib/berkshelf/berksfile.rb +232 -420
  49. data/lib/berkshelf/cached_cookbook.rb +22 -10
  50. data/lib/berkshelf/chef/config.rb +1 -0
  51. data/lib/berkshelf/cli.rb +66 -68
  52. data/lib/berkshelf/commands/shelf.rb +1 -1
  53. data/lib/berkshelf/community_rest.rb +10 -17
  54. data/lib/berkshelf/config.rb +23 -27
  55. data/lib/berkshelf/cookbook_generator.rb +3 -4
  56. data/lib/berkshelf/cookbook_store.rb +74 -17
  57. data/lib/berkshelf/core_ext/file.rb +2 -2
  58. data/lib/berkshelf/core_ext/pathname.rb +7 -5
  59. data/lib/berkshelf/{cookbook_source.rb → dependency.rb} +47 -67
  60. data/lib/berkshelf/downloader.rb +49 -106
  61. data/lib/berkshelf/errors.rb +64 -71
  62. data/lib/berkshelf/formatters.rb +11 -9
  63. data/lib/berkshelf/formatters/human_readable.rb +9 -9
  64. data/lib/berkshelf/formatters/json.rb +14 -4
  65. data/lib/berkshelf/init_generator.rb +3 -3
  66. data/lib/berkshelf/installer.rb +136 -0
  67. data/lib/berkshelf/location.rb +91 -131
  68. data/lib/berkshelf/locations/git_location.rb +9 -11
  69. data/lib/berkshelf/locations/github_location.rb +1 -1
  70. data/lib/berkshelf/locations/path_location.rb +10 -27
  71. data/lib/berkshelf/lockfile.rb +92 -70
  72. data/lib/berkshelf/logger.rb +4 -7
  73. data/lib/berkshelf/mixin/config.rb +21 -4
  74. data/lib/berkshelf/resolver.rb +60 -150
  75. data/lib/berkshelf/resolver/graph.rb +44 -0
  76. data/lib/berkshelf/source.rb +55 -0
  77. data/lib/berkshelf/source_uri.rb +38 -0
  78. data/lib/berkshelf/version.rb +1 -1
  79. data/spec/config/knife.rb +1 -1
  80. data/spec/fixtures/cassettes/Berkshelf_Resolver/_initialize/adds_the_dependencies_of_the_dependency_as_dependencies.yml +3694 -0
  81. data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +1 -1
  82. data/spec/fixtures/lockfiles/default.lock +1 -1
  83. data/spec/spec_helper.rb +20 -121
  84. data/spec/support/chef_api.rb +3 -4
  85. data/spec/support/chef_server.rb +20 -11
  86. data/spec/support/git.rb +127 -0
  87. data/spec/support/kitchen.rb +12 -0
  88. data/spec/support/path_helpers.rb +69 -0
  89. data/spec/unit/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  90. data/spec/unit/berkshelf/api_client_spec.rb +57 -0
  91. data/spec/unit/berkshelf/berksfile_spec.rb +206 -324
  92. data/spec/unit/berkshelf/cached_cookbook_spec.rb +73 -38
  93. data/spec/unit/berkshelf/community_rest_spec.rb +30 -71
  94. data/spec/unit/berkshelf/config_spec.rb +3 -14
  95. data/spec/unit/berkshelf/cookbook_generator_spec.rb +1 -2
  96. data/spec/unit/berkshelf/cookbook_store_spec.rb +12 -7
  97. data/spec/unit/berkshelf/dependency_spec.rb +285 -0
  98. data/spec/unit/berkshelf/downloader_spec.rb +4 -183
  99. data/spec/unit/berkshelf/formatters/null_spec.rb +1 -1
  100. data/spec/unit/berkshelf/formatters_spec.rb +4 -2
  101. data/spec/unit/berkshelf/git_spec.rb +15 -15
  102. data/spec/unit/berkshelf/installer_spec.rb +39 -0
  103. data/spec/unit/berkshelf/location_spec.rb +87 -114
  104. data/spec/unit/berkshelf/locations/git_location_spec.rb +41 -53
  105. data/spec/unit/berkshelf/locations/path_location_spec.rb +13 -23
  106. data/spec/unit/berkshelf/lockfile_spec.rb +38 -40
  107. data/spec/unit/berkshelf/resolver/graph_spec.rb +44 -0
  108. data/spec/unit/berkshelf/resolver_spec.rb +34 -83
  109. data/spec/unit/berkshelf/source_spec.rb +23 -0
  110. data/spec/unit/berkshelf/source_uri_spec.rb +29 -0
  111. metadata +149 -188
  112. checksums.yaml +0 -7
  113. data/features/default_locations.feature +0 -127
  114. data/features/step_definitions/berksfile_steps.rb +0 -8
  115. data/features/step_definitions/configure_cli_steps.rb +0 -19
  116. data/features/vendor_install.feature +0 -19
  117. data/lib/berkshelf/core_ext/openuri.rb +0 -36
  118. data/lib/berkshelf/core_ext/rbzip2.rb +0 -8
  119. data/lib/berkshelf/locations/chef_api_location.rb +0 -228
  120. data/lib/berkshelf/locations/site_location.rb +0 -92
  121. data/lib/berkshelf/test.rb +0 -35
  122. data/spec/knife.rb.sample +0 -12
  123. data/spec/support/test_generators.rb +0 -27
  124. data/spec/unit/berkshelf/cli_spec.rb +0 -16
  125. data/spec/unit/berkshelf/cookbook_source_spec.rb +0 -358
  126. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +0 -46
  127. data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +0 -139
  128. 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(:complacent_constraint) { double('comp-vconstraint', satisfies?: true) }
4
+ let(:constraint) { double('comp-vconstraint', satisfies?: true) }
5
+ let(:dependency) { double('dep', name: "berkshelf-cookbook-fixture", version_constraint: constraint) }
5
6
 
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)
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
- 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)
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
- Berkshelf::GitLocation.any_instance.stub(:cached?).and_return(true)
31
- Berkshelf::GitLocation.any_instance.stub(:validate_cached).with(cached).and_return(cached)
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(tmp_path)).to eq(cached)
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(tmp_path)).to be_a(Berkshelf::CachedCookbook)
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(tmp_path)
47
+ cached_cookbook = subject.download
46
48
  ref = subject.ref
47
49
 
48
- expect(tmp_path).to have_structure {
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 { Berkshelf::GitLocation.new('berkshelf-cookbook-fixture', complacent_constraint, git: 'git://github.com/RiotGames/berkshelf-cookbook-fixture.git') }
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(tmp_path)
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
- subject { Berkshelf::GitLocation.new('doesnot_exist', complacent_constraint, git: 'git://github.com/RiotGames/thisrepo_does_not_exist.git') }
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) { local_git_origin_path_for('not_a_cookbook') }
77
- subject { Berkshelf::GitLocation.new('doesnot_exist', complacent_constraint, git: "file://#{fake_remote}.git") }
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
- subject do
93
- Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
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
- Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
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
- let(:cached) { subject.download(tmp_path) }
106
+
107
+ let(:cached) { subject.download }
117
108
  let(:sha) { subject.ref }
118
- let(:expected_path) { tmp_path.join("#{cached.cookbook_name}-#{sha}") }
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
- Berkshelf::GitLocation.new('berkshelf-cookbook-fixture',
130
- complacent_constraint,
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(tmp_path) }
123
+ let(:cached) { subject.download }
136
124
  let(:sha) { subject.ref }
137
- let(:expected_path) { tmp_path.join("#{cached.cookbook_name}-#{sha}") }
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(:complacent_constraint) { double('comp-vconstraint', satisfies?: true) }
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 '.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)
11
- end
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
- context 'for a store path' do
28
- subject { Berkshelf::PathLocation.new('nginx', complacent_constraint, path: File.join(Berkshelf.berkshelf_path, 'cookbooks/example_cookbook')) }
17
+ let(:options) { { path: path } }
18
+ let(:instance) { described_class.new(dependency, options) }
29
19
 
30
- it 'does not include the path information' do
31
- expect(subject.to_s).to_not match(/path\:.+/)
32
- end
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 sources' do
19
- expect(subject).to have_source 'build-essential'
20
- expect(subject).to have_source 'chef-client'
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 '#sources' do
26
+ describe '#dependencies' do
29
27
  it 'returns an array' do
30
- expect(subject.sources).to be_a(Array)
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 '#has_source?' do
42
+ describe '#has_dependency?' do
45
43
  it 'returns true if a matching cookbook is found' do
46
- expect(subject.has_source?('build-essential')).to be_true
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.has_source?('foo')).to be_false
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 sources' do
56
- subject.should_receive(:reset_sources!).once
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 sources' do
61
- source = double('source')
62
- subject.should_receive(:append).with(source).once
63
- subject.update([source])
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(:source) { double('source', name: 'build-essential') }
71
+ let(:dependency) { double('dependency', name: 'build-essential') }
74
72
 
75
- it 'adds the new source to the @sources instance variable' do
76
- subject.add(source)
77
- expect(subject).to have_source(source)
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 sources' do
81
- 5.times { subject.add(source) }
82
- expect(subject).to have_source(source)
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(:source) { double('source', name: 'build-essential') }
85
+ let(:dependency) { double('dependency', name: 'build-essential') }
88
86
 
89
87
  before do
90
- subject.add(source)
88
+ subject.add(dependency)
91
89
  end
92
90
 
93
- it 'removes the source' do
94
- subject.remove(source)
95
- expect(subject).to_not have_source(source)
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 source does not exist' do
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 '#<Berkshelf::Lockfile Berksfile.lock, sources: [#<Berkshelf::CookbookSource: build-essential (>= 0.0.0), locked_version: 1.1.2, groups: [:default], location: default>, #<Berkshelf::CookbookSource: chef-client (>= 0.0.0), locked_version: 2.1.4, groups: [:default], location: default>]>'
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 `:sources` key' do
121
- expect(hash).to have_key(:sources)
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 '#reset_sources!' do
148
- before { Berkshelf::Lockfile.send(:public, :reset_sources!) }
145
+ describe '#reset_dependencies!' do
146
+ before { Berkshelf::Lockfile.send(:public, :reset_dependencies!) }
149
147
 
150
- it 'sets the sources to an empty hash' do
148
+ it 'sets the dependencies to an empty hash' do
151
149
  expect {
152
- subject.reset_sources!
153
- }.to change { subject.sources }.to([])
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 source' do
161
- source = double('source', name: 'build-essential', is_a?: true)
162
- expect(subject.cookbook_name(source)).to eq 'build-essential'
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, :chef_server, vcr: {record: :new_episodes, serialize_with: :yaml} do
4
- let(:downloader) { Berkshelf::Downloader.new(Berkshelf.cookbook_store) }
5
- let(:berksfile) { double(downloader: downloader) }
6
- let(:source) do
7
- double('source',
8
- name: 'mysql',
9
- version_constraint: Solve::Constraint.new('= 1.2.4'),
10
- :version_constraint= => nil,
11
- locked_version: '1.2.4',
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 '#add_source' do
54
- let(:package_version) { double('package-version', dependencies: Array.new) }
55
-
56
- it 'adds the source to the instance of resolver' do
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 'adds the dependencies of the source as packages to the graph' do
68
- subject.should_receive(:add_source_dependencies).with(source)
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.add_source(source)
78
- }.to raise_error(Berkshelf::DuplicateSourceDefined)
28
+ subject.add_demand(demand)
29
+ }.to raise_error(Berkshelf::DuplicateDemand)
79
30
  end
31
+ end
80
32
 
81
- context 'when include_dependencies is false' do
82
- it 'does not try to include_dependencies' do
83
- subject.should_not_receive(:add_source_dependencies)
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 '#get_source' do
91
- before { subject.add_source(source, false) }
39
+ describe "#get_demand" do
40
+ before { subject.add_demand(demand) }
92
41
 
93
- context 'given a string representation of the source to retrieve' do
94
- it 'returns the source of the same name' do
95
- expect(subject.get_source(source.name)).to eq(source)
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 '#has_source?' do
101
- before { subject.add_source(source, false) }
49
+ describe '#has_demand?' do
50
+ before { subject.add_demand(demand) }
102
51
 
103
- it 'returns true if the source exists' do
104
- expect(subject.has_source?(source.name)).to be_true
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 source does not exist' do
108
- expect(subject.has_source?('non-existent')).to be_false
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