chef-dk 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/chef-dk/authenticated_http.rb +40 -0
  4. data/lib/chef-dk/chef_runner.rb +5 -0
  5. data/lib/chef-dk/command/exec.rb +4 -1
  6. data/lib/chef-dk/command/generate.rb +11 -0
  7. data/lib/chef-dk/command/generator_commands.rb +20 -365
  8. data/lib/chef-dk/command/generator_commands/app.rb +99 -0
  9. data/lib/chef-dk/command/generator_commands/attribute.rb +37 -0
  10. data/lib/chef-dk/command/generator_commands/base.rb +76 -0
  11. data/lib/chef-dk/command/generator_commands/cookbook.rb +100 -0
  12. data/lib/chef-dk/command/generator_commands/cookbook_code_file.rb +99 -0
  13. data/lib/chef-dk/command/generator_commands/cookbook_file.rb +45 -0
  14. data/lib/chef-dk/command/generator_commands/lwrp.rb +36 -0
  15. data/lib/chef-dk/command/generator_commands/recipe.rb +36 -0
  16. data/lib/chef-dk/command/generator_commands/repo.rb +96 -0
  17. data/lib/chef-dk/command/generator_commands/template.rb +45 -0
  18. data/lib/chef-dk/command/verify.rb +28 -0
  19. data/lib/chef-dk/component_test.rb +16 -3
  20. data/lib/chef-dk/cookbook_omnifetch.rb +2 -0
  21. data/lib/chef-dk/cookbook_profiler/identifiers.rb +3 -15
  22. data/lib/chef-dk/exceptions.rb +15 -0
  23. data/lib/chef-dk/generator.rb +102 -25
  24. data/lib/chef-dk/policyfile/community_cookbook_source.rb +0 -7
  25. data/lib/chef-dk/policyfile/{cookbook_spec.rb → cookbook_location_specification.rb} +35 -6
  26. data/lib/chef-dk/policyfile/cookbook_locks.rb +305 -0
  27. data/lib/chef-dk/policyfile/dsl.rb +26 -12
  28. data/lib/chef-dk/policyfile/read_cookbook_for_compat_mode_upload.rb +70 -0
  29. data/lib/chef-dk/policyfile/solution_dependencies.rb +204 -0
  30. data/lib/chef-dk/policyfile/storage_config.rb +77 -0
  31. data/lib/chef-dk/policyfile/uploader.rb +110 -0
  32. data/lib/chef-dk/policyfile_compiler.rb +59 -29
  33. data/lib/chef-dk/policyfile_lock.rb +104 -160
  34. data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +1 -1
  35. data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +0 -1
  36. data/lib/chef-dk/skeletons/code_generator/files/default/repo/README.md +66 -0
  37. data/lib/chef-dk/skeletons/code_generator/files/default/repo/Rakefile +65 -0
  38. data/lib/chef-dk/skeletons/code_generator/files/default/repo/certificates/README.md +19 -0
  39. data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/README-policy.md +9 -0
  40. data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/README.md +54 -0
  41. data/lib/chef-dk/skeletons/code_generator/files/default/repo/data_bags/README.md +63 -0
  42. data/lib/chef-dk/skeletons/code_generator/files/default/repo/environments/README.md +5 -0
  43. data/lib/chef-dk/skeletons/code_generator/files/default/repo/roles/README.md +16 -0
  44. data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +7 -1
  45. data/lib/chef-dk/skeletons/code_generator/recipes/repo.rb +62 -0
  46. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.all_rights.erb +3 -0
  47. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.apache2.erb +201 -0
  48. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv2.erb +339 -0
  49. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.gplv3.erb +674 -0
  50. data/lib/chef-dk/skeletons/code_generator/templates/default/LICENSE.mit.erb +21 -0
  51. data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +1 -4
  52. data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +3 -3
  53. data/lib/chef-dk/skeletons/code_generator/templates/default/repo/config/rake.rb.erb +38 -0
  54. data/lib/chef-dk/skeletons/code_generator/templates/default/repo/gitignore.erb +11 -0
  55. data/lib/chef-dk/version.rb +1 -1
  56. data/spec/shared/a_file_generator.rb +121 -0
  57. data/spec/shared/a_generated_file.rb +12 -0
  58. data/spec/shared/fixture_cookbook_checksums.rb +47 -0
  59. data/spec/spec_helper.rb +4 -2
  60. data/spec/unit/chef_runner_spec.rb +12 -5
  61. data/spec/unit/cli_spec.rb +4 -4
  62. data/spec/unit/command/base_spec.rb +1 -1
  63. data/spec/unit/command/exec_spec.rb +37 -27
  64. data/spec/unit/command/generate_spec.rb +3 -3
  65. data/spec/unit/command/generator_commands/app_spec.rb +131 -0
  66. data/spec/unit/command/generator_commands/attribute_spec.rb +32 -0
  67. data/spec/unit/command/generator_commands/cookbook_file_spec.rb +32 -0
  68. data/spec/unit/command/generator_commands/cookbook_spec.rb +205 -0
  69. data/spec/unit/command/generator_commands/lwrp_spec.rb +32 -0
  70. data/spec/unit/command/generator_commands/recipe_spec.rb +32 -0
  71. data/spec/unit/command/generator_commands/repo_spec.rb +287 -0
  72. data/spec/unit/command/generator_commands/template_spec.rb +32 -0
  73. data/spec/unit/command/shell_init_spec.rb +4 -4
  74. data/spec/unit/command/verify_spec.rb +9 -9
  75. data/spec/unit/commands_map_spec.rb +1 -1
  76. data/spec/unit/component_test_spec.rb +3 -3
  77. data/spec/unit/cookbook_profiler/git_spec.rb +7 -7
  78. data/spec/unit/cookbook_profiler/identifiers_spec.rb +12 -8
  79. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +1 -1
  80. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +1 -1
  81. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +1 -1
  82. data/spec/unit/fixtures/example_cookbook/Berksfile +1 -1
  83. data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/README.md +4 -0
  84. data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/chefignore +96 -0
  85. data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/metadata.rb +8 -0
  86. data/spec/unit/fixtures/local_path_cookbooks/another-local-cookbook/recipes/default.rb +8 -0
  87. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +1 -1
  88. data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
  89. data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
  90. data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
  91. data/spec/unit/fixtures/local_path_cookbooks/noignore-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
  92. data/spec/unit/generator_spec.rb +120 -0
  93. data/spec/unit/policyfile/{cookbook_spec_spec.rb → cookbook_location_specification_spec.rb} +83 -38
  94. data/spec/unit/policyfile/cookbook_locks_spec.rb +354 -0
  95. data/spec/unit/policyfile/read_cookbook_for_compat_mode_upload_spec.rb +85 -0
  96. data/spec/unit/policyfile/solution_dependencies_spec.rb +145 -0
  97. data/spec/unit/policyfile/storage_config_spec.rb +98 -0
  98. data/spec/unit/policyfile/uploader_spec.rb +292 -0
  99. data/spec/unit/policyfile_demands_spec.rb +177 -24
  100. data/spec/unit/policyfile_evaluation_spec.rb +40 -12
  101. data/spec/unit/{policyfile_builder_spec.rb → policyfile_lock_build_spec.rb} +179 -64
  102. data/spec/unit/policyfile_lock_install_spec.rb +138 -0
  103. data/spec/unit/policyfile_lock_validation_spec.rb +610 -0
  104. metadata +103 -59
  105. data/spec/unit/command/generator_commands_spec.rb +0 -504
@@ -46,11 +46,11 @@ describe ChefDK::CookbookProfiler::Git do
46
46
  end
47
47
 
48
48
  it "reports that the repo is clean" do
49
- expect(git_profiler.clean?).to be_true
49
+ expect(git_profiler.clean?).to be true
50
50
  end
51
51
 
52
52
  it "reports that the commits are unpublished" do
53
- expect(git_profiler.unpublished_commits?).to be_true
53
+ expect(git_profiler.unpublished_commits?).to be true
54
54
  end
55
55
 
56
56
  it "reports that no remotes have the commits" do
@@ -74,11 +74,11 @@ describe ChefDK::CookbookProfiler::Git do
74
74
  end
75
75
 
76
76
  it "reports that the repo is clean" do
77
- expect(git_profiler.clean?).to be_true
77
+ expect(git_profiler.clean?).to be true
78
78
  end
79
79
 
80
80
  it "reports that all commits are published to the upstream" do
81
- expect(git_profiler.unpublished_commits?).to be_false
81
+ expect(git_profiler.unpublished_commits?).to be false
82
82
  end
83
83
 
84
84
  it "lists the remotes that commits are published to" do
@@ -97,11 +97,11 @@ describe ChefDK::CookbookProfiler::Git do
97
97
  end
98
98
 
99
99
  it "reports that the repo is clean" do
100
- expect(git_profiler.clean?).to be_true
100
+ expect(git_profiler.clean?).to be true
101
101
  end
102
102
 
103
103
  it "reports that there are unpublished changes" do
104
- expect(git_profiler.unpublished_commits?).to be_true
104
+ expect(git_profiler.unpublished_commits?).to be true
105
105
  end
106
106
 
107
107
  it "reports that no remotes have the commits" do
@@ -118,7 +118,7 @@ describe ChefDK::CookbookProfiler::Git do
118
118
  end
119
119
 
120
120
  it "reports that the repo is dirty" do
121
- expect(git_profiler.clean?).to be_false
121
+ expect(git_profiler.clean?).to be false
122
122
  end
123
123
 
124
124
  end
@@ -17,6 +17,7 @@
17
17
 
18
18
  require 'spec_helper'
19
19
  require 'chef-dk/cookbook_profiler/identifiers'
20
+ require 'chef-dk/policyfile/read_cookbook_for_compat_mode_upload'
20
21
 
21
22
  describe ChefDK::CookbookProfiler::Identifiers do
22
23
 
@@ -28,15 +29,22 @@ describe ChefDK::CookbookProfiler::Identifiers do
28
29
  File.join(cache_path, "foo-1.0.0")
29
30
  end
30
31
 
32
+ let(:cookbook_version) do
33
+ chefignore = Chef::Cookbook::Chefignore.new(File.join(foo_cookbook_path, "chefignore"))
34
+ cbvl = Chef::Cookbook::CookbookVersionLoader.new(foo_cookbook_path, chefignore)
35
+ cbvl.load!
36
+ cbvl.cookbook_version
37
+ end
38
+
39
+
31
40
  let(:identifiers) do
32
- ChefDK::CookbookProfiler::Identifiers.new(foo_cookbook_path)
41
+ ChefDK::CookbookProfiler::Identifiers.new(cookbook_version)
33
42
  end
34
43
 
35
44
  let(:cookbook_files_with_cksums) do
36
45
  # Entries must be sorted lexically.
37
46
  {
38
47
  ".kitchen.yml" => "85ba09a085dab072722cb197e04fa805",
39
- "Berksfile" => "a668a1df3121f22875e754466f535d8a",
40
48
  "README.md" => "0f15038071e5a131bef176cbe2a956d1",
41
49
  "chefignore" => "03485640b005eb1083c76518764053dd",
42
50
  "metadata.rb" => "4879d0004b177546cfbcfb2fd26df7c8",
@@ -44,10 +52,6 @@ describe ChefDK::CookbookProfiler::Identifiers do
44
52
  }
45
53
  end
46
54
 
47
- it "has the cookbook's path" do
48
- expect(identifiers.cookbook_path).to eq(foo_cookbook_path)
49
- end
50
-
51
55
  it "has the cookbook's semver version" do
52
56
  expect(identifiers.semver_version).to eq("1.0.0")
53
57
  end
@@ -68,11 +72,11 @@ describe ChefDK::CookbookProfiler::Identifiers do
68
72
  end
69
73
 
70
74
  it "generates a Hash of the cookbook's content" do
71
- expect(identifiers.content_identifier).to eq("e4611e9b5ec0636a18979e7dd22537222a2eab47")
75
+ expect(identifiers.content_identifier).to eq("467dc855408ce8b74f991c5dc2fd72a6aa369b60")
72
76
  end
73
77
 
74
78
  it "generates a dotted decimal representation of the content hash" do
75
- expect(identifiers.dotted_decimal_identifier).to eq("64283078773620835.29863387009503781.60619876117319")
79
+ expect(identifiers.dotted_decimal_identifier).to eq("19841547746970856.51597439762547453.126060145843040")
76
80
  end
77
81
 
78
82
  end
@@ -1,3 +1,3 @@
1
- source "https://api.berkshelf.com"
1
+ source "https://supermarket.getchef.com"
2
2
 
3
3
  metadata
@@ -1,3 +1,3 @@
1
- source "https://api.berkshelf.com"
1
+ source "https://supermarket.getchef.com"
2
2
 
3
3
  metadata
@@ -1,3 +1,3 @@
1
- source "https://api.berkshelf.com"
1
+ source "https://supermarket.getchef.com"
2
2
 
3
3
  metadata
@@ -1,3 +1,3 @@
1
- source "https://api.berkshelf.com"
1
+ source "https://supermarket.getchef.com"
2
2
 
3
3
  metadata
@@ -0,0 +1,4 @@
1
+ # another-local-cookbook
2
+
3
+ TODO: Enter the cookbook description here.
4
+
@@ -0,0 +1,96 @@
1
+ # Put files/directories that should be ignored in this file when uploading
2
+ # or sharing to the community site.
3
+ # Lines that start with '# ' are comments.
4
+
5
+ # OS generated files #
6
+ ######################
7
+ .DS_Store
8
+ Icon?
9
+ nohup.out
10
+ ehthumbs.db
11
+ Thumbs.db
12
+
13
+ # SASS #
14
+ ########
15
+ .sass-cache
16
+
17
+ # EDITORS #
18
+ ###########
19
+ \#*
20
+ .#*
21
+ *~
22
+ *.sw[a-z]
23
+ *.bak
24
+ REVISION
25
+ TAGS*
26
+ tmtags
27
+ *_flymake.*
28
+ *_flymake
29
+ *.tmproj
30
+ .project
31
+ .settings
32
+ mkmf.log
33
+
34
+ ## COMPILED ##
35
+ ##############
36
+ a.out
37
+ *.o
38
+ *.pyc
39
+ *.so
40
+ *.com
41
+ *.class
42
+ *.dll
43
+ *.exe
44
+ */rdoc/
45
+
46
+ # Testing #
47
+ ###########
48
+ .watchr
49
+ .rspec
50
+ spec/*
51
+ spec/fixtures/*
52
+ test/*
53
+ features/*
54
+ Guardfile
55
+ Procfile
56
+
57
+ # SCM #
58
+ #######
59
+ .git
60
+ */.git
61
+ .gitignore
62
+ .gitmodules
63
+ .gitconfig
64
+ .gitattributes
65
+ .svn
66
+ */.bzr/*
67
+ */.hg/*
68
+ */.svn/*
69
+
70
+ # Berkshelf #
71
+ #############
72
+ Berksfile
73
+ Berksfile.lock
74
+ cookbooks/*
75
+ tmp
76
+
77
+ # Cookbooks #
78
+ #############
79
+ CONTRIBUTING
80
+ CHANGELOG*
81
+
82
+ # Strainer #
83
+ ############
84
+ Colanderfile
85
+ Strainerfile
86
+ .colander
87
+ .strainer
88
+
89
+ # Vagrant #
90
+ ###########
91
+ .vagrant
92
+ Vagrantfile
93
+
94
+ # Travis #
95
+ ##########
96
+ .travis.yml
@@ -0,0 +1,8 @@
1
+ name 'another-local-cookbook'
2
+ maintainer ''
3
+ maintainer_email ''
4
+ license ''
5
+ description 'Installs/Configures another-local-cookbook'
6
+ long_description 'Installs/Configures another-local-cookbook'
7
+ version '0.1.0'
8
+
@@ -0,0 +1,8 @@
1
+ #
2
+ # Cookbook Name:: another-local-cookbook
3
+ # Recipe:: default
4
+ #
5
+ # Copyright (C) 2014
6
+ #
7
+ #
8
+ #
@@ -1,3 +1,3 @@
1
- source "https://api.berkshelf.com"
1
+ source "https://supermarket.getchef.com"
2
2
 
3
3
  metadata
@@ -0,0 +1,16 @@
1
+ ---
2
+ driver:
3
+ name: vagrant
4
+
5
+ provisioner:
6
+ name: chef_solo
7
+
8
+ platforms:
9
+ - name: ubuntu-12.04
10
+ - name: centos-6.4
11
+
12
+ suites:
13
+ - name: default
14
+ run_list:
15
+ - recipe[noignore::default]
16
+ attributes:
@@ -0,0 +1,4 @@
1
+ # noignore
2
+
3
+ TODO: Enter the cookbook description here.
4
+
@@ -0,0 +1,8 @@
1
+ name 'noignore'
2
+ maintainer ''
3
+ maintainer_email ''
4
+ license ''
5
+ description 'a cookbook w/o chefignore'
6
+ long_description 'a cookbook w/o chefignore'
7
+ version '0.1.0'
8
+
@@ -0,0 +1,8 @@
1
+ #
2
+ # Cookbook Name:: noignore
3
+ # Recipe:: default
4
+ #
5
+ # Copyright (C) 2014
6
+ #
7
+ #
8
+ #
@@ -0,0 +1,120 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'spec_helper'
19
+ require 'chef-dk/generator'
20
+
21
+ describe ChefDK::Generator do
22
+
23
+ before(:each) do
24
+ ChefDK::Generator.reset
25
+ end
26
+
27
+ describe "self.add_attr_to_context" do
28
+ it "adds an accessor for the symbol to the context object" do
29
+ ChefDK::Generator.add_attr_to_context(:snakes)
30
+ expect(ChefDK::Generator.context.snakes = 5).to be_eql(5)
31
+ expect(ChefDK::Generator.context.snakes).to be_eql(5)
32
+ end
33
+
34
+ it "delegates the accessor from the template helper" do
35
+ ChefDK::Generator.add_attr_to_context(:snakes)
36
+ ChefDK::Generator.context.snakes = 5
37
+ expect(ChefDK::Generator::TemplateHelper.instance_methods).to include(:snakes)
38
+ end
39
+
40
+ it "sets a value" do
41
+ ChefDK::Generator.add_attr_to_context(:snakes, 5)
42
+ expect(ChefDK::Generator.context.snakes).to be_eql(5)
43
+ end
44
+ end
45
+ end
46
+
47
+ class TmplTest
48
+ include ChefDK::Generator::TemplateHelper
49
+ end
50
+
51
+ describe ChefDK::Generator::TemplateHelper do
52
+ let(:license) { 'all_rights' }
53
+ let(:copyright_holder) { 'Adam Jacob' }
54
+ let(:helper) { TmplTest.new }
55
+
56
+ before(:each) do
57
+ ChefDK::Generator.reset
58
+ ChefDK::Generator.add_attr_to_context(:license, license)
59
+ ChefDK::Generator.add_attr_to_context(:copyright_holder, 'Adam Jacob')
60
+ end
61
+
62
+ describe 'license_description' do
63
+ let(:license) { "all_rights" }
64
+ context "all_rights" do
65
+ it "should match the license" do
66
+ expect(helper.license_description).to match(/^Copyright \(c\)/)
67
+ end
68
+
69
+ it "should comment if requested" do
70
+ expect(helper.license_description('#')).to match(/^# Copyright/)
71
+ end
72
+ end
73
+
74
+ context "apache2" do
75
+ let(:license) { 'apache2' }
76
+ it "should match the license" do
77
+ expect(helper.license_description).to match(/Licensed under the Apache/)
78
+ end
79
+
80
+ it "should comment if requested" do
81
+ expect(helper.license_description('#')).to match(/# Licensed under the Apache/)
82
+ end
83
+ end
84
+
85
+ context "mit" do
86
+ let(:license) { 'mit' }
87
+ it "should match the license" do
88
+ expect(helper.license_description).to match(/Permission is hereby granted/)
89
+ end
90
+
91
+ it "should comment if requested" do
92
+ expect(helper.license_description('#')).to match(/# Permission is hereby granted/)
93
+ end
94
+ end
95
+
96
+ context "gplv2" do
97
+ let(:license) { 'gplv2' }
98
+ it "should match the license" do
99
+ expect(helper.license_description).to match(/This program is free software;/)
100
+ end
101
+
102
+ it "should comment if requested" do
103
+ expect(helper.license_description('#')).to match(/# This program is free software;/)
104
+ end
105
+ end
106
+
107
+ context "gplv3" do
108
+ let(:license) { 'gplv3' }
109
+ it "should match the license" do
110
+ expect(helper.license_description).to match(/This program is free software:/)
111
+ end
112
+
113
+ it "should comment if requested" do
114
+ expect(helper.license_description('#')).to match(/# This program is free software:/)
115
+ end
116
+ end
117
+ end
118
+
119
+ end
120
+
@@ -16,9 +16,9 @@
16
16
  #
17
17
 
18
18
  require 'spec_helper'
19
- require 'chef-dk/policyfile/cookbook_spec'
19
+ require 'chef-dk/policyfile/cookbook_location_specification'
20
20
 
21
- describe ChefDK::Policyfile::CookbookSpec do
21
+ describe ChefDK::Policyfile::CookbookLocationSpecification do
22
22
 
23
23
  let(:policyfile_filename) { File.join(fixtures_path, "example_app/Policyfile.rb") }
24
24
 
@@ -32,84 +32,95 @@ describe ChefDK::Policyfile::CookbookSpec do
32
32
 
33
33
  let(:installer) { double("CookbookOmnifetch location", cached_cookbook: cached_cookbook) }
34
34
 
35
- let(:cookbook_spec) { described_class.new(cookbook_name, version_constraint, source_options, policyfile_filename) }
35
+ let(:storage_config) do
36
+ ChefDK::Policyfile::StorageConfig.new.use_policyfile(policyfile_filename)
37
+ end
38
+
39
+ let(:cookbook_location_spec) { described_class.new(cookbook_name, version_constraint, source_options, storage_config) }
36
40
 
37
41
  it "has a name" do
38
- expect(cookbook_spec.name).to eq(cookbook_name)
42
+ expect(cookbook_location_spec.name).to eq(cookbook_name)
39
43
  end
40
44
 
41
45
  it "has a version constraint" do
42
- expect(cookbook_spec.version_constraint).to eq(Semverse::Constraint.new(version_constraint))
46
+ expect(cookbook_location_spec.version_constraint).to eq(Semverse::Constraint.new(version_constraint))
43
47
  end
44
48
 
45
49
  it "has source options it was created with" do
46
- expect(cookbook_spec.source_options).to eq(source_options)
50
+ expect(cookbook_location_spec.source_options).to eq(source_options)
47
51
  end
48
52
 
49
53
  it "is equal to another cookbook spec with the same name, constraint, and options" do
50
- equal_spec = described_class.new(cookbook_name, version_constraint, source_options, policyfile_filename)
51
- expect(cookbook_spec).to eq(equal_spec)
54
+ equal_spec = described_class.new(cookbook_name, version_constraint, source_options, storage_config)
55
+ expect(cookbook_location_spec).to eq(equal_spec)
52
56
  end
53
57
 
54
58
  it "is not equal to another cookbook spec if the name, constraint or option differ" do
55
- different_name = described_class.new("wut", version_constraint, source_options, policyfile_filename)
56
- expect(cookbook_spec).to_not eq(different_name)
59
+ different_name = described_class.new("wut", version_constraint, source_options, storage_config)
60
+ expect(cookbook_location_spec).to_not eq(different_name)
57
61
 
58
- different_constraint = described_class.new(cookbook_name, ">= 1.0.0", source_options, policyfile_filename)
59
- expect(cookbook_spec).to_not eq(different_constraint)
62
+ different_constraint = described_class.new(cookbook_name, ">= 1.0.0", source_options, storage_config)
63
+ expect(cookbook_location_spec).to_not eq(different_constraint)
60
64
 
61
- different_opts = described_class.new(cookbook_name, version_constraint, {git: "git://example.com/wat.git"}, policyfile_filename)
62
- expect(cookbook_spec).to_not eq(different_opts)
65
+ different_opts = described_class.new(cookbook_name, version_constraint, {git: "git://example.com/wat.git"}, storage_config)
66
+ expect(cookbook_location_spec).to_not eq(different_opts)
63
67
  end
64
68
 
65
69
  it "gives the base directory from which relative paths will be expanded" do
66
- expect(cookbook_spec.relative_paths_root).to eq(File.join(fixtures_path, "example_app"))
70
+ expect(cookbook_location_spec.relative_paths_root).to eq(File.join(fixtures_path, "example_app"))
71
+ end
72
+
73
+ it "gives source options for locking via the installer" do
74
+ lock_data = double("Installer lock data")
75
+ expect(installer).to receive(:lock_data).and_return(lock_data)
76
+ expect(cookbook_location_spec).to receive(:installer).and_return(installer)
77
+ expect(cookbook_location_spec.source_options_for_lock).to eq(lock_data)
67
78
  end
68
79
 
69
80
  describe "fetching and querying a cookbook" do
70
81
 
71
82
  before do
72
- expect(CookbookOmnifetch).to receive(:init).with(cookbook_spec, source_options).and_return(installer)
83
+ expect(CookbookOmnifetch).to receive(:init).with(cookbook_location_spec, source_options).and_return(installer)
73
84
  end
74
85
 
75
86
  it "initializes a CookbookOmnifetch location class to handle installation" do
76
- expect(cookbook_spec.installer).to eq(installer)
87
+ expect(cookbook_location_spec.installer).to eq(installer)
77
88
  end
78
89
 
79
90
  it "delegates installation to the installer" do
80
91
  expect(installer).to receive(:installed?).and_return(false)
81
92
  expect(installer).to receive(:install)
82
- cookbook_spec.ensure_cached
93
+ cookbook_location_spec.ensure_cached
83
94
  end
84
95
 
85
96
  it "does not install the cookbook if it's already cached" do
86
97
  expect(installer).to receive(:installed?).and_return(true)
87
98
  expect(installer).to_not receive(:install)
88
- cookbook_spec.ensure_cached
99
+ cookbook_location_spec.ensure_cached
89
100
  end
90
101
 
91
102
  it "delegates cache_key to the installer" do
92
103
  expect(installer).to receive(:cache_key).and_return("my_cookbook-1.2.3-supermarket.getchef.com")
93
- expect(cookbook_spec.cache_key).to eq("my_cookbook-1.2.3-supermarket.getchef.com")
104
+ expect(cookbook_location_spec.cache_key).to eq("my_cookbook-1.2.3-supermarket.getchef.com")
94
105
  end
95
106
 
96
107
  it "delegates relative_path to the installer" do
97
108
  expect(installer).to receive(:relative_path).and_return(Pathname.new("../my_stuff/my_cookbook"))
98
- expect(cookbook_spec.relative_path).to eq("../my_stuff/my_cookbook")
109
+ expect(cookbook_location_spec.relative_path).to eq("../my_stuff/my_cookbook")
99
110
  end
100
111
 
101
112
  it "loads the cookbook metadata via the installer" do
102
- expect(cookbook_spec.cached_cookbook).to eq(cached_cookbook)
113
+ expect(cookbook_location_spec.cached_cookbook).to eq(cached_cookbook)
103
114
  end
104
115
 
105
116
  it "gives the cookbook's version via the metadata" do
106
117
  expect(cached_cookbook).to receive(:version).and_return("1.2.3")
107
- expect(cookbook_spec.version).to eq("1.2.3")
118
+ expect(cookbook_location_spec.version).to eq("1.2.3")
108
119
  end
109
120
 
110
121
  it "gives the cookbook's dependencies via the metadata" do
111
122
  expect(cached_cookbook).to receive(:dependencies).and_return("apt" => "~> 1.2.3")
112
- expect(cookbook_spec.dependencies).to eq("apt" => "~> 1.2.3")
123
+ expect(cookbook_location_spec.dependencies).to eq("apt" => "~> 1.2.3")
113
124
  end
114
125
 
115
126
  end
@@ -117,11 +128,24 @@ describe ChefDK::Policyfile::CookbookSpec do
117
128
  describe "when created with no source" do
118
129
 
119
130
  it "has a nil installer" do
120
- expect(cookbook_spec.installer).to be_nil
131
+ expect(cookbook_location_spec.installer).to be_nil
121
132
  end
122
133
 
123
134
  it "is not at a fixed version" do
124
- expect(cookbook_spec.version_fixed?).to be false
135
+ expect(cookbook_location_spec.version_fixed?).to be false
136
+ end
137
+
138
+ end
139
+
140
+ describe "when created with invalid source options" do
141
+
142
+ let(:source_options) { { herp: "derp" } }
143
+
144
+ it "is invalid" do
145
+ expect(cookbook_location_spec).to_not be_valid
146
+ expect(cookbook_location_spec.errors.size).to eq(1)
147
+ error = cookbook_location_spec.errors.first
148
+ expect(error).to eq("Cookbook `my_cookbook' has invalid source options `{:herp=>\"derp\"}'")
125
149
  end
126
150
 
127
151
  end
@@ -131,15 +155,20 @@ describe ChefDK::Policyfile::CookbookSpec do
131
155
  let(:source_options) { { git: "git@github.com:example/my_cookbook.git" } }
132
156
 
133
157
  it "has a git installer" do
134
- expect(cookbook_spec.installer).to be_a_kind_of(CookbookOmnifetch::GitLocation)
158
+ expect(cookbook_location_spec.installer).to be_a_kind_of(CookbookOmnifetch::GitLocation)
135
159
  end
136
160
 
137
161
  it "has a fixed version" do
138
- expect(cookbook_spec.version_fixed?).to be true
162
+ expect(cookbook_location_spec.version_fixed?).to be true
139
163
  end
140
164
 
141
165
  it "mirrors a canonical upstream" do
142
- expect(cookbook_spec.mirrors_canonical_upstream?).to be true
166
+ expect(cookbook_location_spec.mirrors_canonical_upstream?).to be true
167
+ end
168
+
169
+ it "is valid" do
170
+ expect(cookbook_location_spec.errors.size).to eq(0)
171
+ expect(cookbook_location_spec).to be_valid
143
172
  end
144
173
 
145
174
  end
@@ -149,15 +178,20 @@ describe ChefDK::Policyfile::CookbookSpec do
149
178
  let(:source_options) { { github: "my_org/my_cookbook" } }
150
179
 
151
180
  it "has a github installer" do
152
- expect(cookbook_spec.installer).to be_a_kind_of(CookbookOmnifetch::GithubLocation)
181
+ expect(cookbook_location_spec.installer).to be_a_kind_of(CookbookOmnifetch::GithubLocation)
153
182
  end
154
183
 
155
184
  it "has a fixed version" do
156
- expect(cookbook_spec.version_fixed?).to be true
185
+ expect(cookbook_location_spec.version_fixed?).to be true
157
186
  end
158
187
 
159
188
  it "mirrors a canonical upstream" do
160
- expect(cookbook_spec.mirrors_canonical_upstream?).to be true
189
+ expect(cookbook_location_spec.mirrors_canonical_upstream?).to be true
190
+ end
191
+
192
+ it "is valid" do
193
+ expect(cookbook_location_spec.errors.size).to eq(0)
194
+ expect(cookbook_location_spec).to be_valid
161
195
  end
162
196
 
163
197
  end
@@ -167,15 +201,20 @@ describe ChefDK::Policyfile::CookbookSpec do
167
201
  let(:source_options) { { path: "../example_cookbook" } }
168
202
 
169
203
  it "has a path installer" do
170
- expect(cookbook_spec.installer).to be_a_kind_of(CookbookOmnifetch::PathLocation)
204
+ expect(cookbook_location_spec.installer).to be_a_kind_of(CookbookOmnifetch::PathLocation)
171
205
  end
172
206
 
173
207
  it "has a fixed version" do
174
- expect(cookbook_spec.version_fixed?).to be true
208
+ expect(cookbook_location_spec.version_fixed?).to be true
175
209
  end
176
210
 
177
211
  it "isnt a mirror of a canonical upstream" do
178
- expect(cookbook_spec.mirrors_canonical_upstream?).to be false
212
+ expect(cookbook_location_spec.mirrors_canonical_upstream?).to be false
213
+ end
214
+
215
+ it "is valid" do
216
+ expect(cookbook_location_spec.errors.size).to eq(0)
217
+ expect(cookbook_location_spec).to be_valid
179
218
  end
180
219
 
181
220
  end
@@ -185,16 +224,22 @@ describe ChefDK::Policyfile::CookbookSpec do
185
224
  let(:source_options) { { artifactserver: "https://supermarket.getchef.com:/api/v1/cookbooks/my_cookbook/versions/2.0.0/download" } }
186
225
 
187
226
  it "has a artifactserver installer" do
188
- expect(cookbook_spec.installer).to be_a_kind_of(CookbookOmnifetch::ArtifactserverLocation)
227
+ expect(cookbook_location_spec.installer).to be_a_kind_of(CookbookOmnifetch::ArtifactserverLocation)
189
228
  end
190
229
 
191
230
  it "does not have a fixed version" do
192
- expect(cookbook_spec.version_fixed?).to be false
231
+ expect(cookbook_location_spec.version_fixed?).to be false
193
232
  end
194
233
 
195
234
  it "is a mirror of a canonical upstream" do
196
- expect(cookbook_spec.mirrors_canonical_upstream?).to be true
235
+ expect(cookbook_location_spec.mirrors_canonical_upstream?).to be true
236
+ end
237
+
238
+ it "is valid" do
239
+ expect(cookbook_location_spec.errors.size).to eq(0)
240
+ expect(cookbook_location_spec).to be_valid
197
241
  end
198
242
 
243
+
199
244
  end
200
245
  end