chef 12.0.0.alpha.1 → 12.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/application.rb +8 -1
  3. data/lib/chef/application/apply.rb +4 -0
  4. data/lib/chef/application/client.rb +7 -7
  5. data/lib/chef/application/solo.rb +21 -13
  6. data/lib/chef/chef_fs/chef_fs_data_store.rb +60 -6
  7. data/lib/chef/chef_fs/config.rb +78 -4
  8. data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +2 -2
  9. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
  10. data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
  11. data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
  12. data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
  13. data/lib/chef/chef_fs/data_handler/data_handler_base.rb +76 -2
  14. data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
  15. data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
  16. data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
  17. data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +30 -0
  18. data/lib/chef/chef_fs/data_handler/organization_invites_data_handler.rb +17 -0
  19. data/lib/chef/chef_fs/data_handler/organization_members_data_handler.rb +17 -0
  20. data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
  21. data/lib/chef/chef_fs/data_handler/user_data_handler.rb +2 -1
  22. data/lib/chef/chef_fs/file_system.rb +0 -1
  23. data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +1 -1
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +5 -1
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +73 -13
  27. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +44 -5
  28. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -1
  29. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -3
  30. data/lib/chef/chef_fs/file_system/org_entry.rb +34 -0
  31. data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +58 -0
  32. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +57 -0
  33. data/lib/chef/chef_fs/file_system/rest_list_entry.rb +13 -4
  34. data/lib/chef/chef_fs/knife.rb +1 -1
  35. data/lib/chef/client.rb +8 -2
  36. data/lib/chef/config.rb +75 -57
  37. data/lib/chef/config_fetcher.rb +6 -21
  38. data/lib/chef/dsl/data_query.rb +48 -3
  39. data/lib/chef/dsl/platform_introspection.rb +42 -0
  40. data/lib/chef/dsl/reboot_pending.rb +6 -3
  41. data/lib/chef/encrypted_data_bag_item.rb +1 -1
  42. data/lib/chef/encrypted_data_bag_item/encryptor.rb +12 -0
  43. data/lib/chef/exceptions.rb +2 -0
  44. data/lib/chef/http/basic_client.rb +14 -0
  45. data/lib/chef/http/json_output.rb +7 -2
  46. data/lib/chef/knife.rb +36 -121
  47. data/lib/chef/knife/bootstrap.rb +68 -54
  48. data/lib/chef/knife/bootstrap/archlinux-gems.erb +6 -1
  49. data/lib/chef/knife/bootstrap/chef-aix.erb +5 -0
  50. data/lib/chef/knife/bootstrap/chef-full.erb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +70 -29
  52. data/lib/chef/knife/search.rb +56 -12
  53. data/lib/chef/knife/serve.rb +1 -1
  54. data/lib/chef/local_mode.rb +10 -4
  55. data/lib/chef/mixin/deep_merge.rb +6 -3
  56. data/lib/chef/mixin/shell_out.rb +33 -17
  57. data/lib/chef/null_logger.rb +72 -0
  58. data/lib/chef/platform.rb +2 -1
  59. data/lib/chef/platform/provider_mapping.rb +1 -1
  60. data/lib/chef/platform/rebooter.rb +54 -0
  61. data/lib/chef/provider/ifconfig.rb +15 -16
  62. data/lib/chef/provider/link.rb +1 -1
  63. data/lib/chef/provider/mount/mount.rb +1 -1
  64. data/lib/chef/provider/mount/solaris.rb +102 -64
  65. data/lib/chef/provider/package/aix.rb +4 -12
  66. data/lib/chef/provider/package/ips.rb +8 -12
  67. data/lib/chef/provider/package/macports.rb +4 -12
  68. data/lib/chef/provider/package/pacman.rb +2 -6
  69. data/lib/chef/provider/package/portage.rb +2 -6
  70. data/lib/chef/provider/package/rpm.rb +4 -12
  71. data/lib/chef/provider/package/solaris.rb +4 -12
  72. data/lib/chef/provider/reboot.rb +69 -0
  73. data/lib/chef/provider/service/debian.rb +10 -10
  74. data/lib/chef/provider/service/freebsd.rb +89 -73
  75. data/lib/chef/provider/service/gentoo.rb +2 -2
  76. data/lib/chef/provider/service/init.rb +6 -4
  77. data/lib/chef/provider/service/insserv.rb +3 -3
  78. data/lib/chef/provider/service/macosx.rb +2 -2
  79. data/lib/chef/provider/service/simple.rb +6 -4
  80. data/lib/chef/provider/service/solaris.rb +1 -1
  81. data/lib/chef/provider/service/systemd.rb +9 -9
  82. data/lib/chef/provider/service/upstart.rb +6 -6
  83. data/lib/chef/provider/subversion.rb +6 -6
  84. data/lib/chef/provider/user/dscl.rb +32 -28
  85. data/lib/chef/provider/user/windows.rb +6 -6
  86. data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
  87. data/lib/chef/providers.rb +1 -0
  88. data/lib/chef/recipe.rb +0 -1
  89. data/lib/chef/resource.rb +3 -5
  90. data/lib/chef/resource/mount.rb +9 -0
  91. data/lib/chef/resource/reboot.rb +48 -0
  92. data/lib/chef/resources.rb +1 -0
  93. data/lib/chef/run_context.rb +25 -0
  94. data/lib/chef/search/query.rb +122 -14
  95. data/lib/chef/util/path_helper.rb +54 -6
  96. data/lib/chef/util/windows/net_user.rb +4 -1
  97. data/lib/chef/version.rb +1 -1
  98. data/lib/chef/win32/api/file.rb +1 -5
  99. data/lib/chef/win32/api/net.rb +1 -0
  100. data/lib/chef/workstation_config_loader.rb +177 -0
  101. data/spec/functional/http/simple_spec.rb +57 -1
  102. data/spec/functional/mixin/shell_out_spec.rb +2 -2
  103. data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +51 -0
  104. data/spec/functional/rebooter_spec.rb +105 -0
  105. data/spec/functional/resource/deploy_revision_spec.rb +0 -4
  106. data/spec/functional/resource/file_spec.rb +26 -3
  107. data/spec/functional/resource/group_spec.rb +5 -3
  108. data/spec/functional/resource/link_spec.rb +16 -16
  109. data/spec/functional/resource/reboot_spec.rb +103 -0
  110. data/spec/integration/client/client_spec.rb +4 -8
  111. data/spec/integration/client/ipv6_spec.rb +1 -1
  112. data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -2
  113. data/spec/integration/knife/delete_spec.rb +39 -0
  114. data/spec/integration/knife/deps_spec.rb +30 -20
  115. data/spec/integration/knife/download_spec.rb +77 -1
  116. data/spec/integration/knife/list_spec.rb +221 -0
  117. data/spec/integration/knife/raw_spec.rb +1 -1
  118. data/spec/integration/knife/show_spec.rb +2 -2
  119. data/spec/integration/knife/upload_spec.rb +154 -1
  120. data/spec/support/pedant/run_pedant.rb +0 -1
  121. data/spec/support/shared/functional/http.rb +8 -1
  122. data/spec/support/shared/integration/integration_helper.rb +11 -19
  123. data/spec/support/shared/unit/platform_introspector.rb +22 -0
  124. data/spec/unit/application/apply.rb +11 -1
  125. data/spec/unit/application/solo_spec.rb +19 -3
  126. data/spec/unit/chef_fs/config_spec.rb +58 -0
  127. data/spec/unit/config_fetcher_spec.rb +1 -3
  128. data/spec/unit/config_spec.rb +247 -220
  129. data/spec/unit/dsl/data_query_spec.rb +165 -23
  130. data/spec/unit/dsl/reboot_pending_spec.rb +1 -7
  131. data/spec/unit/encrypted_data_bag_item_spec.rb +1 -1
  132. data/spec/unit/knife/bootstrap_spec.rb +354 -182
  133. data/spec/unit/knife/core/bootstrap_context_spec.rb +67 -30
  134. data/spec/unit/knife_spec.rb +3 -30
  135. data/spec/unit/mixin/deep_merge_spec.rb +14 -0
  136. data/spec/unit/mixin/shell_out_spec.rb +134 -64
  137. data/spec/unit/provider/ifconfig/debian_spec.rb +19 -9
  138. data/spec/unit/provider/ifconfig/redhat_spec.rb +16 -14
  139. data/spec/unit/provider/ifconfig_spec.rb +3 -3
  140. data/spec/unit/provider/link_spec.rb +5 -5
  141. data/spec/unit/provider/mount/mount_spec.rb +10 -1
  142. data/spec/unit/provider/mount/solaris_spec.rb +185 -11
  143. data/spec/unit/provider/package/aix_spec.rb +5 -17
  144. data/spec/unit/provider/package/ips_spec.rb +8 -21
  145. data/spec/unit/provider/package/macports_spec.rb +12 -12
  146. data/spec/unit/provider/package/pacman_spec.rb +4 -12
  147. data/spec/unit/provider/package/portage_spec.rb +5 -15
  148. data/spec/unit/provider/package/rpm_spec.rb +7 -22
  149. data/spec/unit/provider/package/solaris_spec.rb +5 -16
  150. data/spec/unit/provider/service/arch_service_spec.rb +8 -14
  151. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  152. data/spec/unit/provider/service/freebsd_service_spec.rb +457 -225
  153. data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
  154. data/spec/unit/provider/service/init_service_spec.rb +10 -10
  155. data/spec/unit/provider/service/insserv_service_spec.rb +3 -4
  156. data/spec/unit/provider/service/invokercd_service_spec.rb +8 -9
  157. data/spec/unit/provider/service/macosx_spec.rb +5 -5
  158. data/spec/unit/provider/service/simple_service_spec.rb +4 -6
  159. data/spec/unit/provider/service/solaris_smf_service_spec.rb +1 -3
  160. data/spec/unit/provider/service/systemd_service_spec.rb +20 -20
  161. data/spec/unit/provider/service/upstart_service_spec.rb +15 -17
  162. data/spec/unit/provider/subversion_spec.rb +5 -6
  163. data/spec/unit/provider/user/dscl_spec.rb +2 -1
  164. data/spec/unit/provider/user/windows_spec.rb +7 -0
  165. data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
  166. data/spec/unit/resource/mount_spec.rb +9 -0
  167. data/spec/unit/resource_spec.rb +0 -4
  168. data/spec/unit/rest_spec.rb +1 -1
  169. data/spec/unit/run_context_spec.rb +15 -0
  170. data/spec/unit/search/query_spec.rb +196 -40
  171. data/spec/unit/util/path_helper_spec.rb +111 -28
  172. data/spec/unit/workstation_config_loader_spec.rb +283 -0
  173. metadata +36 -20
  174. data/lib/chef/knife/bootstrap/centos5-gems.erb +0 -62
  175. data/lib/chef/knife/bootstrap/fedora13-gems.erb +0 -44
  176. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +0 -53
  177. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +0 -48
  178. data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +0 -46
  179. data/spec/support/shared/integration/chef_zero_support.rb +0 -130
  180. data/spec/unit/knife/config_file_selection_spec.rb +0 -135
@@ -20,101 +20,184 @@ require 'chef/util/path_helper'
20
20
  require 'spec_helper'
21
21
 
22
22
  describe Chef::Util::PathHelper do
23
- let(:path_helper) { Chef::Util::PathHelper }
23
+ PathHelper = Chef::Util::PathHelper
24
+
25
+ [ false, true ].each do |is_windows|
26
+ context "on #{is_windows ? "windows" : "unix"}" do
27
+ before(:each) do
28
+ Chef::Platform.stub(:windows?).and_return(is_windows)
29
+ end
30
+
31
+ describe "join" do
32
+ it "joins components when some end with separators" do
33
+ expected = PathHelper.cleanpath("/foo/bar/baz")
34
+ expected = "C:#{expected}" if is_windows
35
+ PathHelper.join(is_windows ? 'C:\\foo\\' : "/foo/", "bar", "baz").should == expected
36
+ end
37
+
38
+ it "joins components when some end and start with separators" do
39
+ expected = PathHelper.cleanpath("/foo/bar/baz")
40
+ expected = "C:#{expected}" if is_windows
41
+ PathHelper.join(is_windows ? 'C:\\foo\\' : "/foo/", "bar/", "/baz").should == expected
42
+ end
43
+
44
+ it "joins components that don't end in separators" do
45
+ expected = PathHelper.cleanpath("/foo/bar/baz")
46
+ expected = "C:#{expected}" if is_windows
47
+ PathHelper.join(is_windows ? 'C:\\foo' : "/foo", "bar", "baz").should == expected
48
+ end
49
+
50
+ it "joins starting with '' resolve to absolute paths" do
51
+ PathHelper.join('', 'a', 'b').should == "#{PathHelper.path_separator}a#{PathHelper.path_separator}b"
52
+ end
53
+
54
+ it "joins ending with '' add a / to the end" do
55
+ PathHelper.join('a', 'b', '').should == "a#{PathHelper.path_separator}b#{PathHelper.path_separator}"
56
+ end
57
+
58
+ if is_windows
59
+ it "joins components on Windows when some end with unix separators" do
60
+ PathHelper.join('C:\\foo/', "bar", "baz").should == 'C:\\foo\\bar\\baz'
61
+ end
62
+ end
63
+ end
64
+
65
+ if is_windows
66
+ it "path_separator is \\" do
67
+ PathHelper.path_separator.should == '\\'
68
+ end
69
+ else
70
+ it "path_separator is /" do
71
+ PathHelper.path_separator.should == '/'
72
+ end
73
+ end
74
+
75
+ if is_windows
76
+ it "cleanpath changes slashes into backslashes and leaves backslashes alone" do
77
+ PathHelper.cleanpath('/a/b\\c/d/').should == '\\a\\b\\c\\d'
78
+ end
79
+ it "cleanpath does not remove leading double backslash" do
80
+ PathHelper.cleanpath('\\\\a/b\\c/d/').should == '\\\\a\\b\\c\\d'
81
+ end
82
+ else
83
+ it "cleanpath removes extra slashes alone" do
84
+ PathHelper.cleanpath('/a///b/c/d/').should == '/a/b/c/d'
85
+ end
86
+ end
87
+
88
+ describe "dirname" do
89
+ it "dirname('abc') is '.'" do
90
+ PathHelper.dirname('abc').should == '.'
91
+ end
92
+ it "dirname('/') is '/'" do
93
+ PathHelper.dirname(PathHelper.path_separator).should == PathHelper.path_separator
94
+ end
95
+ it "dirname('a/b/c') is 'a/b'" do
96
+ PathHelper.dirname(PathHelper.join('a', 'b', 'c')).should == PathHelper.join('a', 'b')
97
+ end
98
+ it "dirname('a/b/c/') is 'a/b'" do
99
+ PathHelper.dirname(PathHelper.join('a', 'b', 'c', '')).should == PathHelper.join('a', 'b')
100
+ end
101
+ it "dirname('/a/b/c') is '/a/b'" do
102
+ PathHelper.dirname(PathHelper.join('', 'a', 'b', 'c')).should == PathHelper.join('', 'a', 'b')
103
+ end
104
+ end
105
+ end
106
+ end
24
107
 
25
108
  describe "validate_path" do
26
109
  context "on windows" do
27
110
  before(:each) do
28
111
  # pass by default
29
112
  Chef::Platform.stub(:windows?).and_return(true)
30
- path_helper.stub(:printable?).and_return(true)
31
- path_helper.stub(:windows_max_length_exceeded?).and_return(false)
113
+ PathHelper.stub(:printable?).and_return(true)
114
+ PathHelper.stub(:windows_max_length_exceeded?).and_return(false)
32
115
  end
33
116
 
34
117
  it "returns the path if the path passes the tests" do
35
- expect(path_helper.validate_path("C:\\ThisIsRigged")).to eql("C:\\ThisIsRigged")
118
+ expect(PathHelper.validate_path("C:\\ThisIsRigged")).to eql("C:\\ThisIsRigged")
36
119
  end
37
120
 
38
121
  it "does not raise an error if everything looks great" do
39
- expect { path_helper.validate_path("C:\\cool path\\dude.exe") }.not_to raise_error
122
+ expect { PathHelper.validate_path("C:\\cool path\\dude.exe") }.not_to raise_error
40
123
  end
41
124
 
42
125
  it "raises an error if the path has invalid characters" do
43
- path_helper.stub(:printable?).and_return(false)
44
- expect { path_helper.validate_path("Newline!\n") }.to raise_error(Chef::Exceptions::ValidationFailed)
126
+ PathHelper.stub(:printable?).and_return(false)
127
+ expect { PathHelper.validate_path("Newline!\n") }.to raise_error(Chef::Exceptions::ValidationFailed)
45
128
  end
46
129
 
47
130
  it "Adds the \\\\?\\ prefix if the path exceeds MAX_LENGTH and does not have it" do
48
131
  long_path = "C:\\" + "a" * 250 + "\\" + "b" * 250
49
132
  prefixed_long_path = "\\\\?\\" + long_path
50
- path_helper.stub(:windows_max_length_exceeded?).and_return(true)
51
- expect(path_helper.validate_path(long_path)).to eql(prefixed_long_path)
133
+ PathHelper.stub(:windows_max_length_exceeded?).and_return(true)
134
+ expect(PathHelper.validate_path(long_path)).to eql(prefixed_long_path)
52
135
  end
53
136
  end
54
137
  end
55
138
 
56
139
  describe "windows_max_length_exceeded?" do
57
140
  it "returns true if the path is too long (259 + NUL) for the API" do
58
- expect(path_helper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 6)).to be_true
141
+ expect(PathHelper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 6)).to be_true
59
142
  end
60
143
 
61
144
  it "returns false if the path is not too long (259 + NUL) for the standard API" do
62
- expect(path_helper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 5)).to be_false
145
+ expect(PathHelper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 5)).to be_false
63
146
  end
64
147
 
65
148
  it "returns false if the path is over 259 characters but uses the \\\\?\\ prefix" do
66
- expect(path_helper.windows_max_length_exceeded?("\\\\?\\C:\\" + "a" * 250 + "\\" + "b" * 250)).to be_false
149
+ expect(PathHelper.windows_max_length_exceeded?("\\\\?\\C:\\" + "a" * 250 + "\\" + "b" * 250)).to be_false
67
150
  end
68
151
  end
69
152
 
70
153
  describe "printable?" do
71
154
  it "returns true if the string contains no non-printable characters" do
72
- expect(path_helper.printable?("C:\\Program Files (x86)\\Microsoft Office\\Files.lst")).to be_true
155
+ expect(PathHelper.printable?("C:\\Program Files (x86)\\Microsoft Office\\Files.lst")).to be_true
73
156
  end
74
157
 
75
158
  it "returns true when given 'abc' in unicode" do
76
- expect(path_helper.printable?("\u0061\u0062\u0063")).to be_true
159
+ expect(PathHelper.printable?("\u0061\u0062\u0063")).to be_true
77
160
  end
78
161
 
79
162
  it "returns true when given japanese unicode" do
80
- expect(path_helper.printable?("\uff86\uff87\uff88")).to be_true
163
+ expect(PathHelper.printable?("\uff86\uff87\uff88")).to be_true
81
164
  end
82
165
 
83
166
  it "returns false if the string contains a non-printable character" do
84
- expect(path_helper.printable?("\my files\work\notes.txt")).to be_false
167
+ expect(PathHelper.printable?("\my files\work\notes.txt")).to be_false
85
168
  end
86
169
 
87
170
  # This isn't necessarily a requirement, but here to be explicit about functionality.
88
171
  it "returns false if the string contains a newline or tab" do
89
- expect(path_helper.printable?("\tThere's no way,\n\t *no* way,\n\t that you came from my loins.\n")).to be_false
172
+ expect(PathHelper.printable?("\tThere's no way,\n\t *no* way,\n\t that you came from my loins.\n")).to be_false
90
173
  end
91
174
  end
92
175
 
93
176
  describe "canonical_path" do
94
177
  context "on windows", :windows_only do
95
178
  it "returns an absolute path with backslashes instead of slashes" do
96
- expect(path_helper.canonical_path("\\\\?\\C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini")
179
+ expect(PathHelper.canonical_path("\\\\?\\C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini")
97
180
  end
98
181
 
99
182
  it "adds the \\\\?\\ prefix if it is missing" do
100
- expect(path_helper.canonical_path("C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini")
183
+ expect(PathHelper.canonical_path("C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini")
101
184
  end
102
185
 
103
186
  it "returns a lowercase path" do
104
- expect(path_helper.canonical_path("\\\\?\\C:\\CASE\\INSENSITIVE")).to eq("\\\\?\\c:\\case\\insensitive")
187
+ expect(PathHelper.canonical_path("\\\\?\\C:\\CASE\\INSENSITIVE")).to eq("\\\\?\\c:\\case\\insensitive")
105
188
  end
106
189
  end
107
190
 
108
191
  context "not on windows", :unix_only do
109
192
  context "ruby is at least 1.9", :ruby_gte_19_only do
110
193
  it "returns a canonical path" do
111
- expect(path_helper.canonical_path("/etc//apache.d/sites-enabled/../sites-available/default")).to eq("/etc/apache.d/sites-available/default")
194
+ expect(PathHelper.canonical_path("/etc//apache.d/sites-enabled/../sites-available/default")).to eq("/etc/apache.d/sites-available/default")
112
195
  end
113
196
  end
114
197
 
115
198
  context "ruby is less than 1.9", :ruby_18_only do
116
199
  it "returns a canonical path" do
117
- expect { path_helper.canonical_path("/etc//apache.d/sites-enabled/../sites-available/default") }.to raise_error(NotImplementedError)
200
+ expect { PathHelper.canonical_path("/etc//apache.d/sites-enabled/../sites-available/default") }.to raise_error(NotImplementedError)
118
201
  end
119
202
  end
120
203
  end
@@ -122,15 +205,15 @@ describe Chef::Util::PathHelper do
122
205
 
123
206
  describe "paths_eql?" do
124
207
  it "returns true if the paths are the same" do
125
- path_helper.stub(:canonical_path).with("bandit").and_return("c:/bandit/bandit")
126
- path_helper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
127
- expect(path_helper.paths_eql?("bandit", "../bandit/bandit")).to be_true
208
+ PathHelper.stub(:canonical_path).with("bandit").and_return("c:/bandit/bandit")
209
+ PathHelper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
210
+ expect(PathHelper.paths_eql?("bandit", "../bandit/bandit")).to be_true
128
211
  end
129
212
 
130
213
  it "returns false if the paths are different" do
131
- path_helper.stub(:canonical_path).with("bandit").and_return("c:/Bo/Bandit")
132
- path_helper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
133
- expect(path_helper.paths_eql?("bandit", "../bandit/bandit")).to be_false
214
+ PathHelper.stub(:canonical_path).with("bandit").and_return("c:/Bo/Bandit")
215
+ PathHelper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit")
216
+ expect(PathHelper.paths_eql?("bandit", "../bandit/bandit")).to be_false
134
217
  end
135
218
  end
136
219
  end
@@ -0,0 +1,283 @@
1
+ #
2
+ # Author:: Daniel DeLeo (<dan@getchef.com>)
3
+ # Copyright:: Copyright (c) 2014 Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'tempfile'
21
+ require 'chef/workstation_config_loader'
22
+
23
+ describe Chef::WorkstationConfigLoader do
24
+
25
+ let(:explicit_config_location) { nil }
26
+
27
+ let(:env) { {} }
28
+
29
+ let(:config_loader) do
30
+ described_class.new(explicit_config_location).tap do |c|
31
+ allow(c).to receive(:env).and_return(env)
32
+ end
33
+ end
34
+
35
+ # Test methods that do I/O or reference external state which are stubbed out
36
+ # elsewhere.
37
+ describe "external dependencies" do
38
+ let(:config_loader) { described_class.new(nil) }
39
+
40
+ it "delegates to ENV for env" do
41
+ expect(config_loader.env).to equal(ENV)
42
+ end
43
+
44
+ it "tests a path's existence" do
45
+ expect(config_loader.path_exists?('/nope/nope/nope/nope/frab/jab/nab')).to be(false)
46
+ expect(config_loader.path_exists?(__FILE__)).to be(true)
47
+ end
48
+
49
+ end
50
+
51
+ describe "locating the config file" do
52
+ context "without an explicit config" do
53
+
54
+ before do
55
+ allow(config_loader).to receive(:path_exists?).with(an_instance_of(String)).and_return(false)
56
+ end
57
+
58
+ it "has no config if HOME is not set" do
59
+ expect(config_loader.config_location).to be(nil)
60
+ expect(config_loader.no_config_found?).to be(true)
61
+ end
62
+
63
+ context "when HOME is set and contains a knife.rb" do
64
+
65
+ let(:home) { "/Users/example.user" }
66
+
67
+ before do
68
+ env["HOME"] = home
69
+ allow(config_loader).to receive(:path_exists?).with("#{home}/.chef/knife.rb").and_return(true)
70
+ end
71
+
72
+ it "uses the config in HOME/.chef/knife.rb" do
73
+ expect(config_loader.config_location).to eq("#{home}/.chef/knife.rb")
74
+ end
75
+
76
+ context "and has a config.rb" do
77
+
78
+ before do
79
+ allow(config_loader).to receive(:path_exists?).with("#{home}/.chef/config.rb").and_return(true)
80
+ end
81
+
82
+ it "uses the config in HOME/.chef/config.rb" do
83
+ expect(config_loader.config_location).to eq("#{home}/.chef/config.rb")
84
+ end
85
+
86
+ context "and/or a parent dir contains a .chef dir" do
87
+
88
+ let(:env_pwd) { "/path/to/cwd" }
89
+
90
+ before do
91
+ if Chef::Platform.windows?
92
+ env["CD"] = env_pwd
93
+ else
94
+ env["PWD"] = env_pwd
95
+ end
96
+
97
+ allow(config_loader).to receive(:path_exists?).with("#{env_pwd}/.chef/knife.rb").and_return(true)
98
+ allow(File).to receive(:exist?).with("#{env_pwd}/.chef").and_return(true)
99
+ allow(File).to receive(:directory?).with("#{env_pwd}/.chef").and_return(true)
100
+ end
101
+
102
+ it "prefers the config from parent_dir/.chef" do
103
+ expect(config_loader.config_location).to eq("#{env_pwd}/.chef/knife.rb")
104
+ end
105
+
106
+ context "and the parent dir's .chef dir has a config.rb" do
107
+
108
+ before do
109
+ allow(config_loader).to receive(:path_exists?).with("#{env_pwd}/.chef/config.rb").and_return(true)
110
+ end
111
+
112
+ it "prefers the config from parent_dir/.chef" do
113
+ expect(config_loader.config_location).to eq("#{env_pwd}/.chef/config.rb")
114
+ end
115
+
116
+ context "and/or the current working directory contains a .chef dir" do
117
+
118
+ let(:cwd) { Dir.pwd }
119
+
120
+ before do
121
+ allow(config_loader).to receive(:path_exists?).with("#{cwd}/knife.rb").and_return(true)
122
+ end
123
+
124
+ it "prefers a knife.rb located in the cwd" do
125
+ expect(config_loader.config_location).to eq("#{cwd}/knife.rb")
126
+ end
127
+
128
+ context "and the CWD's .chef dir has a config.rb" do
129
+
130
+ before do
131
+ allow(config_loader).to receive(:path_exists?).with("#{cwd}/config.rb").and_return(true)
132
+ end
133
+
134
+ it "prefers a config located in the cwd" do
135
+ expect(config_loader.config_location).to eq("#{cwd}/config.rb")
136
+ end
137
+
138
+
139
+ context "and/or KNIFE_HOME is set" do
140
+
141
+ let(:knife_home) { "/path/to/knife/home" }
142
+
143
+ before do
144
+ env["KNIFE_HOME"] = knife_home
145
+ allow(config_loader).to receive(:path_exists?).with("#{knife_home}/knife.rb").and_return(true)
146
+ end
147
+
148
+ it "prefers a knife located in KNIFE_HOME" do
149
+ expect(config_loader.config_location).to eq("/path/to/knife/home/knife.rb")
150
+ end
151
+
152
+ context "and KNIFE_HOME contains a config.rb" do
153
+
154
+ before do
155
+ env["KNIFE_HOME"] = knife_home
156
+ allow(config_loader).to receive(:path_exists?).with("#{knife_home}/config.rb").and_return(true)
157
+ end
158
+
159
+ it "prefers a config.rb located in KNIFE_HOME" do
160
+ expect(config_loader.config_location).to eq("/path/to/knife/home/config.rb")
161
+ end
162
+
163
+ end
164
+
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ context "when the current working dir is inside a symlinked directory" do
174
+ before do
175
+ # pwd according to your shell is /home/someuser/prod/chef-repo, but
176
+ # chef-repo is a symlink to /home/someuser/codes/chef-repo
177
+ env["CD"] = "/home/someuser/prod/chef-repo" # windows
178
+ env["PWD"] = "/home/someuser/prod/chef-repo" # unix
179
+
180
+ Dir.stub(:pwd).and_return("/home/someuser/codes/chef-repo")
181
+ end
182
+
183
+ it "loads the config from the non-dereferenced directory path" do
184
+ expect(File).to receive(:exist?).with("/home/someuser/prod/chef-repo/.chef").and_return(false)
185
+ expect(File).to receive(:exist?).with("/home/someuser/prod/.chef").and_return(true)
186
+ expect(File).to receive(:directory?).with("/home/someuser/prod/.chef").and_return(true)
187
+
188
+ expect(config_loader).to receive(:path_exists?).with("/home/someuser/prod/.chef/knife.rb").and_return(true)
189
+
190
+ expect(config_loader.config_location).to eq("/home/someuser/prod/.chef/knife.rb")
191
+ end
192
+ end
193
+ end
194
+
195
+ context "when given an explicit config to load" do
196
+
197
+ let(:explicit_config_location) { "/path/to/explicit/config.rb" }
198
+
199
+ it "prefers the explicit config" do
200
+ expect(config_loader.config_location).to eq(explicit_config_location)
201
+ end
202
+
203
+ end
204
+ end
205
+
206
+
207
+ describe "loading the config file" do
208
+
209
+ context "when no explicit config is specifed and no implicit config is found" do
210
+
211
+ before do
212
+ allow(config_loader).to receive(:path_exists?).with(an_instance_of(String)).and_return(false)
213
+ end
214
+
215
+ it "skips loading" do
216
+ expect(config_loader.config_location).to be(nil)
217
+ expect(config_loader.load).to be(false)
218
+ end
219
+
220
+ end
221
+
222
+ context "when an explict config is given but it doesn't exist" do
223
+
224
+ let(:explicit_config_location) { "/nope/nope/nope/frab/jab/nab" }
225
+
226
+ it "raises a configuration error" do
227
+ expect { config_loader.load }.to raise_error(Chef::Exceptions::ConfigurationError)
228
+ end
229
+
230
+ end
231
+
232
+ context "when the config file exists" do
233
+
234
+ let(:config_content) { "" }
235
+
236
+ let(:explicit_config_location) do
237
+ # could use described_class, but remove all ':' from the path if so.
238
+ t = Tempfile.new("Chef-WorkstationConfigLoader-rspec-test")
239
+ t.print(config_content)
240
+ t.close
241
+ t.path
242
+ end
243
+
244
+ after { File.unlink(explicit_config_location) }
245
+
246
+ context "and is valid" do
247
+
248
+ let(:config_content) { "config_file_evaluated(true)" }
249
+
250
+ it "loads the config" do
251
+ expect(config_loader.load).to be(true)
252
+ expect(Chef::Config.config_file_evaluated).to be(true)
253
+ end
254
+
255
+ it "sets Chef::Config.config_file" do
256
+ config_loader.load
257
+ expect(Chef::Config.config_file).to eq(explicit_config_location)
258
+ end
259
+ end
260
+
261
+ context "and has a syntax error" do
262
+
263
+ let(:config_content) { "{{{{{:{{" }
264
+
265
+ it "raises a ConfigurationError" do
266
+ expect { config_loader.load }.to raise_error(Chef::Exceptions::ConfigurationError)
267
+ end
268
+ end
269
+
270
+ context "and raises a ruby exception during evaluation" do
271
+
272
+ let(:config_content) { ":foo\n:bar\nraise 'oops'\n:baz\n" }
273
+
274
+ it "raises a ConfigurationError" do
275
+ expect { config_loader.load }.to raise_error(Chef::Exceptions::ConfigurationError)
276
+ end
277
+ end
278
+
279
+ end
280
+
281
+ end
282
+
283
+ end