minimart 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +21 -0
- data/.rspec +3 -0
- data/.travis.yml +13 -0
- data/Gemfile +3 -0
- data/README.md +198 -0
- data/Rakefile +45 -0
- data/bin/minimart +4 -0
- data/lib/minimart.rb +15 -0
- data/lib/minimart/cli.rb +93 -0
- data/lib/minimart/commands/mirror.rb +30 -0
- data/lib/minimart/commands/web.rb +91 -0
- data/lib/minimart/configuration.rb +46 -0
- data/lib/minimart/cookbook.rb +173 -0
- data/lib/minimart/download/cookbook.rb +70 -0
- data/lib/minimart/download/git_cache.rb +60 -0
- data/lib/minimart/download/git_repository.rb +41 -0
- data/lib/minimart/error.rb +32 -0
- data/lib/minimart/inventory_requirement/base_requirement.rb +81 -0
- data/lib/minimart/inventory_requirement/git_requirement.rb +87 -0
- data/lib/minimart/inventory_requirement/git_requirements_builder.rb +101 -0
- data/lib/minimart/inventory_requirement/local_path_requirement.rb +45 -0
- data/lib/minimart/inventory_requirement/local_requirements_builder.rb +31 -0
- data/lib/minimart/inventory_requirement/supermarket_requirements_builder.rb +35 -0
- data/lib/minimart/mirror.rb +12 -0
- data/lib/minimart/mirror/dependency_graph.rb +73 -0
- data/lib/minimart/mirror/download_metadata.rb +57 -0
- data/lib/minimart/mirror/inventory_builder.rb +143 -0
- data/lib/minimart/mirror/inventory_configuration.rb +74 -0
- data/lib/minimart/mirror/inventory_requirements.rb +104 -0
- data/lib/minimart/mirror/local_store.rb +107 -0
- data/lib/minimart/mirror/source.rb +57 -0
- data/lib/minimart/mirror/source_cookbook.rb +77 -0
- data/lib/minimart/mirror/sources.rb +37 -0
- data/lib/minimart/output.rb +34 -0
- data/lib/minimart/utils/archive.rb +39 -0
- data/lib/minimart/utils/file_helper.rb +34 -0
- data/lib/minimart/utils/http.rb +60 -0
- data/lib/minimart/version.rb +3 -0
- data/lib/minimart/web.rb +10 -0
- data/lib/minimart/web/cookbook_show_page_generator.rb +78 -0
- data/lib/minimart/web/cookbooks.rb +83 -0
- data/lib/minimart/web/dashboard_generator.rb +46 -0
- data/lib/minimart/web/html_generator.rb +52 -0
- data/lib/minimart/web/markdown_parser.rb +47 -0
- data/lib/minimart/web/template_helper.rb +132 -0
- data/lib/minimart/web/universe_generator.rb +109 -0
- data/minimart.gemspec +36 -0
- data/spec/fixtures/sample_cookbook.tar.gz +0 -0
- data/spec/fixtures/sample_cookbook/Berksfile +3 -0
- data/spec/fixtures/sample_cookbook/CHANGELOG.md +3 -0
- data/spec/fixtures/sample_cookbook/Gemfile +16 -0
- data/spec/fixtures/sample_cookbook/LICENSE +3 -0
- data/spec/fixtures/sample_cookbook/README.md +42 -0
- data/spec/fixtures/sample_cookbook/Thorfile +5 -0
- data/spec/fixtures/sample_cookbook/Vagrantfile +90 -0
- data/spec/fixtures/sample_cookbook/chefignore +94 -0
- data/spec/fixtures/sample_cookbook/metadata.rb +9 -0
- data/spec/fixtures/sample_cookbook/recipes/default.rb +8 -0
- data/spec/fixtures/sample_inventory.yml +16 -0
- data/spec/fixtures/simple_git_inventory.yml +8 -0
- data/spec/fixtures/simple_inventory.yml +6 -0
- data/spec/fixtures/simple_local_path_inventory.yml +5 -0
- data/spec/fixtures/universe.json +42 -0
- data/spec/fixtures/vcr_cassettes/local_path_cookbooks.yml +3316 -0
- data/spec/fixtures/vcr_cassettes/location_specific_cookbooks.yml +3316 -0
- data/spec/fixtures/vcr_cassettes/supermarket_cookbooks_graph.yml +905 -0
- data/spec/fixtures/vcr_cassettes/supermarket_cookbooks_installing_cookbooks.yml +4218 -0
- data/spec/lib/minimart/cli_spec.rb +104 -0
- data/spec/lib/minimart/commands/mirror_spec.rb +37 -0
- data/spec/lib/minimart/commands/web_spec.rb +75 -0
- data/spec/lib/minimart/configuration_spec.rb +54 -0
- data/spec/lib/minimart/cookbook_spec.rb +137 -0
- data/spec/lib/minimart/download/cookbook_spec.rb +135 -0
- data/spec/lib/minimart/download/git_cache_spec.rb +69 -0
- data/spec/lib/minimart/download/git_repository_spec.rb +39 -0
- data/spec/lib/minimart/error_spec.rb +18 -0
- data/spec/lib/minimart/inventory_requirement/base_requirement_spec.rb +38 -0
- data/spec/lib/minimart/inventory_requirement/git_requirement_spec.rb +92 -0
- data/spec/lib/minimart/inventory_requirement/git_requirements_builder_spec.rb +130 -0
- data/spec/lib/minimart/inventory_requirement/local_path_requirement_spec.rb +35 -0
- data/spec/lib/minimart/inventory_requirement/local_requirements_builder_spec.rb +33 -0
- data/spec/lib/minimart/inventory_requirement/supermarket_requirements_builder_spec.rb +69 -0
- data/spec/lib/minimart/mirror/dependency_graph_spec.rb +123 -0
- data/spec/lib/minimart/mirror/download_metadata_spec.rb +73 -0
- data/spec/lib/minimart/mirror/inventory_builder_spec.rb +195 -0
- data/spec/lib/minimart/mirror/inventory_configuration_spec.rb +86 -0
- data/spec/lib/minimart/mirror/inventory_requirements_spec.rb +78 -0
- data/spec/lib/minimart/mirror/local_store_spec.rb +64 -0
- data/spec/lib/minimart/mirror/source_spec.rb +54 -0
- data/spec/lib/minimart/mirror/sources_spec.rb +50 -0
- data/spec/lib/minimart/output_spec.rb +29 -0
- data/spec/lib/minimart/utils/archive_spec.rb +38 -0
- data/spec/lib/minimart/utils/file_helper_spec.rb +43 -0
- data/spec/lib/minimart/utils/http_spec.rb +37 -0
- data/spec/lib/minimart/web/cookbook_show_page_generator_spec.rb +101 -0
- data/spec/lib/minimart/web/cookbooks_spec.rb +70 -0
- data/spec/lib/minimart/web/dashboard_generator_spec.rb +33 -0
- data/spec/lib/minimart/web/html_generator_spec.rb +34 -0
- data/spec/lib/minimart/web/markdown_parser_spec.rb +54 -0
- data/spec/lib/minimart/web/template_helper_spec.rb +86 -0
- data/spec/lib/minimart/web/universe_generator_spec.rb +125 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/file_system.rb +22 -0
- data/web/_assets/javascripts/app.js +164 -0
- data/web/_assets/javascripts/backbone.min.js +6 -0
- data/web/_assets/javascripts/jquery.min.js +4 -0
- data/web/_assets/javascripts/jquery.tabslet.min.js +9 -0
- data/web/_assets/javascripts/manifest.js +5 -0
- data/web/_assets/javascripts/underscore.min.js +5 -0
- data/web/_assets/stylesheets/font-awesome.min.css +4 -0
- data/web/_assets/stylesheets/font-mfizz.css +318 -0
- data/web/_assets/stylesheets/main.css +720 -0
- data/web/_assets/stylesheets/manifest.css +4 -0
- data/web/_assets/stylesheets/normalize.css +427 -0
- data/web/assets/fonts/FontAwesome.otf +0 -0
- data/web/assets/fonts/font-mfizz.eot +0 -0
- data/web/assets/fonts/font-mfizz.svg +1344 -0
- data/web/assets/fonts/font-mfizz.ttf +0 -0
- data/web/assets/fonts/font-mfizz.woff +0 -0
- data/web/assets/fonts/fontawesome-webfont.eot +0 -0
- data/web/assets/fonts/fontawesome-webfont.svg +520 -0
- data/web/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/web/assets/fonts/fontawesome-webfont.woff +0 -0
- data/web/assets/images/header-slim.jpg +0 -0
- data/web/assets/images/icon-search.png +0 -0
- data/web/assets/images/mad-glory-logo.png +0 -0
- data/web/assets/images/main-gradient.png +0 -0
- data/web/assets/images/top-bar-logo.png +0 -0
- data/web/assets/javascripts/application.min.js +5 -0
- data/web/assets/stylesheets/application.min.css +4 -0
- data/web/templates/cookbook_show.erb +96 -0
- data/web/templates/dashboard.erb +81 -0
- data/web/templates/layout.erb +38 -0
- metadata +433 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'minimart/cli'
|
3
|
+
|
4
|
+
describe Minimart::Cli do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@pwd = Dir.pwd
|
8
|
+
Dir.chdir(test_directory)
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) { Dir.chdir(@pwd) }
|
12
|
+
|
13
|
+
describe '#init' do
|
14
|
+
context 'when a config file option is provided' do
|
15
|
+
it 'should create the file' do
|
16
|
+
Minimart::Cli.start %w[init --inventory_config=./test-file.yml]
|
17
|
+
expect(File.exists?('./test-file.yml')).to eq true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should create the default inventory file' do
|
22
|
+
Minimart::Cli.start %w[init]
|
23
|
+
expect(File.exists?('./inventory.yml')).to eq true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#mirror' do
|
28
|
+
let(:command_double) { instance_double(Minimart::Commands::Mirror, execute!: true) }
|
29
|
+
|
30
|
+
it 'should call the mirroring command with the proper options' do
|
31
|
+
expect(Minimart::Commands::Mirror).to receive(:new).with(
|
32
|
+
'inventory_config' => './inventory.yml',
|
33
|
+
'inventory_directory' => './inventory').and_return command_double
|
34
|
+
|
35
|
+
Minimart::Cli.start %w[mirror]
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should allow users to override the default settings' do
|
39
|
+
expect(Minimart::Commands::Mirror).to receive(:new).with(
|
40
|
+
'inventory_config' => './my-test.yml',
|
41
|
+
'inventory_directory' => './test-dir').and_return command_double
|
42
|
+
|
43
|
+
Minimart::Cli.start %w[mirror --inventory_config=./my-test.yml --inventory_directory=./test-dir]
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when an error is raised' do
|
47
|
+
before(:each) do
|
48
|
+
allow_any_instance_of(Minimart::Commands::Mirror).to receive(:execute!).and_raise Minimart::Error::BaseError
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should handle the error' do
|
52
|
+
expect(Minimart::Error).to receive(:handle_exception)
|
53
|
+
|
54
|
+
Minimart::Cli.start %w[mirror --inventory_config=./my-test.yml --inventory_directory=./test-dir]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#web' do
|
60
|
+
let(:command_double) { instance_double(Minimart::Commands::Web, execute!: true) }
|
61
|
+
|
62
|
+
it 'should call the web command with the proper arguments' do
|
63
|
+
expect(Minimart::Commands::Web).to receive(:new).with(
|
64
|
+
'web_directory' => './web',
|
65
|
+
'inventory_directory' => './inventory',
|
66
|
+
'host' => 'http://example.com',
|
67
|
+
'html' => true).and_return command_double
|
68
|
+
|
69
|
+
Minimart::Cli.start %w[web --host=http://example.com]
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should allow users to override defaults' do
|
73
|
+
expect(Minimart::Commands::Web).to receive(:new).with(
|
74
|
+
'web_directory' => './my-web',
|
75
|
+
'inventory_directory' => './my-inventory',
|
76
|
+
'host' => 'http://example.com',
|
77
|
+
'html' => false).and_return command_double
|
78
|
+
|
79
|
+
Minimart::Cli.start %w[
|
80
|
+
web
|
81
|
+
--host=http://example.com
|
82
|
+
--web-directory=./my-web
|
83
|
+
--inventory-directory=./my-inventory
|
84
|
+
--no-html]
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when an error is raised' do
|
88
|
+
before(:each) do
|
89
|
+
allow_any_instance_of(Minimart::Commands::Web).to receive(:execute!).and_raise Minimart::Error::BaseError
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should handle the error' do
|
93
|
+
expect(Minimart::Error).to receive(:handle_exception)
|
94
|
+
|
95
|
+
Minimart::Cli.start %w[
|
96
|
+
web
|
97
|
+
--host=http://example.com
|
98
|
+
--web-directory=./my-web
|
99
|
+
--inventory-directory=./my-inventory
|
100
|
+
--no-html]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'minimart/commands/mirror'
|
3
|
+
|
4
|
+
describe Minimart::Commands::Mirror do
|
5
|
+
|
6
|
+
let(:inventory_directory) { './inventory' }
|
7
|
+
let(:inventory_config_path) { 'spec/fixtures/sample_inventory.yml' }
|
8
|
+
|
9
|
+
subject do
|
10
|
+
Minimart::Commands::Mirror.new(
|
11
|
+
inventory_directory: inventory_directory,
|
12
|
+
inventory_config: inventory_config_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '::new' do
|
16
|
+
it 'should set the inventory directory' do
|
17
|
+
expect(subject.inventory_directory).to eq inventory_directory
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should build an inventory config' do
|
21
|
+
expect(subject.inventory_config).to be_a Minimart::Mirror::InventoryConfiguration
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should pass the inventory config file path' do
|
25
|
+
expect(subject.inventory_config.inventory_config_path).to eq inventory_config_path
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '::execute' do
|
30
|
+
let(:builder) { double('builder', build!: nil) }
|
31
|
+
|
32
|
+
it 'should build an inventory' do
|
33
|
+
expect(Minimart::Mirror::InventoryBuilder).to receive(:new).and_return builder
|
34
|
+
subject.execute!
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'minimart/commands/web'
|
3
|
+
|
4
|
+
describe Minimart::Commands::Web do
|
5
|
+
|
6
|
+
let(:inventory_directory) { File.join(test_directory, 'my-inventory') }
|
7
|
+
let(:web_directory) { File.join(test_directory, 'my-site') }
|
8
|
+
let(:endpoint) { 'http://example.com' }
|
9
|
+
|
10
|
+
subject do
|
11
|
+
Minimart::Commands::Web.new(
|
12
|
+
inventory_directory: inventory_directory,
|
13
|
+
web_directory: web_directory,
|
14
|
+
host: endpoint)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '::new' do
|
18
|
+
it 'should set the inventory directory' do
|
19
|
+
expect(subject.inventory_directory).to eq File.expand_path(inventory_directory)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should set the web directory' do
|
23
|
+
expect(subject.web_directory).to eq File.expand_path(web_directory)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should set the web endpoint' do
|
27
|
+
expect(subject.web_endpoint).to eq endpoint
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#execute!' do
|
32
|
+
let(:generator_double) { double('generator', generate: true) }
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
allow_any_instance_of(Minimart::Web::UniverseGenerator).to receive(:generate)
|
36
|
+
allow_any_instance_of(Minimart::Web::HtmlGenerator).to receive(:generate)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should make the web directory' do
|
40
|
+
subject.execute!
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should generate the universe.json file' do
|
44
|
+
expect(Minimart::Web::UniverseGenerator).to receive(:new).with(
|
45
|
+
web_directory: subject.web_directory,
|
46
|
+
endpoint: subject.web_endpoint,
|
47
|
+
cookbooks: an_instance_of(Minimart::Web::Cookbooks)).and_return generator_double
|
48
|
+
|
49
|
+
subject.execute!
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should generate the static HTML files' do
|
53
|
+
expect(Minimart::Web::HtmlGenerator).to receive(:new).with(
|
54
|
+
web_directory: subject.web_directory,
|
55
|
+
cookbooks: an_instance_of(Minimart::Web::Cookbooks)).and_return generator_double
|
56
|
+
|
57
|
+
subject.execute!
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when the user disable html generation' do
|
61
|
+
subject do
|
62
|
+
Minimart::Commands::Web.new(
|
63
|
+
html: false,
|
64
|
+
inventory_directory: inventory_directory,
|
65
|
+
web_directory: web_directory,
|
66
|
+
web_endpoint: endpoint)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should not execute the html generator' do
|
70
|
+
expect(Minimart::Web::HtmlGenerator).to_not receive(:new)
|
71
|
+
subject.execute!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Minimart::Configuration do
|
4
|
+
|
5
|
+
describe '#output' do
|
6
|
+
subject { Minimart::Configuration.output }
|
7
|
+
it { is_expected.to be_a Minimart::Output }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#chef_server_config' do
|
11
|
+
subject { Minimart::Configuration.chef_server_config }
|
12
|
+
it { is_expected.to eq({ssl: {verify: true}}) }
|
13
|
+
|
14
|
+
context 'when a value is set' do
|
15
|
+
let(:conf) { {'client_name' => 'berkshelf', 'client_key' => 'key_path'} }
|
16
|
+
|
17
|
+
before(:each) { Minimart::Configuration.chef_server_config = conf }
|
18
|
+
after(:each) { Minimart::Configuration.chef_server_config = nil }
|
19
|
+
|
20
|
+
it { is_expected.to include conf }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#github_config' do
|
25
|
+
subject { Minimart::Configuration.github_config }
|
26
|
+
it { is_expected.to eq({:connection_options=>{:ssl=>{:verify=>true}}}) }
|
27
|
+
|
28
|
+
context 'when a value is set' do
|
29
|
+
let(:conf) { {'organization' => 'org', 'api_endpoint' => 'api'} }
|
30
|
+
|
31
|
+
before(:each) { Minimart::Configuration.github_config = conf }
|
32
|
+
after(:each) { Minimart::Configuration.github_config = nil }
|
33
|
+
|
34
|
+
it { is_expected.to include conf }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#verify_ssl' do
|
39
|
+
after(:each) { Minimart::Configuration.verify_ssl = nil }
|
40
|
+
|
41
|
+
subject { Minimart::Configuration.verify_ssl }
|
42
|
+
it { is_expected.to eq true }
|
43
|
+
|
44
|
+
context 'when set to false' do
|
45
|
+
subject { Minimart::Configuration.verify_ssl = false }
|
46
|
+
it { is_expected.to eq false }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when set to true' do
|
50
|
+
subject { Minimart::Configuration.verify_ssl = true }
|
51
|
+
it { is_expected.to eq true }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Minimart::Cookbook do
|
4
|
+
|
5
|
+
let(:cookbook) do
|
6
|
+
Minimart::Cookbook.from_path('spec/fixtures/sample_cookbook')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#name' do
|
10
|
+
subject { cookbook.name }
|
11
|
+
it { is_expected.to eq 'sample_cookbook' }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#version' do
|
15
|
+
subject { cookbook.version }
|
16
|
+
it { is_expected.to eq '1.2.3' }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#to_s' do
|
20
|
+
subject { cookbook.to_s }
|
21
|
+
it { is_expected.to eq 'sample_cookbook-1.2.3' }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#description' do
|
25
|
+
subject { cookbook.description }
|
26
|
+
it { is_expected.to eq 'Installs/Configures sample_cookbook' }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#maintainer' do
|
30
|
+
subject { cookbook.maintainer }
|
31
|
+
it { is_expected.to eq 'MadGlory' }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#path' do
|
35
|
+
subject { cookbook.path }
|
36
|
+
it { is_expected.to eq Pathname.new('spec/fixtures/sample_cookbook') }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#web_friendly_version' do
|
40
|
+
subject { cookbook.web_friendly_version }
|
41
|
+
it { is_expected.to eq '1_2_3' }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#dependencies' do
|
45
|
+
subject { cookbook.dependencies }
|
46
|
+
it { is_expected.to eq('yum' => '> 3.0.0') }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#readme_file' do
|
50
|
+
subject { cookbook.readme_file }
|
51
|
+
it { is_expected.to eq 'spec/fixtures/sample_cookbook/README.md' }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#changelog_file' do
|
55
|
+
subject { cookbook.changelog_file }
|
56
|
+
it { is_expected.to eq 'spec/fixtures/sample_cookbook/CHANGELOG.md' }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#readme_content' do
|
60
|
+
it 'should use the markdown parser to parse the readme content' do
|
61
|
+
expect(Minimart::Web::MarkdownParser).to receive(:parse).with('spec/fixtures/sample_cookbook/README.md')
|
62
|
+
cookbook.readme_content
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#changelog_content' do
|
67
|
+
it 'should use the markdown parser to parse the changelog content' do
|
68
|
+
expect(Minimart::Web::MarkdownParser).to receive(:parse).with('spec/fixtures/sample_cookbook/CHANGELOG.md')
|
69
|
+
cookbook.changelog_content
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#to_json' do
|
74
|
+
subject { JSON.parse(cookbook.to_json) }
|
75
|
+
|
76
|
+
it do
|
77
|
+
is_expected.to include(
|
78
|
+
'name' => 'sample_cookbook',
|
79
|
+
'version' => '1.2.3',
|
80
|
+
'description' => 'Installs/Configures sample_cookbook',
|
81
|
+
'maintainer' => 'MadGlory',
|
82
|
+
'download_url' => 'cookbook_files/sample_cookbook/1_2_3/sample_cookbook-1.2.3.tar.gz',
|
83
|
+
'url' => 'cookbooks/sample_cookbook/1.2.3.html')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#satisfies_requirement?' do
|
88
|
+
context 'when the cookbook satisfies the requirement' do
|
89
|
+
subject { cookbook.satisfies_requirement?('~> 1.2.0') }
|
90
|
+
it { is_expected.to eq true }
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when the cookbook does not satisfy the requirement' do
|
94
|
+
subject { cookbook.satisfies_requirement?('>= 2.0.0') }
|
95
|
+
it { is_expected.to eq false }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#downloaded_at' do
|
100
|
+
let(:path) { File.join(test_directory, 'sample_cookbook') }
|
101
|
+
let(:cookbook) { Minimart::Cookbook.from_path(path) }
|
102
|
+
let(:metadata) { Minimart::Mirror::DownloadMetadata.new(cookbook.path) }
|
103
|
+
|
104
|
+
before(:each) do
|
105
|
+
FileUtils.cp_r('spec/fixtures/sample_cookbook', path)
|
106
|
+
metadata.write
|
107
|
+
end
|
108
|
+
|
109
|
+
subject { cookbook.downloaded_at }
|
110
|
+
|
111
|
+
it { is_expected.to eq metadata.downloaded_at }
|
112
|
+
it { is_expected.to be_a Time }
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#download_date' do
|
116
|
+
let(:date) { Time.new(2001, 06, 01) }
|
117
|
+
|
118
|
+
before(:each) do
|
119
|
+
allow_any_instance_of(Minimart::Mirror::DownloadMetadata).to receive(:downloaded_at).and_return date
|
120
|
+
end
|
121
|
+
|
122
|
+
subject { cookbook.download_date }
|
123
|
+
|
124
|
+
it { is_expected.to eq 'June 01, 2001' }
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#normalized_platforms' do
|
128
|
+
subject { cookbook.normalized_platforms }
|
129
|
+
it { is_expected.to eq('question' => 'Not Specified') }
|
130
|
+
|
131
|
+
context 'when the cookbook has platforms' do
|
132
|
+
before(:each) { allow(cookbook).to receive(:platforms).and_return %w[amazon] }
|
133
|
+
it { is_expected.to eq('aws' => 'Amazon') }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Minimart::Download::Cookbook do
|
4
|
+
|
5
|
+
let(:archive) { File.open('spec/fixtures/sample_cookbook.tar.gz') }
|
6
|
+
|
7
|
+
let(:cookbook) do
|
8
|
+
Minimart::Mirror::SourceCookbook.new(
|
9
|
+
location_type: 'opscode',
|
10
|
+
location_path: 'http://supermarket.chef.io',
|
11
|
+
name: 'sample',
|
12
|
+
version: '0.1.0',
|
13
|
+
web_friendly_version: '0_1_0')
|
14
|
+
end
|
15
|
+
|
16
|
+
subject do
|
17
|
+
Minimart::Download::Cookbook.new(cookbook)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '::fetch' do
|
21
|
+
context 'when the location type provided is not recognized' do
|
22
|
+
let(:cookbook) do
|
23
|
+
Minimart::Mirror::SourceCookbook.new('location_type' => 'not-real')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise an error' do
|
27
|
+
expect {
|
28
|
+
subject.fetch
|
29
|
+
}.to raise_error Minimart::Error::UnknownLocationType
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'supermarket cookbook' do
|
34
|
+
let(:url) { 'http://supermarket.chef.io/cookbooks/sample/versions/0_1_0' }
|
35
|
+
let(:file_path) { "#{url}.tar.gz" }
|
36
|
+
|
37
|
+
let!(:details_request) do
|
38
|
+
stub_request(:get, url).to_return(status: 200, body: {file: file_path}.to_json)
|
39
|
+
end
|
40
|
+
|
41
|
+
let!(:file_request) do
|
42
|
+
stub_request(:get, file_path).to_return(status: 200, body: archive)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should request the file location' do
|
46
|
+
subject.fetch
|
47
|
+
expect(details_request).to have_been_requested
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should actually download the file' do
|
51
|
+
subject.fetch
|
52
|
+
expect(file_request).to have_been_requested
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should extract the downloaded archive' do
|
56
|
+
expect(Minimart::Utils::Archive).to receive(:extract_archive)
|
57
|
+
subject.fetch
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'uri cookbook' do
|
62
|
+
let!(:request) do
|
63
|
+
stub_request(:get, cookbook.location_path).to_return(status: 200, body: archive)
|
64
|
+
end
|
65
|
+
|
66
|
+
before(:each) { cookbook.location_type = 'uri' }
|
67
|
+
|
68
|
+
it 'should download the archive' do
|
69
|
+
subject.fetch
|
70
|
+
expect(request).to have_been_requested
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should extract the archive' do
|
74
|
+
expect(Minimart::Utils::Archive).to receive(:extract_archive)
|
75
|
+
subject.fetch
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'chef server cookbook' do
|
80
|
+
let(:conf) { {'client_name' => 'berkshelf', 'client_key' => 'key_path'} }
|
81
|
+
|
82
|
+
let(:chef_connection) do
|
83
|
+
double('connection', cookbook: double('cookbook', download: true))
|
84
|
+
end
|
85
|
+
|
86
|
+
before(:each) do
|
87
|
+
Minimart::Configuration.chef_server_config = conf
|
88
|
+
cookbook.location_type = 'chef_server'
|
89
|
+
end
|
90
|
+
|
91
|
+
after(:each) { Minimart::Configuration.chef_server_config = {} }
|
92
|
+
|
93
|
+
it 'should download the cookbook using Ridley' do
|
94
|
+
expect(Ridley).to receive(:open).
|
95
|
+
with(conf.merge(server_url: 'http://supermarket.chef.io', ssl: {verify: true})).
|
96
|
+
and_yield chef_connection
|
97
|
+
|
98
|
+
subject.fetch
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'github cookbook' do
|
103
|
+
let(:conf) { {'organization' => 'org', 'api_endpoint' => 'api'} }
|
104
|
+
let(:url) { 'http://github.com/org/my_repo' }
|
105
|
+
let(:archive_url) { "#{url}.tar.gz" }
|
106
|
+
|
107
|
+
let!(:file_request) do
|
108
|
+
stub_request(:get, archive_url).to_return(status: 200, body: archive)
|
109
|
+
end
|
110
|
+
|
111
|
+
before(:each) do
|
112
|
+
Minimart::Configuration.github_config = conf
|
113
|
+
cookbook.location_type = 'github'
|
114
|
+
cookbook.location_path = url
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
after(:each) { Minimart::Configuration.github_config = nil }
|
119
|
+
|
120
|
+
it 'should build the client with the proper options' do
|
121
|
+
expect(Octokit::Client).to receive(:new).with(conf.merge(connection_options: {ssl: {verify: true}})).and_call_original
|
122
|
+
allow_any_instance_of(Octokit::Client).to receive(:archive_link).and_return archive_url
|
123
|
+
subject.fetch
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should download the cookbook using octokit' do
|
127
|
+
expect_any_instance_of(Octokit::Client).to receive(:archive_link).
|
128
|
+
with('org/my_repo', ref: 'v0.1.0').
|
129
|
+
and_return(archive_url)
|
130
|
+
subject.fetch
|
131
|
+
expect(file_request).to have_been_requested
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|