chef-dk 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +192 -0
  3. data/LICENSE +201 -0
  4. data/README.md +198 -0
  5. data/Rakefile +18 -0
  6. data/bin/chef +25 -0
  7. data/lib/chef-dk.rb +19 -0
  8. data/lib/chef-dk/builtin_commands.rb +31 -0
  9. data/lib/chef-dk/chef_runner.rb +83 -0
  10. data/lib/chef-dk/cli.rb +135 -0
  11. data/lib/chef-dk/command/base.rb +71 -0
  12. data/lib/chef-dk/command/exec.rb +33 -0
  13. data/lib/chef-dk/command/gem.rb +47 -0
  14. data/lib/chef-dk/command/generate.rb +97 -0
  15. data/lib/chef-dk/command/generator_commands.rb +417 -0
  16. data/lib/chef-dk/command/shell_init.rb +80 -0
  17. data/lib/chef-dk/command/verify.rb +226 -0
  18. data/lib/chef-dk/commands_map.rb +115 -0
  19. data/lib/chef-dk/component_test.rb +142 -0
  20. data/lib/chef-dk/cookbook_metadata.rb +36 -0
  21. data/lib/chef-dk/cookbook_omnifetch.rb +29 -0
  22. data/lib/chef-dk/cookbook_profiler/git.rb +95 -0
  23. data/lib/chef-dk/cookbook_profiler/identifiers.rb +79 -0
  24. data/lib/chef-dk/cookbook_profiler/null_scm.rb +32 -0
  25. data/lib/chef-dk/exceptions.rb +46 -0
  26. data/lib/chef-dk/generator.rb +70 -0
  27. data/lib/chef-dk/helpers.rb +95 -0
  28. data/lib/chef-dk/policyfile/chef_server_cookbook_source.rb +46 -0
  29. data/lib/chef-dk/policyfile/community_cookbook_source.rb +84 -0
  30. data/lib/chef-dk/policyfile/cookbook_sources.rb +20 -0
  31. data/lib/chef-dk/policyfile/cookbook_spec.rb +96 -0
  32. data/lib/chef-dk/policyfile/dsl.rb +148 -0
  33. data/lib/chef-dk/policyfile/null_cookbook_source.rb +37 -0
  34. data/lib/chef-dk/policyfile_compiler.rb +217 -0
  35. data/lib/chef-dk/policyfile_lock.rb +243 -0
  36. data/lib/chef-dk/shell_out.rb +36 -0
  37. data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +3 -0
  38. data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +96 -0
  39. data/lib/chef-dk/skeletons/code_generator/files/default/converge_spec.rb +9 -0
  40. data/lib/chef-dk/skeletons/code_generator/files/default/gitignore +16 -0
  41. data/lib/chef-dk/skeletons/code_generator/files/default/spec_helper.rb +8 -0
  42. data/lib/chef-dk/skeletons/code_generator/metadata.rb +8 -0
  43. data/lib/chef-dk/skeletons/code_generator/recipes/app.rb +65 -0
  44. data/lib/chef-dk/skeletons/code_generator/recipes/attribute.rb +12 -0
  45. data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +50 -0
  46. data/lib/chef-dk/skeletons/code_generator/recipes/cookbook_file.rb +24 -0
  47. data/lib/chef-dk/skeletons/code_generator/recipes/lwrp.rb +23 -0
  48. data/lib/chef-dk/skeletons/code_generator/recipes/recipe.rb +9 -0
  49. data/lib/chef-dk/skeletons/code_generator/recipes/template.rb +32 -0
  50. data/lib/chef-dk/skeletons/code_generator/templates/default/README.md.erb +4 -0
  51. data/lib/chef-dk/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
  52. data/lib/chef-dk/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
  53. data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +8 -0
  54. data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen.yml.erb +16 -0
  55. data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +8 -0
  56. data/lib/chef-dk/skeletons/code_generator/templates/default/provider.rb.erb +0 -0
  57. data/lib/chef-dk/skeletons/code_generator/templates/default/recipe.rb.erb +0 -0
  58. data/lib/chef-dk/skeletons/code_generator/templates/default/resource.rb.erb +0 -0
  59. data/lib/chef-dk/skeletons/code_generator/templates/default/template.erb +0 -0
  60. data/lib/chef-dk/version.rb +20 -0
  61. data/spec/shared/setup_git_cookbooks.rb +53 -0
  62. data/spec/spec_helper.rb +32 -0
  63. data/spec/test_helpers.rb +59 -0
  64. data/spec/unit/chef_runner_spec.rb +70 -0
  65. data/spec/unit/cli_spec.rb +151 -0
  66. data/spec/unit/command/base_spec.rb +88 -0
  67. data/spec/unit/command/exec_spec.rb +123 -0
  68. data/spec/unit/command/generate_spec.rb +102 -0
  69. data/spec/unit/command/generator_commands_spec.rb +504 -0
  70. data/spec/unit/command/shell_init_spec.rb +109 -0
  71. data/spec/unit/command/verify_spec.rb +311 -0
  72. data/spec/unit/commands_map_spec.rb +57 -0
  73. data/spec/unit/component_test_spec.rb +126 -0
  74. data/spec/unit/cookbook_metadata_spec.rb +62 -0
  75. data/spec/unit/cookbook_profiler/git_spec.rb +127 -0
  76. data/spec/unit/cookbook_profiler/identifiers_spec.rb +79 -0
  77. data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_one.rb +9 -0
  78. data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_two.rb +9 -0
  79. data/spec/unit/fixtures/command/cli_test_command.rb +26 -0
  80. data/spec/unit/fixtures/command/explicit_path_example.rb +7 -0
  81. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
  82. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +3 -0
  83. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
  84. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore +96 -0
  85. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
  86. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
  87. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/.kitchen.yml +16 -0
  88. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +3 -0
  89. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/README.md +4 -0
  90. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/chefignore +96 -0
  91. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/metadata.rb +8 -0
  92. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/recipes/default.rb +8 -0
  93. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/.kitchen.yml +16 -0
  94. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +3 -0
  95. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/README.md +4 -0
  96. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/chefignore +96 -0
  97. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/metadata.rb +8 -0
  98. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/recipes/default.rb +8 -0
  99. data/spec/unit/fixtures/cookbooks_api/pruned_small_universe.json +1322 -0
  100. data/spec/unit/fixtures/cookbooks_api/small_universe.json +2987 -0
  101. data/spec/unit/fixtures/cookbooks_api/universe.json +1 -0
  102. data/spec/unit/fixtures/cookbooks_api/update_fixtures.rb +36 -0
  103. data/spec/unit/fixtures/dev_cookbooks/README.md +16 -0
  104. data/spec/unit/fixtures/dev_cookbooks/bar-cookbook.gitbundle +0 -0
  105. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/bin/.keep +0 -0
  106. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/.keep +0 -0
  107. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/bin/.keep +0 -0
  108. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/bin/.keep +0 -0
  109. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/berkshelf/.keep +0 -0
  110. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/test-kitchen/.keep +0 -0
  111. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/bin/.keep +0 -0
  112. data/spec/unit/fixtures/eg_omnibus_dir/valid/bin/.keep +0 -0
  113. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/integration_test +2 -0
  114. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/verify_me +5 -0
  115. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef-dk/.keep +0 -0
  116. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef/verify_me +3 -0
  117. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/test-kitchen/verify_me +2 -0
  118. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/bin/.keep +0 -0
  119. data/spec/unit/fixtures/example_app/Policyfile.rb +0 -0
  120. data/spec/unit/fixtures/example_cookbook/.gitignore +17 -0
  121. data/spec/unit/fixtures/example_cookbook/.kitchen.yml +16 -0
  122. data/spec/unit/fixtures/example_cookbook/Berksfile +3 -0
  123. data/spec/unit/fixtures/example_cookbook/README.md +4 -0
  124. data/spec/unit/fixtures/example_cookbook/chefignore +96 -0
  125. data/spec/unit/fixtures/example_cookbook/metadata.rb +8 -0
  126. data/spec/unit/fixtures/example_cookbook/recipes/default.rb +8 -0
  127. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/.kitchen.yml +16 -0
  128. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +3 -0
  129. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/README.md +4 -0
  130. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/chefignore +96 -0
  131. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/metadata.rb +8 -0
  132. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/recipes/default.rb +8 -0
  133. data/spec/unit/fixtures/local_path_cookbooks/metadata-missing/README.md +2 -0
  134. data/spec/unit/policyfile/chef_server_cookbook_source_spec.rb +34 -0
  135. data/spec/unit/policyfile/community_cookbook_source_spec.rb +51 -0
  136. data/spec/unit/policyfile/cookbook_spec_spec.rb +200 -0
  137. data/spec/unit/policyfile/null_cookbook_source_spec.rb +35 -0
  138. data/spec/unit/policyfile_builder_spec.rb +489 -0
  139. data/spec/unit/policyfile_demands_spec.rb +484 -0
  140. data/spec/unit/policyfile_evaluation_spec.rb +284 -0
  141. data/spec/unit/shell_out_spec.rb +34 -0
  142. metadata +422 -0
@@ -0,0 +1,126 @@
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/component_test'
20
+ require 'pathname'
21
+
22
+ describe ChefDK::ComponentTest do
23
+
24
+ let(:component) do
25
+ ChefDK::ComponentTest.new("berkshelf").tap do |c|
26
+ c.base_dir = "berkshelf"
27
+ end
28
+ end
29
+
30
+ it "defines the component" do
31
+ expect(component.name).to eq("berkshelf")
32
+ end
33
+
34
+ it "sets the component base directory" do
35
+ expect(component.base_dir).to eq("berkshelf")
36
+ end
37
+
38
+ it "defines a default unit test" do
39
+ expect(component.run_unit_test.exitstatus).to eq(0)
40
+ expect(component.run_unit_test.stdout).to eq("")
41
+ expect(component.run_unit_test.stderr).to eq("")
42
+ end
43
+
44
+ it "defines a default integration test" do
45
+ expect(component.run_integration_test.exitstatus).to eq(0)
46
+ expect(component.run_integration_test.stdout).to eq("")
47
+ expect(component.run_integration_test.stderr).to eq("")
48
+ end
49
+
50
+ it "defines a default smoke test" do
51
+ expect(component.run_smoke_test.exitstatus).to eq(0)
52
+ expect(component.run_smoke_test.stdout).to eq("")
53
+ expect(component.run_smoke_test.stderr).to eq("")
54
+ end
55
+
56
+ context "with basic tests defined" do
57
+
58
+ let(:result) { {} }
59
+
60
+ before do
61
+ # capture a reference to results hash so we can use it in tests.
62
+ result_hash = result
63
+ component.tap do |c|
64
+ c.unit_test { result_hash[:unit_test] = true }
65
+ c.integration_test { result_hash[:integration_test] = true }
66
+ c.smoke_test { result_hash[:smoke_test] = true }
67
+ end
68
+ end
69
+
70
+ it "defines a unit test block" do
71
+ component.run_unit_test
72
+ expect(result[:unit_test]).to be_true
73
+ end
74
+
75
+ it "defines an integration test block" do
76
+ component.run_integration_test
77
+ expect(result[:integration_test]).to be_true
78
+ end
79
+
80
+ it "defines a smoke test block" do
81
+ component.run_smoke_test
82
+ expect(result[:smoke_test]).to be_true
83
+ end
84
+
85
+ end
86
+
87
+ context "with tests that shell out to commands" do
88
+
89
+ let(:omnibus_root) { File.join(fixtures_path, "eg_omnibus_dir/valid/") }
90
+
91
+ before do
92
+ component.tap do |c|
93
+ # Have to set omnibus dir so command can run with correct cwd
94
+ c.omnibus_root = omnibus_root
95
+
96
+ c.unit_test { sh("true") }
97
+
98
+ c.integration_test { sh("ruby -e 'puts Dir.pwd'", env: { "RUBYOPT" => "" }) }
99
+
100
+ c.smoke_test { run_in_tmpdir("ruby -e 'puts Dir.pwd'", env: { "RUBYOPT" => "" }) }
101
+ end
102
+ end
103
+
104
+ it "shells out and returns the shell out object" do
105
+ expect(component.run_unit_test.exitstatus).to eq(0)
106
+ expect(component.run_unit_test.stdout).to eq("")
107
+ expect(component.run_unit_test.stderr).to eq("")
108
+ end
109
+
110
+ it "runs the command in the app's root" do
111
+ result = component.run_integration_test
112
+ expected_path = Pathname.new(File.join(omnibus_root, "embedded/apps/berkshelf")).realpath
113
+ expect(Pathname.new(result.stdout.strip).realpath).to eq(expected_path)
114
+ end
115
+
116
+ it "runs commands in a temporary directory when specified" do
117
+ result = component.run_smoke_test
118
+
119
+ parent_of_cwd = Pathname.new(result.stdout.strip).parent.realpath
120
+ tempdir = Pathname.new(Dir.tmpdir).realpath
121
+ expect(parent_of_cwd).to eq(tempdir)
122
+ end
123
+
124
+ end
125
+
126
+ end
@@ -0,0 +1,62 @@
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/cookbook_metadata'
20
+
21
+ describe ChefDK::CookbookMetadata do
22
+
23
+ describe "providing the API required by CookbookOmnifetch" do
24
+
25
+ let(:metadata) { ChefDK::CookbookMetadata.new }
26
+
27
+ it "provides a `from_path` class method" do
28
+ expect(described_class).to respond_to(:from_path)
29
+ end
30
+
31
+ it "responds to #cookbook_name" do
32
+ expect(metadata).to respond_to(:cookbook_name)
33
+ end
34
+
35
+ it "responds to #version" do
36
+ expect(metadata).to respond_to(:version)
37
+ end
38
+
39
+ end
40
+
41
+ describe "when a cookbook is loaded" do
42
+
43
+ let(:cookbook_root) { File.join(fixtures_path, 'example_cookbook') }
44
+
45
+ let(:cookbook) { described_class.from_path(cookbook_root) }
46
+
47
+ it "has a name" do
48
+ expect(cookbook.name).to eq("example_cookbook")
49
+ expect(cookbook.cookbook_name).to eq("example_cookbook")
50
+ end
51
+
52
+ it "has a version" do
53
+ expect(cookbook.version).to eq("0.1.0")
54
+ end
55
+
56
+ it "has a map of dependencies" do
57
+ expect(cookbook.dependencies).to eq({})
58
+ end
59
+
60
+ end
61
+ end
62
+
@@ -0,0 +1,127 @@
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 'shared/setup_git_cookbooks'
20
+ require 'fileutils'
21
+ require 'chef-dk/helpers'
22
+ require 'chef-dk/cookbook_profiler/git'
23
+
24
+ describe ChefDK::CookbookProfiler::Git do
25
+
26
+ include ChefDK::Helpers
27
+
28
+ include_context "setup git cookbooks"
29
+
30
+ let(:git_profiler) do
31
+ ChefDK::CookbookProfiler::Git.new(cookbook_path)
32
+ end
33
+
34
+ def edit_repo
35
+ File.open(File.join(cookbook_path, "README.md"), "a+") { |f| f.puts "some unpublished changes" }
36
+ end
37
+
38
+ context "given a clean repo with no remotes" do
39
+
40
+ it "reports that the repo has no remotes" do
41
+ expect(git_profiler.remote).to be_nil
42
+ end
43
+
44
+ it "determines the rev of the repo" do
45
+ expect(git_profiler.revision).to eq(current_rev)
46
+ end
47
+
48
+ it "reports that the repo is clean" do
49
+ expect(git_profiler.clean?).to be_true
50
+ end
51
+
52
+ it "reports that the commits are unpublished" do
53
+ expect(git_profiler.unpublished_commits?).to be_true
54
+ end
55
+
56
+ it "reports that no remotes have the commits" do
57
+ expect(git_profiler.synchronized_remotes).to eq([])
58
+ end
59
+
60
+ end
61
+
62
+ context "with a remote configured" do
63
+
64
+ include_context "setup git cookbook remote"
65
+
66
+ context "given a clean repo with all commits published to the remote" do
67
+
68
+ it "determines the remote for the repo" do
69
+ expect(git_profiler.remote).to eq(remote_url)
70
+ end
71
+
72
+ it "determines the rev of the repo" do
73
+ expect(git_profiler.revision).to eq(current_rev)
74
+ end
75
+
76
+ it "reports that the repo is clean" do
77
+ expect(git_profiler.clean?).to be_true
78
+ end
79
+
80
+ it "reports that all commits are published to the upstream" do
81
+ expect(git_profiler.unpublished_commits?).to be_false
82
+ end
83
+
84
+ it "lists the remotes that commits are published to" do
85
+ expect(git_profiler.synchronized_remotes).to eq(%w[origin/master])
86
+ end
87
+
88
+ end
89
+
90
+ context "given a clean repo with unpublished changes" do
91
+
92
+ before do
93
+ edit_repo
94
+ system_command('git config --local user.name "Alice"', cwd: cookbook_path).error!
95
+ system_command('git config --local user.email "alice@example.com"', cwd: cookbook_path).error!
96
+ system_command("git commit -a -m 'update readme' --author 'Alice <alice@example.com>'", cwd: cookbook_path).error!
97
+ end
98
+
99
+ it "reports that the repo is clean" do
100
+ expect(git_profiler.clean?).to be_true
101
+ end
102
+
103
+ it "reports that there are unpublished changes" do
104
+ expect(git_profiler.unpublished_commits?).to be_true
105
+ end
106
+
107
+ it "reports that no remotes have the commits" do
108
+ expect(git_profiler.synchronized_remotes).to eq([])
109
+ end
110
+
111
+ end
112
+ end
113
+
114
+ context "given a dirty repo" do
115
+
116
+ before do
117
+ edit_repo
118
+ end
119
+
120
+ it "reports that the repo is dirty" do
121
+ expect(git_profiler.clean?).to be_false
122
+ end
123
+
124
+ end
125
+
126
+ end
127
+
@@ -0,0 +1,79 @@
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/cookbook_profiler/identifiers'
20
+
21
+ describe ChefDK::CookbookProfiler::Identifiers do
22
+
23
+ let(:cache_path) do
24
+ File.expand_path("spec/unit/fixtures/cookbook_cache", project_root)
25
+ end
26
+
27
+ let(:foo_cookbook_path) do
28
+ File.join(cache_path, "foo-1.0.0")
29
+ end
30
+
31
+ let(:identifiers) do
32
+ ChefDK::CookbookProfiler::Identifiers.new(foo_cookbook_path)
33
+ end
34
+
35
+ let(:cookbook_files_with_cksums) do
36
+ # Entries must be sorted lexically.
37
+ {
38
+ ".kitchen.yml" => "85ba09a085dab072722cb197e04fa805",
39
+ "Berksfile" => "a668a1df3121f22875e754466f535d8a",
40
+ "README.md" => "0f15038071e5a131bef176cbe2a956d1",
41
+ "chefignore" => "03485640b005eb1083c76518764053dd",
42
+ "metadata.rb" => "4879d0004b177546cfbcfb2fd26df7c8",
43
+ "recipes/default.rb" => "9a0f27d741deaca21461073f7452474f"
44
+ }
45
+ end
46
+
47
+ it "has the cookbook's path" do
48
+ expect(identifiers.cookbook_path).to eq(foo_cookbook_path)
49
+ end
50
+
51
+ it "has the cookbook's semver version" do
52
+ expect(identifiers.semver_version).to eq("1.0.0")
53
+ end
54
+
55
+ it "lists the cookbook's files" do
56
+ cookbook_files_with_cksums.each do |path, cksum|
57
+ expect(identifiers.cookbook_files).to have_key(path)
58
+ expect(identifiers.cookbook_files[path]["checksum"]).to eq(cksum)
59
+ end
60
+ end
61
+
62
+ it "generates a sorted list of the cookbook's files with checksums" do
63
+ # Verify that the keys are sorted in our expected data, otherwise our test
64
+ # is wrong.
65
+ expect(cookbook_files_with_cksums.keys).to eq(cookbook_files_with_cksums.keys.sort)
66
+ expected = cookbook_files_with_cksums.map { |path,cksum| "#{path}:#{cksum}\n" }.join("")
67
+ expect(identifiers.fingerprint_text).to eq(expected)
68
+ end
69
+
70
+ it "generates a Hash of the cookbook's content" do
71
+ expect(identifiers.content_identifier).to eq("e4611e9b5ec0636a18979e7dd22537222a2eab47")
72
+ end
73
+
74
+ it "generates a dotted decimal representation of the content hash" do
75
+ expect(identifiers.dotted_decimal_identifier).to eq("64283078773620835.29863387009503781.60619876117319")
76
+ end
77
+
78
+ end
79
+
@@ -0,0 +1,9 @@
1
+ TestHelpers.test_state[:loaded_recipes] ||= []
2
+ TestHelpers.test_state[:loaded_recipes] << "recipe_one"
3
+
4
+ ruby_block "record_test_result_one" do
5
+ block do
6
+ TestHelpers.test_state[:converged_recipes] ||= []
7
+ TestHelpers.test_state[:converged_recipes] << "recipe_one"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ TestHelpers.test_state[:loaded_recipes] ||= []
2
+ TestHelpers.test_state[:loaded_recipes] << "recipe_two"
3
+
4
+ ruby_block "record_test_result_two" do
5
+ block do
6
+ TestHelpers.test_state[:converged_recipes] ||= []
7
+ TestHelpers.test_state[:converged_recipes] << "recipe_two"
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ require 'chef-dk/command/base'
2
+
3
+ module ChefDK
4
+ module Command
5
+ class TestCommand < ChefDK::Command::Base
6
+
7
+ def self.reset!
8
+ @test_result = nil
9
+ end
10
+
11
+ def self.test_result
12
+ @test_result
13
+ end
14
+
15
+ def self.test_result=(result)
16
+ @test_result = result
17
+ end
18
+
19
+ def run(params)
20
+ self.class.test_result = {:status => :success, :params => params}
21
+ 23
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module ChefDK
2
+ module Command
3
+ class ExplicitPathExample
4
+
5
+ end
6
+ end
7
+ end