minimart 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +3 -0
  6. data/README.md +198 -0
  7. data/Rakefile +45 -0
  8. data/bin/minimart +4 -0
  9. data/lib/minimart.rb +15 -0
  10. data/lib/minimart/cli.rb +93 -0
  11. data/lib/minimart/commands/mirror.rb +30 -0
  12. data/lib/minimart/commands/web.rb +91 -0
  13. data/lib/minimart/configuration.rb +46 -0
  14. data/lib/minimart/cookbook.rb +173 -0
  15. data/lib/minimart/download/cookbook.rb +70 -0
  16. data/lib/minimart/download/git_cache.rb +60 -0
  17. data/lib/minimart/download/git_repository.rb +41 -0
  18. data/lib/minimart/error.rb +32 -0
  19. data/lib/minimart/inventory_requirement/base_requirement.rb +81 -0
  20. data/lib/minimart/inventory_requirement/git_requirement.rb +87 -0
  21. data/lib/minimart/inventory_requirement/git_requirements_builder.rb +101 -0
  22. data/lib/minimart/inventory_requirement/local_path_requirement.rb +45 -0
  23. data/lib/minimart/inventory_requirement/local_requirements_builder.rb +31 -0
  24. data/lib/minimart/inventory_requirement/supermarket_requirements_builder.rb +35 -0
  25. data/lib/minimart/mirror.rb +12 -0
  26. data/lib/minimart/mirror/dependency_graph.rb +73 -0
  27. data/lib/minimart/mirror/download_metadata.rb +57 -0
  28. data/lib/minimart/mirror/inventory_builder.rb +143 -0
  29. data/lib/minimart/mirror/inventory_configuration.rb +74 -0
  30. data/lib/minimart/mirror/inventory_requirements.rb +104 -0
  31. data/lib/minimart/mirror/local_store.rb +107 -0
  32. data/lib/minimart/mirror/source.rb +57 -0
  33. data/lib/minimart/mirror/source_cookbook.rb +77 -0
  34. data/lib/minimart/mirror/sources.rb +37 -0
  35. data/lib/minimart/output.rb +34 -0
  36. data/lib/minimart/utils/archive.rb +39 -0
  37. data/lib/minimart/utils/file_helper.rb +34 -0
  38. data/lib/minimart/utils/http.rb +60 -0
  39. data/lib/minimart/version.rb +3 -0
  40. data/lib/minimart/web.rb +10 -0
  41. data/lib/minimart/web/cookbook_show_page_generator.rb +78 -0
  42. data/lib/minimart/web/cookbooks.rb +83 -0
  43. data/lib/minimart/web/dashboard_generator.rb +46 -0
  44. data/lib/minimart/web/html_generator.rb +52 -0
  45. data/lib/minimart/web/markdown_parser.rb +47 -0
  46. data/lib/minimart/web/template_helper.rb +132 -0
  47. data/lib/minimart/web/universe_generator.rb +109 -0
  48. data/minimart.gemspec +36 -0
  49. data/spec/fixtures/sample_cookbook.tar.gz +0 -0
  50. data/spec/fixtures/sample_cookbook/Berksfile +3 -0
  51. data/spec/fixtures/sample_cookbook/CHANGELOG.md +3 -0
  52. data/spec/fixtures/sample_cookbook/Gemfile +16 -0
  53. data/spec/fixtures/sample_cookbook/LICENSE +3 -0
  54. data/spec/fixtures/sample_cookbook/README.md +42 -0
  55. data/spec/fixtures/sample_cookbook/Thorfile +5 -0
  56. data/spec/fixtures/sample_cookbook/Vagrantfile +90 -0
  57. data/spec/fixtures/sample_cookbook/chefignore +94 -0
  58. data/spec/fixtures/sample_cookbook/metadata.rb +9 -0
  59. data/spec/fixtures/sample_cookbook/recipes/default.rb +8 -0
  60. data/spec/fixtures/sample_inventory.yml +16 -0
  61. data/spec/fixtures/simple_git_inventory.yml +8 -0
  62. data/spec/fixtures/simple_inventory.yml +6 -0
  63. data/spec/fixtures/simple_local_path_inventory.yml +5 -0
  64. data/spec/fixtures/universe.json +42 -0
  65. data/spec/fixtures/vcr_cassettes/local_path_cookbooks.yml +3316 -0
  66. data/spec/fixtures/vcr_cassettes/location_specific_cookbooks.yml +3316 -0
  67. data/spec/fixtures/vcr_cassettes/supermarket_cookbooks_graph.yml +905 -0
  68. data/spec/fixtures/vcr_cassettes/supermarket_cookbooks_installing_cookbooks.yml +4218 -0
  69. data/spec/lib/minimart/cli_spec.rb +104 -0
  70. data/spec/lib/minimart/commands/mirror_spec.rb +37 -0
  71. data/spec/lib/minimart/commands/web_spec.rb +75 -0
  72. data/spec/lib/minimart/configuration_spec.rb +54 -0
  73. data/spec/lib/minimart/cookbook_spec.rb +137 -0
  74. data/spec/lib/minimart/download/cookbook_spec.rb +135 -0
  75. data/spec/lib/minimart/download/git_cache_spec.rb +69 -0
  76. data/spec/lib/minimart/download/git_repository_spec.rb +39 -0
  77. data/spec/lib/minimart/error_spec.rb +18 -0
  78. data/spec/lib/minimart/inventory_requirement/base_requirement_spec.rb +38 -0
  79. data/spec/lib/minimart/inventory_requirement/git_requirement_spec.rb +92 -0
  80. data/spec/lib/minimart/inventory_requirement/git_requirements_builder_spec.rb +130 -0
  81. data/spec/lib/minimart/inventory_requirement/local_path_requirement_spec.rb +35 -0
  82. data/spec/lib/minimart/inventory_requirement/local_requirements_builder_spec.rb +33 -0
  83. data/spec/lib/minimart/inventory_requirement/supermarket_requirements_builder_spec.rb +69 -0
  84. data/spec/lib/minimart/mirror/dependency_graph_spec.rb +123 -0
  85. data/spec/lib/minimart/mirror/download_metadata_spec.rb +73 -0
  86. data/spec/lib/minimart/mirror/inventory_builder_spec.rb +195 -0
  87. data/spec/lib/minimart/mirror/inventory_configuration_spec.rb +86 -0
  88. data/spec/lib/minimart/mirror/inventory_requirements_spec.rb +78 -0
  89. data/spec/lib/minimart/mirror/local_store_spec.rb +64 -0
  90. data/spec/lib/minimart/mirror/source_spec.rb +54 -0
  91. data/spec/lib/minimart/mirror/sources_spec.rb +50 -0
  92. data/spec/lib/minimart/output_spec.rb +29 -0
  93. data/spec/lib/minimart/utils/archive_spec.rb +38 -0
  94. data/spec/lib/minimart/utils/file_helper_spec.rb +43 -0
  95. data/spec/lib/minimart/utils/http_spec.rb +37 -0
  96. data/spec/lib/minimart/web/cookbook_show_page_generator_spec.rb +101 -0
  97. data/spec/lib/minimart/web/cookbooks_spec.rb +70 -0
  98. data/spec/lib/minimart/web/dashboard_generator_spec.rb +33 -0
  99. data/spec/lib/minimart/web/html_generator_spec.rb +34 -0
  100. data/spec/lib/minimart/web/markdown_parser_spec.rb +54 -0
  101. data/spec/lib/minimart/web/template_helper_spec.rb +86 -0
  102. data/spec/lib/minimart/web/universe_generator_spec.rb +125 -0
  103. data/spec/spec_helper.rb +35 -0
  104. data/spec/support/file_system.rb +22 -0
  105. data/web/_assets/javascripts/app.js +164 -0
  106. data/web/_assets/javascripts/backbone.min.js +6 -0
  107. data/web/_assets/javascripts/jquery.min.js +4 -0
  108. data/web/_assets/javascripts/jquery.tabslet.min.js +9 -0
  109. data/web/_assets/javascripts/manifest.js +5 -0
  110. data/web/_assets/javascripts/underscore.min.js +5 -0
  111. data/web/_assets/stylesheets/font-awesome.min.css +4 -0
  112. data/web/_assets/stylesheets/font-mfizz.css +318 -0
  113. data/web/_assets/stylesheets/main.css +720 -0
  114. data/web/_assets/stylesheets/manifest.css +4 -0
  115. data/web/_assets/stylesheets/normalize.css +427 -0
  116. data/web/assets/fonts/FontAwesome.otf +0 -0
  117. data/web/assets/fonts/font-mfizz.eot +0 -0
  118. data/web/assets/fonts/font-mfizz.svg +1344 -0
  119. data/web/assets/fonts/font-mfizz.ttf +0 -0
  120. data/web/assets/fonts/font-mfizz.woff +0 -0
  121. data/web/assets/fonts/fontawesome-webfont.eot +0 -0
  122. data/web/assets/fonts/fontawesome-webfont.svg +520 -0
  123. data/web/assets/fonts/fontawesome-webfont.ttf +0 -0
  124. data/web/assets/fonts/fontawesome-webfont.woff +0 -0
  125. data/web/assets/images/header-slim.jpg +0 -0
  126. data/web/assets/images/icon-search.png +0 -0
  127. data/web/assets/images/mad-glory-logo.png +0 -0
  128. data/web/assets/images/main-gradient.png +0 -0
  129. data/web/assets/images/top-bar-logo.png +0 -0
  130. data/web/assets/javascripts/application.min.js +5 -0
  131. data/web/assets/stylesheets/application.min.css +4 -0
  132. data/web/templates/cookbook_show.erb +96 -0
  133. data/web/templates/dashboard.erb +81 -0
  134. data/web/templates/layout.erb +38 -0
  135. metadata +433 -0
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Minimart::Utils::Http do
4
+ describe '::get_json' do
5
+ pending
6
+ end
7
+
8
+ describe '::get' do
9
+ pending
10
+ end
11
+
12
+ describe '::get_binary' do
13
+ pending
14
+ end
15
+
16
+ describe '::build_url' do
17
+ context 'when no protocol is provided' do
18
+ subject { described_class.build_url('example.com') }
19
+ it { is_expected.to eq 'http://example.com' }
20
+ end
21
+
22
+ context 'when a protocol is provided' do
23
+ subject { described_class.build_url('git://example.com') }
24
+ it { is_expected.to eq 'git://example.com' }
25
+ end
26
+
27
+ context 'when a sub url is provided' do
28
+ subject { described_class.build_url('http://example.com', 'path') }
29
+ it { is_expected.to eq 'http://example.com/path' }
30
+ end
31
+
32
+ context 'when the path has a leading slash' do
33
+ subject { described_class.build_url('http://example.com/', '/path') }
34
+ it { is_expected.to eq 'http://example.com/path' }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+ require 'minimart/web/cookbook_show_page_generator'
3
+
4
+ describe Minimart::Web::CookbookShowPageGenerator do
5
+ let(:cookbooks) do
6
+ Minimart::Web::Cookbooks.new(inventory_directory: 'spec/fixtures')
7
+ end
8
+
9
+ let(:web_directory) { test_directory }
10
+
11
+ subject do
12
+ Minimart::Web::CookbookShowPageGenerator.new(
13
+ web_directory: web_directory,
14
+ cookbooks: cookbooks)
15
+ end
16
+
17
+ describe '#generate' do
18
+ let(:cookbooks_directory) { File.join(web_directory, 'cookbooks') }
19
+ let(:cookbook_directory) { File.join(cookbooks_directory, 'sample_cookbook') }
20
+ let(:cookbook_file) { File.join(cookbook_directory, '1.2.3.html') }
21
+ let(:view_content) { File.open(cookbook_file).read }
22
+
23
+ it 'should generate a directory for the cookbook provided' do
24
+ subject.generate
25
+ expect(Dir.exists?(cookbook_directory)).to eq true
26
+ end
27
+
28
+ context 'when the web command was previously run' do
29
+ let(:cookbook_directory) { File.join(cookbooks_directory, 'existing-cookbook') }
30
+
31
+ before(:each) do
32
+ FileUtils.mkdir_p(cookbooks_directory)
33
+ FileUtils.mkdir_p(cookbook_directory)
34
+ end
35
+
36
+ it 'should remove any existing files' do
37
+ subject.generate
38
+ expect(Dir.exists?(cookbook_directory)).to eq false
39
+ end
40
+ end
41
+
42
+ it 'should generate an html file for the cookbook version' do
43
+ subject.generate
44
+ expect(File.exists?(cookbook_file)).to eq true
45
+ end
46
+
47
+ it 'should have a proper link back to the home page' do
48
+ subject.generate
49
+ expect(view_content).to match(%{href="../../index.html"})
50
+ end
51
+
52
+ it 'should have a form for the search action with the proper path' do
53
+ subject.generate
54
+ expect(view_content).to match(%{action="../../index.html#search/"})
55
+ end
56
+
57
+ it 'should have the proper relative path to any loaded assets' do
58
+ subject.generate
59
+ expect(view_content).to match %{href="../../assets/}
60
+ end
61
+
62
+ it 'should display the name of the cookbook' do
63
+ subject.generate
64
+ expect(view_content).to match 'sample_cookbook'
65
+ end
66
+
67
+ it 'should display the version of the cookbook' do
68
+ subject.generate
69
+ expect(view_content).to match '1.2.3'
70
+ end
71
+
72
+ it 'should display a link to download the cookbook' do
73
+ subject.generate
74
+ expect(view_content).to match %{href="../../cookbook_files/sample_cookbook/1_2_3/sample_cookbook-1.2.3.tar.gz"}
75
+ end
76
+
77
+ it 'should display any dependencies the cookbook has' do
78
+ subject.generate
79
+ expect(view_content).to match 'yum > 3.0.0'
80
+ end
81
+
82
+ context 'when minimart has the dependent cookbook' do
83
+ let(:yum) do
84
+ res = cookbooks.individual_cookbooks.first.dup
85
+ allow(res).to receive(:name).and_return('yum')
86
+ allow(res).to receive(:version).and_return('3.2.0')
87
+ res
88
+ end
89
+
90
+ before(:each) do
91
+ cookbooks.add(yum)
92
+ end
93
+
94
+ it 'should build a link for the dependent cookbook' do
95
+ subject.generate
96
+ expect(view_content).to match %{href="../../cookbooks/yum/3.2.0.html"}
97
+ end
98
+ end
99
+ end
100
+
101
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'minimart/web/cookbooks'
3
+
4
+ describe Minimart::Web::Cookbooks do
5
+
6
+ let(:inventory_directory) { 'spec/fixtures/' }
7
+ let(:data_path) { File.join(directory, 'data.json') }
8
+
9
+ subject do
10
+ Minimart::Web::Cookbooks.new(inventory_directory: inventory_directory)
11
+ end
12
+
13
+ describe '::new' do
14
+ it 'should set the #inventory_directory' do
15
+ expect(subject.inventory_directory).to eq inventory_directory
16
+ end
17
+
18
+ it 'should build a data structure with the proper cookbooks' do
19
+ expect(subject.keys).to include 'sample_cookbook'
20
+ end
21
+
22
+ it 'should load the cookbooks provided' do
23
+ expect(subject['sample_cookbook'].first).to be_a Minimart::Cookbook
24
+ end
25
+
26
+ context 'when there are multiple versions of the same cookbook' do
27
+ let(:cookbook_one) do
28
+ c = Minimart::Cookbook.new(nil)
29
+ allow(c).to receive(:name).and_return 'test-book'
30
+ allow(c).to receive(:version).and_return '1.9.0'
31
+ c
32
+ end
33
+
34
+ let(:cookbook_two) do
35
+ c = Minimart::Cookbook.new(nil)
36
+ allow(c).to receive(:name).and_return 'test-book'
37
+ allow(c).to receive(:version).and_return '1.19.0'
38
+ c
39
+ end
40
+
41
+ let(:cookbooks) { [cookbook_one, cookbook_two] }
42
+
43
+ before(:each) do
44
+ allow_any_instance_of(Minimart::Web::Cookbooks).to receive(:cookbooks).and_return cookbooks
45
+ end
46
+
47
+ it 'should load both cookbooks' do
48
+ expect(subject['test-book'].size).to eq 2
49
+ end
50
+
51
+ it 'should properly sort them in version descending order' do
52
+ expect(subject['test-book'][0].version).to eq '1.19.0'
53
+ expect(subject['test-book'][1].version).to eq '1.9.0'
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '::to_json' do
59
+ let(:result) { JSON.parse(subject.to_json) }
60
+
61
+ it 'should return the proper data structure as JSON' do
62
+ expect(result.first['name']).to eq 'sample_cookbook'
63
+ end
64
+
65
+ it 'should include the number of versions available' do
66
+ expect(result.first['available_versions']).to eq 1
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'minimart/web/dashboard_generator'
3
+
4
+ describe Minimart::Web::DashboardGenerator do
5
+ let(:cookbooks) do
6
+ Minimart::Web::Cookbooks.new(inventory_directory: 'spec/fixtures')
7
+ end
8
+
9
+ let(:web_directory) { test_directory }
10
+
11
+ subject do
12
+ Minimart::Web::DashboardGenerator.new(
13
+ web_directory: web_directory,
14
+ cookbooks: cookbooks)
15
+ end
16
+
17
+ describe '#generate' do
18
+ it 'should create an index.html file in the web directory' do
19
+ subject.generate
20
+ expect(File.exists?(File.join(web_directory, 'index.html'))).to eq true
21
+ end
22
+
23
+ it 'should have a proper link back to the home page' do
24
+ subject.generate
25
+ expect(subject.template_content).to match(%{href="index.html"})
26
+ end
27
+
28
+ it 'should have the proper relative path to any loaded assets' do
29
+ subject.generate
30
+ expect(subject.template_content).to match %{href="assets/}
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'minimart/web/html_generator'
3
+
4
+ describe Minimart::Web::HtmlGenerator do
5
+ let(:cookbooks) do
6
+ Minimart::Web::Cookbooks.new(inventory_directory: 'spec/fixtures')
7
+ end
8
+
9
+ let(:web_directory) { test_directory }
10
+
11
+ subject do
12
+ Minimart::Web::HtmlGenerator.new(
13
+ web_directory: web_directory,
14
+ cookbooks: cookbooks)
15
+ end
16
+
17
+ describe '#generate' do
18
+ it 'should copy any available assets' do
19
+ subject.generate
20
+ expect(Dir.exists?(File.join(web_directory, 'assets'))).to eq true
21
+ end
22
+
23
+ it 'should generate the dashboard page' do
24
+ expect_any_instance_of(Minimart::Web::DashboardGenerator).to receive(:generate)
25
+ subject.generate
26
+ end
27
+
28
+ it 'should generate show pages for any of the cookbooks' do
29
+ expect_any_instance_of(Minimart::Web::CookbookShowPageGenerator).to receive(:generate)
30
+ subject.generate
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Minimart::Web::MarkdownParser do
4
+
5
+ describe '::parse' do
6
+ context 'when the file does not have a markdown extension' do
7
+ let(:contents) { 'file contents here' }
8
+
9
+ let(:file) do
10
+ File.join(test_directory, 'readme.rdoc').tap do |file_name|
11
+ File.open(file_name, 'w+') { |f| f.write(contents) }
12
+ end
13
+ end
14
+
15
+ it 'should return the file contents' do
16
+ expect(Minimart::Web::MarkdownParser.parse(file)).to eq contents
17
+ end
18
+
19
+ it 'should not attempt to parse the file' do
20
+ expect(Minimart::Web::MarkdownParser).to_not receive(:new)
21
+ Minimart::Web::MarkdownParser.parse(file)
22
+ end
23
+ end
24
+
25
+ context 'when the file has a .md extension' do
26
+ let(:contents) { '# Title' }
27
+
28
+ let(:file) do
29
+ File.join(test_directory, 'readme.md').tap do |file_name|
30
+ File.open(file_name, 'w+') { |f| f.write(contents) }
31
+ end
32
+ end
33
+
34
+ it 'should parse the contents as markdown' do
35
+ expect(Minimart::Web::MarkdownParser.parse(file)).to match '<h1>Title</h1>'
36
+ end
37
+ end
38
+
39
+ context 'when the file has a .markdown extension' do
40
+ let(:contents) { '# Title' }
41
+
42
+ let(:file) do
43
+ File.join(test_directory, 'readme.markdown').tap do |file_name|
44
+ File.open(file_name, 'w+') { |f| f.write(contents) }
45
+ end
46
+ end
47
+
48
+ it 'should parse the contents as markdown' do
49
+ expect(Minimart::Web::MarkdownParser.parse(file)).to match '<h1>Title</h1>'
50
+ end
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Minimart::Web::TemplateHelper do
4
+ let(:klass) do
5
+ k = Class.new
6
+ k.extend(Minimart::Web::TemplateHelper)
7
+ k
8
+ end
9
+
10
+ describe '#platform_icon' do
11
+ describe 'amazon' do
12
+ subject { klass.platform_icon('amazon') }
13
+ it { is_expected.to eq 'aws' }
14
+ end
15
+
16
+ describe 'centos' do
17
+ subject { klass.platform_icon('centos') }
18
+ it { is_expected.to eq 'centos' }
19
+ end
20
+
21
+ describe 'debian' do
22
+ subject { klass.platform_icon('debian') }
23
+ it { is_expected.to eq 'debian' }
24
+ end
25
+
26
+ describe 'fedora' do
27
+ subject { klass.platform_icon('fedora') }
28
+ it { is_expected.to eq 'fedora' }
29
+ end
30
+
31
+ describe 'freebsd' do
32
+ subject { klass.platform_icon('freebsd') }
33
+ it { is_expected.to eq 'freebsd' }
34
+ end
35
+
36
+ describe 'linuxmint' do
37
+ subject { klass.platform_icon('linuxmint') }
38
+ it { is_expected.to eq 'linux-mint' }
39
+ end
40
+
41
+ describe 'mac_os_x' do
42
+ subject { klass.platform_icon('mac_os_x') }
43
+ it { is_expected.to eq 'apple' }
44
+ end
45
+
46
+ describe 'oracle' do
47
+ subject { klass.platform_icon('oracle') }
48
+ it { is_expected.to eq 'oracle' }
49
+ end
50
+
51
+ describe 'raspbian' do
52
+ subject { klass.platform_icon('raspbian') }
53
+ it { is_expected.to eq 'raspberrypi' }
54
+ end
55
+
56
+ describe 'redhat' do
57
+ subject { klass.platform_icon('redhat') }
58
+ it { is_expected.to eq 'redhat' }
59
+ end
60
+
61
+ describe 'solaris' do
62
+ subject { klass.platform_icon('solaris') }
63
+ it { is_expected.to eq 'solaris' }
64
+ end
65
+
66
+ describe 'suse' do
67
+ subject { klass.platform_icon('suse') }
68
+ it { is_expected.to eq 'suse' }
69
+ end
70
+
71
+ describe 'ubuntu' do
72
+ subject { klass.platform_icon('ubuntu') }
73
+ it { is_expected.to eq 'ubuntu' }
74
+ end
75
+
76
+ describe 'windows' do
77
+ subject { klass.platform_icon('windows') }
78
+ it { is_expected.to eq 'windows' }
79
+ end
80
+
81
+ describe 'unknown' do
82
+ subject { klass.platform_icon('made-up-os') }
83
+ it { is_expected.to eq 'laptop' }
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+ require 'minimart/web/universe_generator'
3
+ require 'minimart/web/cookbooks'
4
+ require 'minimart/cookbook'
5
+
6
+ describe Minimart::Web::UniverseGenerator do
7
+
8
+ let(:web_directory) { test_directory }
9
+ let(:endpoint) { 'example.com' }
10
+
11
+ let(:cookbook) do
12
+ instance_double(Minimart::Cookbook,
13
+ name: 'sample_cookbook',
14
+ version: '1.2.3',
15
+ web_friendly_version: '1_2_3',
16
+ dependencies: {'mysql' => '> 0.0'},
17
+ path: Pathname.new('/spec/fixtures/sample_cookbook'),
18
+ to_s: 'sample_cookbook-1.2.3')
19
+ end
20
+
21
+ let(:cookbooks) do
22
+ instance_double(Minimart::Web::Cookbooks, individual_cookbooks: [cookbook])
23
+ end
24
+
25
+ subject do
26
+ Minimart::Web::UniverseGenerator.new(
27
+ web_directory: web_directory,
28
+ endpoint: endpoint,
29
+ cookbooks: cookbooks)
30
+ end
31
+
32
+ describe '::new' do
33
+ it 'should assign #web_directory' do
34
+ expect(subject.web_directory).to eq web_directory
35
+ end
36
+
37
+ it 'should assign #endpoint' do
38
+ expect(subject.endpoint).to eq endpoint
39
+ end
40
+
41
+ it 'should assign #cookbooks' do
42
+ expect(subject.cookbooks).to eq cookbooks
43
+ end
44
+
45
+ it 'should build an empty universe' do
46
+ expect(subject.universe.empty?).to eq true
47
+ end
48
+ end
49
+
50
+ describe '#generate' do
51
+ let(:cookbook_files_dir) { File.join(web_directory, 'cookbook_files') }
52
+ let(:cookbook_dir) { File.join(cookbook_files_dir, 'sample_cookbook') }
53
+ let(:universe_file) { File.join(web_directory, 'universe') }
54
+
55
+ before(:each) do
56
+ allow(Minimart::Utils::Archive).to receive(:pack_archive)
57
+ end
58
+
59
+ it 'should make a cookbook_files directory in the web directory' do
60
+ subject.generate
61
+ expect(Dir.exists?(cookbook_files_dir)).to eq true
62
+ end
63
+
64
+ context 'when a cookbook files directory already exists' do
65
+ let(:cookbook_dir) { File.join(cookbook_files_dir, 'existing-cookbook') }
66
+
67
+ before(:each) do
68
+ FileUtils.mkdir_p(cookbook_files_dir)
69
+ FileUtils.mkdir_p(cookbook_dir)
70
+ end
71
+
72
+ it 'should remove the contents' do
73
+ subject.generate
74
+ expect(Dir.exists?(cookbook_dir)).to eq false
75
+ end
76
+ end
77
+
78
+ it 'should make a sub-directory for any cookbooks provided' do
79
+ subject.generate
80
+ expect(Dir.exists?(cookbook_dir)).to eq true
81
+ end
82
+
83
+ it 'should make a sub-directory for any versions of cookbooks provided' do
84
+ subject.generate
85
+ expect(Dir.exists?(File.join(cookbook_dir, '1_2_3'))).to eq true
86
+ end
87
+
88
+ it 'should generate an archive for the cookbook in the correct path' do
89
+ expect(Minimart::Utils::Archive).to receive(:pack_archive).with(
90
+ cookbook,
91
+ File.join(cookbook_dir, '1_2_3/sample_cookbook-1.2.3.tar.gz'))
92
+
93
+ subject.generate
94
+ end
95
+
96
+ it 'should write a universe file in the proper directory' do
97
+ subject.generate
98
+ expect(File.exists?(universe_file)).to eq true
99
+ end
100
+
101
+ describe 'universe contents' do
102
+ let(:universe_contents) { JSON.parse(File.open(universe_file).read) }
103
+ let(:cookbook_info) { universe_contents['sample_cookbook']['1.2.3'] }
104
+
105
+ before(:each) { subject.generate }
106
+
107
+ it 'should give the cookbook the proper location type' do
108
+ expect(cookbook_info['location_type']).to eq 'uri'
109
+ end
110
+
111
+ it 'should give the cookbook the proper location path' do
112
+ expect(cookbook_info['location_path']).to eq 'http://example.com/cookbook_files/sample_cookbook/1_2_3/sample_cookbook-1.2.3.tar.gz'
113
+ end
114
+
115
+ it 'should give the cookbook the proper download url' do
116
+ expect(cookbook_info['download_url']).to eq 'http://example.com/cookbook_files/sample_cookbook/1_2_3/sample_cookbook-1.2.3.tar.gz'
117
+ end
118
+
119
+ it 'should include any dependencies' do
120
+ expect(cookbook_info['dependencies']).to eq('mysql' => '> 0.0')
121
+ end
122
+ end
123
+ end
124
+
125
+ end