librarian-puppet-lmco 0.9.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.md +187 -0
  5. data/bin/librarian-puppet +9 -0
  6. data/lib/librarian/puppet.rb +22 -0
  7. data/lib/librarian/puppet/cli.rb +85 -0
  8. data/lib/librarian/puppet/dsl.rb +16 -0
  9. data/lib/librarian/puppet/environment.rb +54 -0
  10. data/lib/librarian/puppet/extension.rb +47 -0
  11. data/lib/librarian/puppet/lockfile/parser.rb +53 -0
  12. data/lib/librarian/puppet/source.rb +4 -0
  13. data/lib/librarian/puppet/source/forge.rb +348 -0
  14. data/lib/librarian/puppet/source/git.rb +121 -0
  15. data/lib/librarian/puppet/source/githubtarball.rb +249 -0
  16. data/lib/librarian/puppet/source/local.rb +57 -0
  17. data/lib/librarian/puppet/source/path.rb +12 -0
  18. data/lib/librarian/puppet/templates/Puppetfile +10 -0
  19. data/lib/librarian/puppet/version.rb +5 -0
  20. data/vendor/librarian/CHANGELOG.md +224 -0
  21. data/vendor/librarian/Gemfile +6 -0
  22. data/vendor/librarian/MIT-LICENSE +20 -0
  23. data/vendor/librarian/README.md +401 -0
  24. data/vendor/librarian/Rakefile +34 -0
  25. data/vendor/librarian/bin/librarian-chef +7 -0
  26. data/vendor/librarian/bin/librarian-mock +7 -0
  27. data/vendor/librarian/config/cucumber.yaml +1 -0
  28. data/vendor/librarian/features/chef/cli/init.feature +11 -0
  29. data/vendor/librarian/features/chef/cli/install.feature +64 -0
  30. data/vendor/librarian/features/chef/cli/show.feature +77 -0
  31. data/vendor/librarian/features/chef/cli/version.feature +11 -0
  32. data/vendor/librarian/features/support/env.rb +9 -0
  33. data/vendor/librarian/lib/librarian.rb +11 -0
  34. data/vendor/librarian/lib/librarian/action.rb +5 -0
  35. data/vendor/librarian/lib/librarian/action/base.rb +24 -0
  36. data/vendor/librarian/lib/librarian/action/clean.rb +44 -0
  37. data/vendor/librarian/lib/librarian/action/ensure.rb +24 -0
  38. data/vendor/librarian/lib/librarian/action/install.rb +95 -0
  39. data/vendor/librarian/lib/librarian/action/persist_resolution_mixin.rb +51 -0
  40. data/vendor/librarian/lib/librarian/action/resolve.rb +46 -0
  41. data/vendor/librarian/lib/librarian/action/update.rb +44 -0
  42. data/vendor/librarian/lib/librarian/chef.rb +1 -0
  43. data/vendor/librarian/lib/librarian/chef/cli.rb +47 -0
  44. data/vendor/librarian/lib/librarian/chef/dsl.rb +16 -0
  45. data/vendor/librarian/lib/librarian/chef/environment.rb +27 -0
  46. data/vendor/librarian/lib/librarian/chef/extension.rb +9 -0
  47. data/vendor/librarian/lib/librarian/chef/integration/knife.rb +46 -0
  48. data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +59 -0
  49. data/vendor/librarian/lib/librarian/chef/source.rb +4 -0
  50. data/vendor/librarian/lib/librarian/chef/source/git.rb +25 -0
  51. data/vendor/librarian/lib/librarian/chef/source/github.rb +27 -0
  52. data/vendor/librarian/lib/librarian/chef/source/local.rb +69 -0
  53. data/vendor/librarian/lib/librarian/chef/source/path.rb +12 -0
  54. data/vendor/librarian/lib/librarian/chef/source/site.rb +442 -0
  55. data/vendor/librarian/lib/librarian/chef/templates/Cheffile +15 -0
  56. data/vendor/librarian/lib/librarian/cli.rb +223 -0
  57. data/vendor/librarian/lib/librarian/cli/manifest_presenter.rb +93 -0
  58. data/vendor/librarian/lib/librarian/config.rb +7 -0
  59. data/vendor/librarian/lib/librarian/config/database.rb +205 -0
  60. data/vendor/librarian/lib/librarian/config/file_source.rb +47 -0
  61. data/vendor/librarian/lib/librarian/config/hash_source.rb +33 -0
  62. data/vendor/librarian/lib/librarian/config/source.rb +149 -0
  63. data/vendor/librarian/lib/librarian/dependency.rb +147 -0
  64. data/vendor/librarian/lib/librarian/dsl.rb +108 -0
  65. data/vendor/librarian/lib/librarian/dsl/receiver.rb +46 -0
  66. data/vendor/librarian/lib/librarian/dsl/target.rb +171 -0
  67. data/vendor/librarian/lib/librarian/environment.rb +182 -0
  68. data/vendor/librarian/lib/librarian/error.rb +4 -0
  69. data/vendor/librarian/lib/librarian/helpers.rb +13 -0
  70. data/vendor/librarian/lib/librarian/linter/source_linter.rb +55 -0
  71. data/vendor/librarian/lib/librarian/lockfile.rb +29 -0
  72. data/vendor/librarian/lib/librarian/lockfile/compiler.rb +66 -0
  73. data/vendor/librarian/lib/librarian/lockfile/parser.rb +123 -0
  74. data/vendor/librarian/lib/librarian/logger.rb +46 -0
  75. data/vendor/librarian/lib/librarian/manifest.rb +140 -0
  76. data/vendor/librarian/lib/librarian/manifest_set.rb +151 -0
  77. data/vendor/librarian/lib/librarian/mock.rb +1 -0
  78. data/vendor/librarian/lib/librarian/mock/cli.rb +19 -0
  79. data/vendor/librarian/lib/librarian/mock/dsl.rb +15 -0
  80. data/vendor/librarian/lib/librarian/mock/environment.rb +24 -0
  81. data/vendor/librarian/lib/librarian/mock/extension.rb +9 -0
  82. data/vendor/librarian/lib/librarian/mock/source.rb +1 -0
  83. data/vendor/librarian/lib/librarian/mock/source/mock.rb +80 -0
  84. data/vendor/librarian/lib/librarian/mock/source/mock/registry.rb +83 -0
  85. data/vendor/librarian/lib/librarian/resolution.rb +46 -0
  86. data/vendor/librarian/lib/librarian/resolver.rb +81 -0
  87. data/vendor/librarian/lib/librarian/resolver/implementation.rb +223 -0
  88. data/vendor/librarian/lib/librarian/source.rb +2 -0
  89. data/vendor/librarian/lib/librarian/source/basic_api.rb +45 -0
  90. data/vendor/librarian/lib/librarian/source/git.rb +134 -0
  91. data/vendor/librarian/lib/librarian/source/git/repository.rb +217 -0
  92. data/vendor/librarian/lib/librarian/source/local.rb +54 -0
  93. data/vendor/librarian/lib/librarian/source/path.rb +56 -0
  94. data/vendor/librarian/lib/librarian/spec.rb +13 -0
  95. data/vendor/librarian/lib/librarian/spec_change_set.rb +173 -0
  96. data/vendor/librarian/lib/librarian/specfile.rb +17 -0
  97. data/vendor/librarian/lib/librarian/support/abstract_method.rb +21 -0
  98. data/vendor/librarian/lib/librarian/ui.rb +64 -0
  99. data/vendor/librarian/lib/librarian/version.rb +3 -0
  100. data/vendor/librarian/librarian.gemspec +35 -0
  101. data/vendor/librarian/spec/functional/chef/cli_spec.rb +194 -0
  102. data/vendor/librarian/spec/functional/chef/source/git_spec.rb +432 -0
  103. data/vendor/librarian/spec/functional/chef/source/site_spec.rb +266 -0
  104. data/vendor/librarian/spec/functional/source/git/repository_spec.rb +150 -0
  105. data/vendor/librarian/spec/integration/chef/source/git_spec.rb +441 -0
  106. data/vendor/librarian/spec/integration/chef/source/site_spec.rb +217 -0
  107. data/vendor/librarian/spec/support/cli_macro.rb +114 -0
  108. data/vendor/librarian/spec/support/method_patch_macro.rb +30 -0
  109. data/vendor/librarian/spec/support/with_env_macro.rb +20 -0
  110. data/vendor/librarian/spec/unit/action/base_spec.rb +18 -0
  111. data/vendor/librarian/spec/unit/action/clean_spec.rb +102 -0
  112. data/vendor/librarian/spec/unit/action/ensure_spec.rb +37 -0
  113. data/vendor/librarian/spec/unit/action/install_spec.rb +111 -0
  114. data/vendor/librarian/spec/unit/config/database_spec.rb +327 -0
  115. data/vendor/librarian/spec/unit/dependency_spec.rb +212 -0
  116. data/vendor/librarian/spec/unit/dsl_spec.rb +173 -0
  117. data/vendor/librarian/spec/unit/environment_spec.rb +173 -0
  118. data/vendor/librarian/spec/unit/lockfile/parser_spec.rb +162 -0
  119. data/vendor/librarian/spec/unit/lockfile_spec.rb +65 -0
  120. data/vendor/librarian/spec/unit/manifest_set_spec.rb +202 -0
  121. data/vendor/librarian/spec/unit/manifest_spec.rb +36 -0
  122. data/vendor/librarian/spec/unit/mock/source/mock_spec.rb +22 -0
  123. data/vendor/librarian/spec/unit/resolver_spec.rb +233 -0
  124. data/vendor/librarian/spec/unit/source/git_spec.rb +29 -0
  125. data/vendor/librarian/spec/unit/spec_change_set_spec.rb +169 -0
  126. metadata +220 -0
@@ -0,0 +1,150 @@
1
+ require "fileutils"
2
+ require "pathname"
3
+ require "securerandom"
4
+
5
+ require "librarian/source/git/repository"
6
+
7
+ describe Librarian::Source::Git::Repository do
8
+
9
+ let(:env) do
10
+ double(:ui => nil, :logger => double(:debug => nil, :info => nil))
11
+ end
12
+
13
+ let(:project_path) do
14
+ project_path = Pathname.new(__FILE__).expand_path
15
+ project_path = project_path.dirname until project_path.join("Rakefile").exist?
16
+ project_path
17
+ end
18
+ let(:tmp_path) { project_path + "tmp/spec/functional/source/git/repository" }
19
+ after { tmp_path.rmtree if tmp_path && tmp_path.exist? }
20
+ let(:git_source_path) { tmp_path + SecureRandom.hex(16) }
21
+ let(:branch) { "the-branch" }
22
+ let(:tag) { "the-tag" }
23
+ let(:atag) { "the-atag" }
24
+
25
+ before do
26
+ git_source_path.mkpath
27
+ Dir.chdir(git_source_path) do
28
+ `git init`
29
+
30
+ # master
31
+ `touch butter.txt`
32
+ `git add butter.txt`
33
+ `git commit -m "Initial Commit"`
34
+
35
+ # branch
36
+ `git checkout -b #{branch} --quiet`
37
+ `touch jam.txt`
38
+ `git add jam.txt`
39
+ `git commit -m "Branch Commit"`
40
+ `git checkout master --quiet`
41
+
42
+ # tag
43
+ `git checkout -b deletable --quiet`
44
+ `touch jelly.txt`
45
+ `git add jelly.txt`
46
+ `git commit -m "Tag Commit"`
47
+ `git tag #{tag}`
48
+ `git checkout master --quiet`
49
+ `git branch -D deletable`
50
+
51
+ # annotated tag
52
+ `git checkout -b deletable --quiet`
53
+ `touch jelly.txt`
54
+ `git add jelly.txt`
55
+ `git commit -m "Tag Commit"`
56
+ `git tag -am "Annotated Tag Commit" #{atag}`
57
+ `git checkout master --quiet`
58
+ `git branch -D deletable`
59
+ end
60
+ end
61
+
62
+ context "the original" do
63
+ subject { described_class.new(env, git_source_path) }
64
+
65
+ it "should recognize it" do
66
+ subject.should be_git
67
+ end
68
+
69
+ it "should not list any remotes for it" do
70
+ subject.remote_names.should be_empty
71
+ end
72
+
73
+ it "should not list any remote branches for it" do
74
+ subject.remote_branch_names.should be_empty
75
+ end
76
+ end
77
+
78
+ context "a clone" do
79
+ let(:git_clone_path) { tmp_path + SecureRandom.hex(16) }
80
+ subject { described_class.clone!(env, git_clone_path, git_source_path) }
81
+
82
+ let(:master_sha) { subject.hash_from("origin", "master") }
83
+ let(:branch_sha) { subject.hash_from("origin", branch) }
84
+ let(:tag_sha) { subject.hash_from("origin", tag) }
85
+ let(:atag_sha) { subject.hash_from("origin", atag) }
86
+
87
+ it "should recognize it" do
88
+ subject.should be_git
89
+ end
90
+
91
+ it "should have a single remote for it" do
92
+ subject.should have(1).remote_names
93
+ end
94
+
95
+ it "should have a remote with the expected name" do
96
+ subject.remote_names.first.should == "origin"
97
+ end
98
+
99
+ it "should have the remote branch" do
100
+ subject.remote_branch_names["origin"].should include branch
101
+ end
102
+
103
+ it "should be checked out on the master" do
104
+ subject.should be_checked_out(master_sha)
105
+ end
106
+
107
+ context "checking out the branch" do
108
+ before do
109
+ subject.checkout! branch
110
+ end
111
+
112
+ it "should be checked out on the branch" do
113
+ subject.should be_checked_out(branch_sha)
114
+ end
115
+
116
+ it "should not be checked out on the master" do
117
+ subject.should_not be_checked_out(master_sha)
118
+ end
119
+ end
120
+
121
+ context "checking out the tag" do
122
+ before do
123
+ subject.checkout! tag
124
+ end
125
+
126
+ it "should be checked out on the tag" do
127
+ subject.should be_checked_out(tag_sha)
128
+ end
129
+
130
+ it "should not be checked out on the master" do
131
+ subject.should_not be_checked_out(master_sha)
132
+ end
133
+ end
134
+
135
+ context "checking out the annotated tag" do
136
+ before do
137
+ subject.checkout! atag
138
+ end
139
+
140
+ it "should be checked out on the annotated tag" do
141
+ subject.should be_checked_out(atag_sha)
142
+ end
143
+
144
+ it "should not be checked out on the master" do
145
+ subject.should_not be_checked_out(master_sha)
146
+ end
147
+ end
148
+ end
149
+
150
+ end
@@ -0,0 +1,441 @@
1
+ require 'pathname'
2
+ require 'securerandom'
3
+
4
+ require 'librarian'
5
+ require 'librarian/helpers'
6
+ require 'librarian/error'
7
+ require 'librarian/action/resolve'
8
+ require 'librarian/action/install'
9
+ require 'librarian/action/update'
10
+ require 'librarian/chef'
11
+
12
+ module Librarian
13
+ module Chef
14
+ module Source
15
+ describe Git do
16
+
17
+ let(:project_path) do
18
+ project_path = Pathname.new(__FILE__).expand_path
19
+ project_path = project_path.dirname until project_path.join("Rakefile").exist?
20
+ project_path
21
+ end
22
+ let(:tmp_path) { project_path.join("tmp/spec/integration/chef/source/git") }
23
+ after { tmp_path.rmtree if tmp_path && tmp_path.exist? }
24
+
25
+ let(:cookbooks_path) { tmp_path.join("cookbooks") }
26
+
27
+ # depends on repo_path being defined in each context
28
+ let(:env) { Environment.new(:project_path => repo_path) }
29
+
30
+ context "a single dependency with a git source" do
31
+
32
+ let(:sample_path) { tmp_path.join("sample") }
33
+ let(:sample_metadata) do
34
+ Helpers.strip_heredoc(<<-METADATA)
35
+ version "0.6.5"
36
+ METADATA
37
+ end
38
+
39
+ let(:first_sample_path) { cookbooks_path.join("first-sample") }
40
+ let(:first_sample_metadata) do
41
+ Helpers.strip_heredoc(<<-METADATA)
42
+ version "3.2.1"
43
+ METADATA
44
+ end
45
+
46
+ let(:second_sample_path) { cookbooks_path.join("second-sample") }
47
+ let(:second_sample_metadata) do
48
+ Helpers.strip_heredoc(<<-METADATA)
49
+ version "4.3.2"
50
+ METADATA
51
+ end
52
+
53
+ before do
54
+ sample_path.rmtree if sample_path.exist?
55
+ sample_path.mkpath
56
+ sample_path.join("metadata.rb").open("wb") { |f| f.write(sample_metadata) }
57
+ Dir.chdir(sample_path) do
58
+ `git init`
59
+ `git add metadata.rb`
60
+ `git commit -m "Initial commit."`
61
+ end
62
+
63
+ cookbooks_path.rmtree if cookbooks_path.exist?
64
+ cookbooks_path.mkpath
65
+ first_sample_path.mkpath
66
+ first_sample_path.join("metadata.rb").open("wb") { |f| f.write(first_sample_metadata) }
67
+ second_sample_path.mkpath
68
+ second_sample_path.join("metadata.rb").open("wb") { |f| f.write(second_sample_metadata) }
69
+ Dir.chdir(cookbooks_path) do
70
+ `git init`
71
+ `git add .`
72
+ `git commit -m "Initial commit."`
73
+ end
74
+ end
75
+
76
+ context "resolving" do
77
+ let(:repo_path) { tmp_path.join("repo/resolve") }
78
+ before do
79
+ repo_path.rmtree if repo_path.exist?
80
+ repo_path.mkpath
81
+ repo_path.join("cookbooks").mkpath
82
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
83
+ #!/usr/bin/env ruby
84
+ cookbook "sample", :git => #{sample_path.to_s.inspect}
85
+ CHEFFILE
86
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
87
+ end
88
+
89
+ context "the resolve" do
90
+ it "should not raise an exception" do
91
+ expect { Action::Resolve.new(env).run }.to_not raise_error
92
+ end
93
+ end
94
+
95
+ context "the results" do
96
+ before { Action::Resolve.new(env).run }
97
+
98
+ it "should create the lockfile" do
99
+ repo_path.join("Cheffile.lock").should exist
100
+ end
101
+
102
+ it "should not attempt to install the sample cookbok" do
103
+ repo_path.join("cookbooks/sample").should_not exist
104
+ end
105
+ end
106
+ end
107
+
108
+ context "installing" do
109
+ let(:repo_path) { tmp_path.join("repo/install") }
110
+ before do
111
+ repo_path.rmtree if repo_path.exist?
112
+ repo_path.mkpath
113
+ repo_path.join("cookbooks").mkpath
114
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
115
+ #!/usr/bin/env ruby
116
+ cookbook "sample", :git => #{sample_path.to_s.inspect}
117
+ CHEFFILE
118
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
119
+
120
+ Action::Resolve.new(env).run
121
+ end
122
+
123
+ context "the install" do
124
+ it "should not raise an exception" do
125
+ expect { Action::Install.new(env).run }.to_not raise_error
126
+ end
127
+ end
128
+
129
+ context "the results" do
130
+ before { Action::Install.new(env).run }
131
+
132
+ it "should create the lockfile" do
133
+ repo_path.join("Cheffile.lock").should exist
134
+ end
135
+
136
+ it "should create the directory for the cookbook" do
137
+ repo_path.join("cookbooks/sample").should exist
138
+ end
139
+
140
+ it "should copy the cookbook files into the cookbook directory" do
141
+ repo_path.join("cookbooks/sample/metadata.rb").should exist
142
+ end
143
+ end
144
+ end
145
+
146
+ context "resolving and and separately installing" do
147
+ let(:repo_path) { tmp_path.join("repo/resolve-install") }
148
+ before do
149
+ repo_path.rmtree if repo_path.exist?
150
+ repo_path.mkpath
151
+ repo_path.join("cookbooks").mkpath
152
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
153
+ #!/usr/bin/env ruby
154
+ cookbook "sample", :git => #{sample_path.to_s.inspect}
155
+ CHEFFILE
156
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
157
+
158
+ Action::Resolve.new(env).run
159
+ repo_path.join("tmp").rmtree if repo_path.join("tmp").exist?
160
+ end
161
+
162
+ context "the install" do
163
+ it "should not raise an exception" do
164
+ expect { Action::Install.new(env).run }.to_not raise_error
165
+ end
166
+ end
167
+
168
+ context "the results" do
169
+ before { Action::Install.new(env).run }
170
+
171
+ it "should create the directory for the cookbook" do
172
+ repo_path.join("cookbooks/sample").should exist
173
+ end
174
+
175
+ it "should copy the cookbook files into the cookbook directory" do
176
+ repo_path.join("cookbooks/sample/metadata.rb").should exist
177
+ end
178
+ end
179
+ end
180
+
181
+ context "resolving, changing, and resolving" do
182
+ let(:repo_path) { tmp_path.join("repo/resolve-update") }
183
+ before do
184
+ repo_path.rmtree if repo_path.exist?
185
+ repo_path.mkpath
186
+ repo_path.join("cookbooks").mkpath
187
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
188
+ git #{cookbooks_path.to_s.inspect}
189
+ cookbook "first-sample"
190
+ CHEFFILE
191
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
192
+ Action::Resolve.new(env).run
193
+
194
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
195
+ git #{cookbooks_path.to_s.inspect}
196
+ cookbook "first-sample"
197
+ cookbook "second-sample"
198
+ CHEFFILE
199
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
200
+ end
201
+
202
+ context "the second resolve" do
203
+ it "should not raise an exception" do
204
+ expect { Action::Resolve.new(env).run }.to_not raise_error
205
+ end
206
+ end
207
+ end
208
+
209
+ end
210
+
211
+ context "with a path" do
212
+
213
+ let(:git_path) { tmp_path.join("big-git-repo") }
214
+ let(:sample_path) { git_path.join("buttercup") }
215
+ let(:sample_metadata) do
216
+ Helpers.strip_heredoc(<<-METADATA)
217
+ version "0.6.5"
218
+ METADATA
219
+ end
220
+
221
+ before do
222
+ git_path.rmtree if git_path.exist?
223
+ git_path.mkpath
224
+ sample_path.mkpath
225
+ sample_path.join("metadata.rb").open("wb") { |f| f.write(sample_metadata) }
226
+ Dir.chdir(git_path) do
227
+ `git init`
228
+ `git add .`
229
+ `git commit -m "Initial commit."`
230
+ end
231
+ end
232
+
233
+ context "if no path option is given" do
234
+ let(:repo_path) { tmp_path.join("repo/resolve") }
235
+ before do
236
+ repo_path.rmtree if repo_path.exist?
237
+ repo_path.mkpath
238
+ repo_path.join("cookbooks").mkpath
239
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
240
+ #!/usr/bin/env ruby
241
+ cookbook "sample",
242
+ :git => #{git_path.to_s.inspect}
243
+ CHEFFILE
244
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
245
+ end
246
+
247
+ it "should not resolve" do
248
+ expect{ Action::Resolve.new(env).run }.to raise_error
249
+ end
250
+ end
251
+
252
+ context "if the path option is wrong" do
253
+ let(:repo_path) { tmp_path.join("repo/resolve") }
254
+ before do
255
+ repo_path.rmtree if repo_path.exist?
256
+ repo_path.mkpath
257
+ repo_path.join("cookbooks").mkpath
258
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
259
+ #!/usr/bin/env ruby
260
+ cookbook "sample",
261
+ :git => #{git_path.to_s.inspect},
262
+ :path => "jelly"
263
+ CHEFFILE
264
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
265
+ end
266
+
267
+ it "should not resolve" do
268
+ expect{ Action::Resolve.new(env).run }.to raise_error
269
+ end
270
+ end
271
+
272
+ context "if the path option is right" do
273
+ let(:repo_path) { tmp_path.join("repo/resolve") }
274
+ before do
275
+ repo_path.rmtree if repo_path.exist?
276
+ repo_path.mkpath
277
+ repo_path.join("cookbooks").mkpath
278
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
279
+ #!/usr/bin/env ruby
280
+ cookbook "sample",
281
+ :git => #{git_path.to_s.inspect},
282
+ :path => "buttercup"
283
+ CHEFFILE
284
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
285
+ end
286
+
287
+ context "the resolve" do
288
+ it "should not raise an exception" do
289
+ expect { Action::Resolve.new(env).run }.to_not raise_error
290
+ end
291
+ end
292
+
293
+ context "the results" do
294
+ before { Action::Resolve.new(env).run }
295
+
296
+ it "should create the lockfile" do
297
+ repo_path.join("Cheffile.lock").should exist
298
+ end
299
+ end
300
+ end
301
+
302
+ end
303
+
304
+ context "missing a metadata" do
305
+ let(:git_path) { tmp_path.join("big-git-repo") }
306
+ let(:repo_path) { tmp_path.join("repo/resolve") }
307
+ before do
308
+ git_path.rmtree if git_path.exist?
309
+ git_path.mkpath
310
+ Dir.chdir(git_path) do
311
+ `git init`
312
+ `touch not-a-metadata`
313
+ `git add .`
314
+ `git commit -m "Initial commit."`
315
+ end
316
+ repo_path.rmtree if repo_path.exist?
317
+ repo_path.mkpath
318
+ repo_path.join("cookbooks").mkpath
319
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
320
+ cookbook "sample",
321
+ :git => #{git_path.to_s.inspect}
322
+ CHEFFILE
323
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
324
+ end
325
+
326
+ context "the resolve" do
327
+ it "should raise an exception" do
328
+ expect { Action::Resolve.new(env).run }.to raise_error
329
+ end
330
+
331
+ it "should explain the problem" do
332
+ expect { Action::Resolve.new(env).run }.
333
+ to raise_error(Error, /no metadata file found/i)
334
+ end
335
+ end
336
+
337
+ context "the results" do
338
+ before { Action::Resolve.new(env).run rescue nil }
339
+
340
+ it "should not create the lockfile" do
341
+ repo_path.join("Cheffile.lock").should_not exist
342
+ end
343
+
344
+ it "should not create the directory for the cookbook" do
345
+ repo_path.join("cookbooks/sample").should_not exist
346
+ end
347
+ end
348
+ end
349
+
350
+ context "when upstream updates" do
351
+ let(:git_path) { tmp_path.join("upstream-updates-repo") }
352
+ let(:repo_path) { tmp_path.join("repo/resolve-with-upstream-updates") }
353
+
354
+ let(:sample_metadata) do
355
+ Helpers.strip_heredoc(<<-METADATA)
356
+ version "0.6.5"
357
+ METADATA
358
+ end
359
+ before do
360
+
361
+ # set up the git repo as normal, but let's also set up a release-stable branch
362
+ # from which our Cheffile will only pull stable releases
363
+ git_path.rmtree if git_path.exist?
364
+ git_path.mkpath
365
+ git_path.join("metadata.rb").open("w+b"){|f| f.write(sample_metadata)}
366
+
367
+ Dir.chdir(git_path) do
368
+ `git init`
369
+ `git add metadata.rb`
370
+ `git commit -m "Initial Commit."`
371
+ `git checkout -b some-branch --quiet`
372
+ `echo 'hi' > some-file`
373
+ `git add some-file`
374
+ `git commit -m 'Some File.'`
375
+ `git checkout master --quiet`
376
+ end
377
+
378
+ # set up the chef repo as normal, except the Cheffile points to the release-stable
379
+ # branch - we expect when the upstream copy of that branch is changed, then we can
380
+ # fetch & merge those changes when we update
381
+ repo_path.rmtree if repo_path.exist?
382
+ repo_path.mkpath
383
+ repo_path.join("cookbooks").mkpath
384
+ cheffile = Helpers.strip_heredoc(<<-CHEFFILE)
385
+ cookbook "sample",
386
+ :git => #{git_path.to_s.inspect},
387
+ :ref => "some-branch"
388
+ CHEFFILE
389
+ repo_path.join("Cheffile").open("wb") { |f| f.write(cheffile) }
390
+ Action::Resolve.new(env).run
391
+
392
+ # change the upstream copy of that branch: we expect to be able to pull the latest
393
+ # when we re-resolve
394
+ Dir.chdir(git_path) do
395
+ `git checkout some-branch --quiet`
396
+ `echo 'ho' > some-other-file`
397
+ `git add some-other-file`
398
+ `git commit -m 'Some Other File.'`
399
+ `git checkout master --quiet`
400
+ end
401
+ end
402
+
403
+ let(:metadata_file) { repo_path.join("cookbooks/sample/metadata.rb") }
404
+ let(:old_code_file) { repo_path.join("cookbooks/sample/some-file") }
405
+ let(:new_code_file) { repo_path.join("cookbooks/sample/some-other-file") }
406
+
407
+ context "when updating not a cookbook from that source" do
408
+ before do
409
+ Action::Update.new(env).run
410
+ end
411
+
412
+ it "should pull the tip from upstream" do
413
+ Action::Install.new(env).run
414
+
415
+ metadata_file.should exist #sanity
416
+ old_code_file.should exist #sanity
417
+
418
+ new_code_file.should_not exist # the assertion
419
+ end
420
+ end
421
+
422
+ context "when updating a cookbook from that source" do
423
+ before do
424
+ Action::Update.new(env, :names => %w(sample)).run
425
+ end
426
+
427
+ it "should pull the tip from upstream" do
428
+ Action::Install.new(env).run
429
+
430
+ metadata_file.should exist #sanity
431
+ old_code_file.should exist #sanity
432
+
433
+ new_code_file.should exist # the assertion
434
+ end
435
+ end
436
+ end
437
+
438
+ end
439
+ end
440
+ end
441
+ end