librarian-puppet 0.0.1.pre

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