librarian 0.0.26 → 0.1.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +0 -3
  2. data/.travis.yml +7 -0
  3. data/Gemfile +1 -1
  4. data/{MIT-LICENSE → LICENSE.txt} +2 -0
  5. data/README.md +13 -363
  6. data/lib/librarian/chef/version.rb +5 -0
  7. data/lib/librarian/cli.rb +1 -0
  8. data/lib/librarian/environment.rb +8 -2
  9. data/lib/librarian/mock/environment.rb +6 -1
  10. data/lib/librarian/mock/version.rb +5 -0
  11. data/lib/librarian/rspec/support/cli_macro.rb +120 -0
  12. data/lib/librarian/source/git.rb +1 -1
  13. data/lib/librarian/source/git/repository.rb +10 -2
  14. data/lib/librarian/version.rb +1 -1
  15. data/librarian.gemspec +15 -22
  16. data/spec/functional/cli_spec.rb +27 -0
  17. data/spec/functional/source/git/repository_spec.rb +2 -0
  18. metadata +69 -100
  19. data/lib/librarian/chef.rb +0 -1
  20. data/lib/librarian/chef/cli.rb +0 -47
  21. data/lib/librarian/chef/dsl.rb +0 -16
  22. data/lib/librarian/chef/environment.rb +0 -27
  23. data/lib/librarian/chef/extension.rb +0 -9
  24. data/lib/librarian/chef/integration/knife.rb +0 -46
  25. data/lib/librarian/chef/manifest_reader.rb +0 -59
  26. data/lib/librarian/chef/source.rb +0 -4
  27. data/lib/librarian/chef/source/git.rb +0 -25
  28. data/lib/librarian/chef/source/github.rb +0 -27
  29. data/lib/librarian/chef/source/local.rb +0 -69
  30. data/lib/librarian/chef/source/path.rb +0 -12
  31. data/lib/librarian/chef/source/site.rb +0 -442
  32. data/lib/librarian/chef/templates/Cheffile +0 -15
  33. data/spec/functional/chef/cli_spec.rb +0 -194
  34. data/spec/functional/chef/source/site_spec.rb +0 -266
  35. data/spec/integration/chef/source/git_spec.rb +0 -441
  36. data/spec/integration/chef/source/site_spec.rb +0 -217
  37. data/spec/support/cli_macro.rb +0 -114
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #^syntax detection
3
-
4
- site 'http://community.opscode.com/api/v1'
5
-
6
- # cookbook 'chef-client'
7
-
8
- # cookbook 'apache2', '>= 1.0.0'
9
-
10
- # cookbook 'rvm',
11
- # :git => 'https://github.com/fnichol/chef-rvm'
12
-
13
- # cookbook 'postgresql',
14
- # :git => 'https://github.com/findsyou/cookbooks',
15
- # :ref => 'postgresql-improvements'
@@ -1,194 +0,0 @@
1
- require "securerandom"
2
-
3
- require "support/cli_macro"
4
-
5
- require "librarian/chef/cli"
6
-
7
- module Librarian
8
- module Chef
9
- describe Cli do
10
- include CliMacro
11
-
12
- describe "init" do
13
- before do
14
- cli! "init"
15
- end
16
-
17
- it "should create a file named Cheffile" do
18
- pwd.should have_file "Cheffile"
19
- end
20
- end
21
-
22
- describe "version" do
23
- before do
24
- cli! "version"
25
- end
26
-
27
- it "should print the version" do
28
- stdout.should == strip_heredoc(<<-STDOUT)
29
- librarian-#{VERSION}
30
- STDOUT
31
- end
32
- end
33
-
34
- describe "install" do
35
-
36
- context "a simple Cheffile with one cookbook" do
37
- let(:metadata) { {
38
- "name" => "apt",
39
- "version" => "1.0.0",
40
- "dependencies" => { },
41
- } }
42
-
43
- before do
44
- write_json_file! "cookbook-sources/apt/metadata.json", metadata
45
- write_file! "Cheffile", strip_heredoc(<<-CHEFFILE)
46
- cookbook 'apt',
47
- :path => 'cookbook-sources'
48
- CHEFFILE
49
-
50
- cli! "install"
51
- end
52
-
53
- it "should write a lockfile" do
54
- pwd.should have_file "Cheffile.lock"
55
- end
56
-
57
- it "should install the cookbook" do
58
- pwd.should have_json_file "cookbooks/apt/metadata.json", metadata
59
- end
60
- end
61
-
62
- context "a simple Cheffile with one cookbook with one dependency" do
63
- let(:main_metadata) { {
64
- "name" => "main",
65
- "version" => "1.0.0",
66
- "dependencies" => {
67
- "sub" => "1.0.0",
68
- }
69
- } }
70
- let(:sub_metadata) { {
71
- "name" => "sub",
72
- "version" => "1.0.0",
73
- "dependencies" => { },
74
- } }
75
-
76
- before do
77
- write_json_file! "cookbook-sources/main/metadata.json", main_metadata
78
- write_json_file! "cookbook-sources/sub/metadata.json", sub_metadata
79
- write_file! "Cheffile", strip_heredoc(<<-CHEFFILE)
80
- path 'cookbook-sources'
81
- cookbook 'main'
82
- CHEFFILE
83
-
84
- cli! "install"
85
- end
86
-
87
- it "should write a lockfile" do
88
- pwd.should have_file "Cheffile.lock"
89
- end
90
-
91
- it "should install the dependant cookbook" do
92
- pwd.should have_json_file "cookbooks/main/metadata.json", main_metadata
93
- end
94
-
95
- it "should install the independent cookbook" do
96
- pwd.should have_json_file "cookbooks/sub/metadata.json", sub_metadata
97
- end
98
- end
99
-
100
- end
101
-
102
- describe "show" do
103
- let(:main_metadata) { {
104
- "name" => "main",
105
- "version" => "1.0.0",
106
- "dependencies" => {
107
- "sub" => "1.0.0",
108
- }
109
- } }
110
- let(:sub_metadata) { {
111
- "name" => "sub",
112
- "version" => "1.0.0",
113
- "dependencies" => { },
114
- } }
115
-
116
- before do
117
- write_json_file! "cookbook-sources/main/metadata.json", main_metadata
118
- write_json_file! "cookbook-sources/sub/metadata.json", sub_metadata
119
- write_file! "Cheffile", strip_heredoc(<<-CHEFFILE)
120
- path 'cookbook-sources'
121
- cookbook 'main'
122
- CHEFFILE
123
-
124
- cli! "install"
125
- end
126
-
127
- context "showing all without a lockfile" do
128
- before do
129
- pwd.join("Cheffile.lock").delete
130
-
131
- cli! "show"
132
- end
133
-
134
- specify { exit_status.should == 1 }
135
-
136
- it "should print a warning" do
137
- stdout.should == strip_heredoc(<<-STDOUT)
138
- Be sure to install first!
139
- STDOUT
140
- end
141
- end
142
-
143
- context "showing all" do
144
- before do
145
- cli! "show"
146
- end
147
-
148
- specify { exit_status.should == 0 }
149
-
150
- it "should print a summary" do
151
- stdout.should == strip_heredoc(<<-STDOUT)
152
- main (1.0.0)
153
- sub (1.0.0)
154
- STDOUT
155
- end
156
- end
157
-
158
- context "showing one without dependencies" do
159
- before do
160
- cli! "show", "sub"
161
- end
162
-
163
- specify { exit_status.should == 0 }
164
-
165
- it "should print the details" do
166
- stdout.should == strip_heredoc(<<-STDOUT)
167
- sub (1.0.0)
168
- source: cookbook-sources
169
- STDOUT
170
- end
171
- end
172
-
173
- context "showing one with dependencies" do
174
- before do
175
- cli! "show", "main"
176
- end
177
-
178
- specify { exit_status.should == 0 }
179
-
180
- it "should print the details" do
181
- stdout.should == strip_heredoc(<<-STDOUT)
182
- main (1.0.0)
183
- source: cookbook-sources
184
- dependencies:
185
- sub (= 1.0.0)
186
- STDOUT
187
- end
188
- end
189
-
190
- end
191
-
192
- end
193
- end
194
- end
@@ -1,266 +0,0 @@
1
- require 'pathname'
2
- require 'json'
3
- require 'webmock'
4
-
5
- require 'librarian'
6
- require 'librarian/helpers'
7
- require 'librarian/chef'
8
- require 'librarian/linter/source_linter'
9
-
10
- module Librarian
11
- module Chef
12
- module Source
13
- describe Site do
14
-
15
- include WebMock::API
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/functional/chef/source/site") }
23
- after { tmp_path.rmtree if tmp_path && tmp_path.exist? }
24
- let(:sample_path) { tmp_path.join("sample") }
25
- let(:sample_metadata) do
26
- Helpers.strip_heredoc(<<-METADATA)
27
- version "0.6.5"
28
- METADATA
29
- end
30
-
31
- let(:api_url) { "http://site.cookbooks.com" }
32
-
33
- let(:sample_index_data) do
34
- {
35
- "name" => "sample",
36
- "versions" => [
37
- "#{api_url}/cookbooks/sample/versions/0_6_5"
38
- ]
39
- }
40
- end
41
- let(:sample_0_6_5_data) do
42
- {
43
- "version" => "0.6.5",
44
- "file" => "#{api_url}/cookbooks/sample/versions/0_6_5/file.tar.gz"
45
- }
46
- end
47
- let(:sample_0_6_5_package) do
48
- s = StringIO.new
49
- z = Zlib::GzipWriter.new(s, Zlib::NO_COMPRESSION)
50
- t = Archive::Tar::Minitar::Output.new(z)
51
- t.tar.add_file_simple("sample/metadata.rb", :mode => 0700,
52
- :size => sample_metadata.bytesize){|io| io.write(sample_metadata)}
53
- t.close
54
- z.close unless z.closed?
55
- s.string
56
- end
57
-
58
- # depends on repo_path being defined in each context
59
- let(:env) { Environment.new(:project_path => repo_path) }
60
-
61
- before do
62
- stub_request(:get, "#{api_url}/cookbooks/sample").
63
- to_return(:body => JSON.dump(sample_index_data))
64
-
65
- stub_request(:get, "#{api_url}/cookbooks/sample/versions/0_6_5").
66
- to_return(:body => JSON.dump(sample_0_6_5_data))
67
-
68
- stub_request(:get, "#{api_url}/cookbooks/sample/versions/0_6_5/file.tar.gz").
69
- to_return(:body => sample_0_6_5_package)
70
- end
71
-
72
- after do
73
- WebMock.reset!
74
- end
75
-
76
- let(:repo_path) { tmp_path.join("methods") }
77
- before { repo_path.mkpath }
78
-
79
- describe "lint" do
80
- it "lints" do
81
- Librarian::Linter::SourceLinter.lint! described_class
82
- end
83
- end
84
-
85
- describe "class methods" do
86
-
87
- describe ".lock_name" do
88
- specify { described_class.lock_name.should == "SITE" }
89
- end
90
-
91
- describe ".from_spec_args" do
92
- it "gives the expected source" do
93
- args = { }
94
- source = described_class.from_spec_args(env, api_url, args)
95
- source.uri.should == api_url
96
- end
97
-
98
- it "raises on unexpected args" do
99
- args = {:k => 3}
100
- expect { described_class.from_spec_args(env, api_url, args) }.
101
- to raise_error Librarian::Error, "unrecognized options: k"
102
- end
103
- end
104
-
105
- describe ".from_lock_options" do
106
- it "gives the expected source" do
107
- options = {:remote => api_url}
108
- source = described_class.from_lock_options(env, options)
109
- source.uri.should == api_url
110
- end
111
-
112
- it "roundtrips" do
113
- options = {:remote => api_url}
114
- source = described_class.from_lock_options(env, options)
115
- source.to_lock_options.should == options
116
- end
117
- end
118
-
119
- end
120
-
121
- describe "instance methods" do
122
- let(:source) { described_class.new(env, api_url) }
123
-
124
- describe "#manifests" do
125
- it "gives a list of all manifests" do
126
- manifests = source.manifests("sample")
127
- manifests.should have(1).item
128
- manifest = manifests.first
129
- manifest.source.should be source
130
- manifest.version.should == Manifest::Version.new("0.6.5")
131
- manifest.dependencies.should be_empty
132
- end
133
- end
134
-
135
- describe "#fetch_version" do
136
- it "fetches the version based on extra" do
137
- extra = "#{api_url}/cookbooks/sample/versions/0_6_5"
138
- source.fetch_version("sample", extra).should == "0.6.5"
139
- end
140
- end
141
-
142
- describe "#fetch_dependencies" do
143
- it "fetches the dependencies based on extra" do
144
- extra = "#{api_url}/cookbooks/sample/versions/0_6_5"
145
- source.fetch_dependencies("sample", "0.6.5", extra).should == [ ]
146
- end
147
- end
148
-
149
- describe "#pinned?" do
150
- it "returns false" do
151
- source.should_not be_pinned
152
- end
153
- end
154
-
155
- describe "#unpin!" do
156
- it "is a no-op" do
157
- source.unpin!
158
- end
159
- end
160
-
161
- describe "#install!" do
162
- before { env.install_path.mkpath }
163
-
164
- context "directly" do
165
- it "installs the manifest" do
166
- manifest = Manifest.new(source, "sample")
167
- manifest.version = "0.6.5"
168
- source.install!(manifest)
169
- text = env.install_path.join("sample/metadata.rb").read
170
- text.should == sample_metadata
171
- end
172
- end
173
-
174
- context "indirectly" do
175
- it "installs the manifest" do
176
- manifest = source.manifests("sample").first
177
- source.install!(manifest)
178
- text = env.install_path.join("sample/metadata.rb").read
179
- text.should == sample_metadata
180
- end
181
- end
182
- end
183
-
184
- describe "#to_spec_args" do
185
- it "gives the expected spec args" do
186
- source.to_spec_args.should == [api_url, { }]
187
- end
188
- end
189
-
190
- describe "#to_lock_options" do
191
- it "gives the expected lock options" do
192
- source.to_lock_options.should == {:remote => api_url}
193
- end
194
-
195
- it "roundtrips" do
196
- options = source.to_lock_options
197
- described_class.from_lock_options(env, options).should == source
198
- end
199
- end
200
-
201
- end
202
-
203
- describe "following http redirects" do
204
- let(:source) { described_class.new(env, api_url) }
205
-
206
- def redirect_to(url)
207
- {:status => 302, :headers => {"Location" => url}}
208
- end
209
-
210
- context "with a sequence of http redirects" do
211
- before do
212
- stub_request(:get, "#{api_url}/cookbooks/sample").
213
- to_return redirect_to "#{api_url}/cookbooks/sample-1"
214
- stub_request(:get, "#{api_url}/cookbooks/sample-1").
215
- to_return redirect_to "#{api_url}/cookbooks/sample-2"
216
- stub_request(:get, "#{api_url}/cookbooks/sample-2").
217
- to_return(:body => JSON.dump(sample_index_data))
218
- end
219
-
220
- it "follows a sequence of redirects" do
221
- manifest = source.manifests("sample").first
222
- manifest.version.to_s.should == "0.6.5"
223
- end
224
- end
225
-
226
- context "with too many http redirects" do
227
- before do
228
- stub_request(:get, "#{api_url}/cookbooks/sample").
229
- to_return redirect_to "#{api_url}/cookbooks/sample-1"
230
- (1 .. 11).each do |i|
231
- stub_request(:get, "#{api_url}/cookbooks/sample-#{i}").
232
- to_return redirect_to "#{api_url}/cookbooks/sample-#{i + 1}"
233
- end
234
- stub_request(:get, "#{api_url}/cookbooks/sample-12").
235
- to_return(:body => JSON.dump(sample_index_data))
236
- end
237
-
238
- it "raises, warning of too many redirects" do
239
- expect { source.manifests("sample").first }.
240
- to raise_error Librarian::Error, /because too many redirects!/
241
- end
242
- end
243
-
244
- context "with a redirect cycle" do
245
- before do
246
- stub_request(:get, "#{api_url}/cookbooks/sample").
247
- to_return redirect_to "#{api_url}/cookbooks/sample-1"
248
- (1 .. 8).each do |i|
249
- stub_request(:get, "#{api_url}/cookbooks/sample-#{i}").
250
- to_return redirect_to "#{api_url}/cookbooks/sample-#{i + 1}"
251
- end
252
- stub_request(:get, "#{api_url}/cookbooks/sample-9").
253
- to_return redirect_to "#{api_url}/cookbooks/sample-6"
254
- end
255
-
256
- it "raises, warning of a redirect cycle" do
257
- expect { source.manifests("sample").first }.
258
- to raise_error Librarian::Error, /because redirect cycle!/
259
- end
260
- end
261
- end
262
-
263
- end
264
- end
265
- end
266
- end