ohai 15.3.1 → 15.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -6
  3. data/lib/ohai/mixin/{network_constants.rb → network_helper.rb} +8 -1
  4. data/lib/ohai/plugins/aix/network.rb +3 -8
  5. data/lib/ohai/plugins/darwin/network.rb +6 -4
  6. data/lib/ohai/plugins/filesystem.rb +166 -0
  7. data/lib/ohai/plugins/network.rb +5 -5
  8. data/lib/ohai/plugins/openstack.rb +2 -1
  9. data/lib/ohai/plugins/solaris2/network.rb +6 -4
  10. data/lib/ohai/version.rb +1 -1
  11. data/ohai.gemspec +1 -1
  12. metadata +3 -162
  13. data/Rakefile +0 -42
  14. data/lib/ohai/plugins/windows/filesystem.rb +0 -147
  15. data/spec/data/plugins/dpkg-query.output +0 -4
  16. data/spec/data/plugins/lslpp.output +0 -50
  17. data/spec/data/plugins/pacman.output +0 -51
  18. data/spec/data/plugins/pkg-query.output +0 -58
  19. data/spec/data/plugins/pkginfo.output +0 -50
  20. data/spec/data/plugins/pkglist.output +0 -24
  21. data/spec/data/plugins/rpmquery.output +0 -7
  22. data/spec/functional/application_spec.rb +0 -107
  23. data/spec/functional/loader_spec.rb +0 -53
  24. data/spec/functional/plugins/powershell_spec.rb +0 -88
  25. data/spec/functional/plugins/root_group_spec.rb +0 -41
  26. data/spec/functional/plugins/windows/uptime_spec.rb +0 -51
  27. data/spec/ohai_spec.rb +0 -27
  28. data/spec/rcov.opts +0 -2
  29. data/spec/spec.opts +0 -2
  30. data/spec/spec_helper.rb +0 -124
  31. data/spec/support/integration_helper.rb +0 -61
  32. data/spec/support/platform_helpers.rb +0 -38
  33. data/spec/unit/application_spec.rb +0 -96
  34. data/spec/unit/config_spec.rb +0 -57
  35. data/spec/unit/dsl/plugin_spec.rb +0 -634
  36. data/spec/unit/hints_spec.rb +0 -65
  37. data/spec/unit/loader_spec.rb +0 -195
  38. data/spec/unit/mixin/azure_metadata_spec.rb +0 -72
  39. data/spec/unit/mixin/command_spec.rb +0 -151
  40. data/spec/unit/mixin/dmi_decode.rb +0 -75
  41. data/spec/unit/mixin/ec2_metadata_spec.rb +0 -88
  42. data/spec/unit/mixin/softlayer_metadata_spec.rb +0 -72
  43. data/spec/unit/plugin_config_spec.rb +0 -117
  44. data/spec/unit/plugins/abort_spec.rb +0 -69
  45. data/spec/unit/plugins/aix/cpu_spec.rb +0 -127
  46. data/spec/unit/plugins/aix/filesystem_spec.rb +0 -238
  47. data/spec/unit/plugins/aix/hostname_spec.rb +0 -33
  48. data/spec/unit/plugins/aix/kernel_spec.rb +0 -61
  49. data/spec/unit/plugins/aix/memory_spec.rb +0 -49
  50. data/spec/unit/plugins/aix/network_spec.rb +0 -313
  51. data/spec/unit/plugins/aix/platform_spec.rb +0 -44
  52. data/spec/unit/plugins/aix/uptime_spec.rb +0 -42
  53. data/spec/unit/plugins/aix/virtualization_spec.rb +0 -319
  54. data/spec/unit/plugins/azure_spec.rb +0 -243
  55. data/spec/unit/plugins/bsd/filesystem_spec.rb +0 -138
  56. data/spec/unit/plugins/bsd/virtualization_spec.rb +0 -145
  57. data/spec/unit/plugins/c_spec.rb +0 -341
  58. data/spec/unit/plugins/chef_spec.rb +0 -44
  59. data/spec/unit/plugins/cloud_spec.rb +0 -484
  60. data/spec/unit/plugins/darwin/cpu_spec.rb +0 -124
  61. data/spec/unit/plugins/darwin/filesystem_spec.rb +0 -140
  62. data/spec/unit/plugins/darwin/hardware_spec.rb +0 -105
  63. data/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +0 -1110
  64. data/spec/unit/plugins/darwin/hostname_spec.rb +0 -43
  65. data/spec/unit/plugins/darwin/kernel_spec.rb +0 -65
  66. data/spec/unit/plugins/darwin/memory_spec.rb +0 -64
  67. data/spec/unit/plugins/darwin/network_spec.rb +0 -849
  68. data/spec/unit/plugins/darwin/platform_spec.rb +0 -71
  69. data/spec/unit/plugins/darwin/virtualization_spec.rb +0 -156
  70. data/spec/unit/plugins/digital_ocean_spec.rb +0 -106
  71. data/spec/unit/plugins/dmi_spec.rb +0 -156
  72. data/spec/unit/plugins/docker_spec.rb +0 -100
  73. data/spec/unit/plugins/ec2_spec.rb +0 -452
  74. data/spec/unit/plugins/elixir_spec.rb +0 -55
  75. data/spec/unit/plugins/erlang_spec.rb +0 -71
  76. data/spec/unit/plugins/eucalyptus_spec.rb +0 -109
  77. data/spec/unit/plugins/fail_spec.rb +0 -260
  78. data/spec/unit/plugins/freebsd/cpu_spec.rb +0 -129
  79. data/spec/unit/plugins/freebsd/hostname_spec.rb +0 -35
  80. data/spec/unit/plugins/freebsd/kernel_spec.rb +0 -36
  81. data/spec/unit/plugins/freebsd/platform_spec.rb +0 -38
  82. data/spec/unit/plugins/gce_spec.rb +0 -81
  83. data/spec/unit/plugins/go_spec.rb +0 -48
  84. data/spec/unit/plugins/groovy_spec.rb +0 -66
  85. data/spec/unit/plugins/haskell_spec.rb +0 -231
  86. data/spec/unit/plugins/hostname_spec.rb +0 -162
  87. data/spec/unit/plugins/init_package_spec.rb +0 -60
  88. data/spec/unit/plugins/java_spec.rb +0 -230
  89. data/spec/unit/plugins/joyent_spec.rb +0 -100
  90. data/spec/unit/plugins/kernel_spec.rb +0 -38
  91. data/spec/unit/plugins/linode_spec.rb +0 -135
  92. data/spec/unit/plugins/linux/block_device_spec.rb +0 -75
  93. data/spec/unit/plugins/linux/cpu_spec.rb +0 -441
  94. data/spec/unit/plugins/linux/filesystem_spec.rb +0 -550
  95. data/spec/unit/plugins/linux/fips_spec.rb +0 -60
  96. data/spec/unit/plugins/linux/hostname_spec.rb +0 -52
  97. data/spec/unit/plugins/linux/hostnamectl_spec.rb +0 -59
  98. data/spec/unit/plugins/linux/kernel_spec.rb +0 -71
  99. data/spec/unit/plugins/linux/lsb_spec.rb +0 -147
  100. data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
  101. data/spec/unit/plugins/linux/machineid_spec.rb +0 -46
  102. data/spec/unit/plugins/linux/mdadm_spec.rb +0 -170
  103. data/spec/unit/plugins/linux/memory_spec.rb +0 -256
  104. data/spec/unit/plugins/linux/network_spec.rb +0 -1392
  105. data/spec/unit/plugins/linux/platform_spec.rb +0 -812
  106. data/spec/unit/plugins/linux/sessions_spec.rb +0 -98
  107. data/spec/unit/plugins/linux/sysctl_spec.rb +0 -53
  108. data/spec/unit/plugins/linux/systemd_paths_spec.rb +0 -122
  109. data/spec/unit/plugins/linux/uptime_spec.rb +0 -48
  110. data/spec/unit/plugins/linux/virtualization_spec.rb +0 -650
  111. data/spec/unit/plugins/lua_spec.rb +0 -60
  112. data/spec/unit/plugins/mono_spec.rb +0 -67
  113. data/spec/unit/plugins/netbsd/hostname_spec.rb +0 -43
  114. data/spec/unit/plugins/netbsd/kernel_spec.rb +0 -35
  115. data/spec/unit/plugins/netbsd/platform_spec.rb +0 -38
  116. data/spec/unit/plugins/network_spec.rb +0 -1078
  117. data/spec/unit/plugins/nodejs_spec.rb +0 -55
  118. data/spec/unit/plugins/ohai_spec.rb +0 -32
  119. data/spec/unit/plugins/ohai_time_spec.rb +0 -44
  120. data/spec/unit/plugins/openbsd/hostname_spec.rb +0 -43
  121. data/spec/unit/plugins/openbsd/kernel_spec.rb +0 -36
  122. data/spec/unit/plugins/openbsd/platform_spec.rb +0 -33
  123. data/spec/unit/plugins/openstack_spec.rb +0 -311
  124. data/spec/unit/plugins/os_spec.rb +0 -115
  125. data/spec/unit/plugins/packages_spec.rb +0 -353
  126. data/spec/unit/plugins/passwd_spec.rb +0 -65
  127. data/spec/unit/plugins/perl_spec.rb +0 -62
  128. data/spec/unit/plugins/php_spec.rb +0 -97
  129. data/spec/unit/plugins/platform_spec.rb +0 -65
  130. data/spec/unit/plugins/powershell_spec.rb +0 -71
  131. data/spec/unit/plugins/python_spec.rb +0 -51
  132. data/spec/unit/plugins/rackspace_spec.rb +0 -350
  133. data/spec/unit/plugins/root_group_spec.rb +0 -90
  134. data/spec/unit/plugins/ruby_spec.rb +0 -60
  135. data/spec/unit/plugins/rust_spec.rb +0 -43
  136. data/spec/unit/plugins/scala_spec.rb +0 -58
  137. data/spec/unit/plugins/scaleway_spec.rb +0 -93
  138. data/spec/unit/plugins/scsi_spec.rb +0 -69
  139. data/spec/unit/plugins/shard_spec.rb +0 -121
  140. data/spec/unit/plugins/shells_spec.rb +0 -56
  141. data/spec/unit/plugins/softlayer_spec.rb +0 -60
  142. data/spec/unit/plugins/solaris2/cpu_spec.rb +0 -2926
  143. data/spec/unit/plugins/solaris2/dmi_spec.rb +0 -153
  144. data/spec/unit/plugins/solaris2/filesystem.rb +0 -407
  145. data/spec/unit/plugins/solaris2/hostname_spec.rb +0 -37
  146. data/spec/unit/plugins/solaris2/kernel_spec.rb +0 -183
  147. data/spec/unit/plugins/solaris2/memory_spec.rb +0 -43
  148. data/spec/unit/plugins/solaris2/network_spec.rb +0 -201
  149. data/spec/unit/plugins/solaris2/platform_spec.rb +0 -108
  150. data/spec/unit/plugins/solaris2/virtualization_spec.rb +0 -97
  151. data/spec/unit/plugins/ssh_host_keys_spec.rb +0 -116
  152. data/spec/unit/plugins/sysconf_spec.rb +0 -680
  153. data/spec/unit/plugins/timezone_spec.rb +0 -30
  154. data/spec/unit/plugins/vbox_host_spec.rb +0 -14
  155. data/spec/unit/plugins/virtualbox_spec.rb +0 -375
  156. data/spec/unit/plugins/vmware_spec.rb +0 -81
  157. data/spec/unit/plugins/windows/cpu_spec.rb +0 -118
  158. data/spec/unit/plugins/windows/filesystem_spec.rb +0 -226
  159. data/spec/unit/plugins/windows/fips_spec.rb +0 -60
  160. data/spec/unit/plugins/windows/kernel_spec.rb +0 -79
  161. data/spec/unit/plugins/windows/memory_spec.rb +0 -52
  162. data/spec/unit/plugins/windows/network_spec.rb +0 -137
  163. data/spec/unit/plugins/windows/system_enclosure_spec.rb +0 -45
  164. data/spec/unit/plugins/windows/uptime_spec.rb +0 -38
  165. data/spec/unit/plugins/windows/virtualization_spec.rb +0 -63
  166. data/spec/unit/plugins/zpools_spec.rb +0 -244
  167. data/spec/unit/provides_map_spec.rb +0 -208
  168. data/spec/unit/runner_spec.rb +0 -422
  169. data/spec/unit/system_spec.rb +0 -416
  170. data/spec/unit/util/file_helper_spec.rb +0 -47
  171. data/spec/unit/util/ip_helper_spec.rb +0 -128
@@ -1,65 +0,0 @@
1
- #
2
- # Author:: Serdar Sutay (<serdar@chef.io>)
3
- # Copyright:: Copyright (c) 2013-2016 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
15
- # implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require "spec_helper"
21
-
22
- describe "Ohai::Hints" do
23
- # We are using the plugins directory infrastructure to test hints
24
- extend IntegrationSupport
25
-
26
- before do
27
- @original_hints = Ohai.config[:hints_path]
28
- end
29
-
30
- after do
31
- Ohai.config[:hints_path] = @original_hints
32
- end
33
-
34
- when_plugins_directory "doesn't contain any hints" do
35
- before do
36
- Ohai.config[:hints_path] = [ path_to(".") ]
37
- end
38
-
39
- it "hint? should return nil" do
40
- expect(Ohai::Hints.hint?("cloud")).to be_nil
41
- end
42
- end
43
-
44
- when_plugins_directory "contains empty and full hints" do
45
- with_plugin("cloud.json", <<~EOF)
46
- {"name":"circus"}
47
- EOF
48
-
49
- with_plugin("cloud_empty.json", <<EOF)
50
- EOF
51
-
52
- before do
53
- Ohai.config[:hints_path] = [ path_to(".") ]
54
- end
55
-
56
- it "hint? should return the data for full hints" do
57
- expect(Ohai::Hints.hint?("cloud")).to eq({ "name" => "circus" })
58
- end
59
-
60
- it "hint? should return empty hash for empty hints" do
61
- expect(Ohai::Hints.hint?("cloud_empty")).to eq({})
62
- end
63
- end
64
-
65
- end
@@ -1,195 +0,0 @@
1
- #
2
- # Author:: Claire McQuin (<claire@chef.io>)
3
- # Copyright:: Copyright (c) 2013-2016 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
15
- # implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require "spec_helper"
21
-
22
- describe Ohai::Loader do
23
- extend IntegrationSupport
24
-
25
- let(:loader) { Ohai::Loader.new(ohai) }
26
- let(:ohai) { double("Ohai::System", data: Mash.new, provides_map: provides_map, logger: Ohai::Log) }
27
- let(:provides_map) { Ohai::ProvidesMap.new }
28
-
29
- describe "#initialize" do
30
- it "returns an Ohai::Loader object" do
31
- loader = Ohai::Loader.new(ohai)
32
- expect(loader).to be_a_kind_of(Ohai::Loader)
33
- end
34
- end
35
-
36
- when_plugins_directory "is an additional plugin path" do
37
- with_plugin("cookbook_a/alpha.rb", <<~EOF)
38
- Ohai.plugin(:Alpha) do
39
- provides "alpha"
40
- end
41
- EOF
42
-
43
- with_plugin("cookbook_b/beta.rb", <<~EOF)
44
- Ohai.plugin(:Beta) do
45
- provides "beta"
46
- end
47
- EOF
48
-
49
- describe "#load_additional" do
50
- it "adds the plugins to the map" do
51
- loader.load_additional(@plugins_directory)
52
- expect(provides_map.map.keys).to include("alpha")
53
- end
54
-
55
- it "returns a set of plugins" do
56
- expect(loader.load_additional(@plugins_directory)).to include(Ohai::NamedPlugin::Alpha)
57
- end
58
- end
59
- end
60
-
61
- when_plugins_directory "contains invalid plugins" do
62
- with_plugin("extra_s.rb", <<~EOF)
63
- Ohai.plugins(:ExtraS) do
64
- provides "the_letter_s"
65
- end
66
- EOF
67
-
68
- with_plugin("no_method.rb", <<~EOF)
69
- Ohai.plugin(:NoMethod) do
70
- really_wants "this_attribute"
71
- end
72
- EOF
73
-
74
- with_plugin("illegal_def.rb", <<~EOF)
75
- Ohai.plugin(:Zoo) do
76
- collect_data(:darwin) do
77
- end
78
- collect_data(:darwin) do
79
- end
80
- end
81
- EOF
82
-
83
- with_plugin("unexpected_error.rb", <<~EOF)
84
- Ohai.plugin(:Zoo) do
85
- raise "You aren't expecting this."
86
- end
87
- EOF
88
-
89
- with_plugin("bad_symbol.rb", <<~EOF)
90
- Ohai.plugin(:1nval!d) do
91
- provides "not_a_symbol"
92
- end
93
- EOF
94
-
95
- with_plugin("no_end.rb", <<~EOF)
96
- Ohai.plugin(:NoEnd) do
97
- provides "fish_oil"
98
- collect_data do
99
- end
100
- EOF
101
-
102
- with_plugin("bad_name.rb", <<~EOF)
103
- Ohai.plugin(:you_give_plugins_a_bad_name) do
104
- provides "that/one/song"
105
- end
106
- EOF
107
-
108
- describe "load_plugin() method" do
109
- describe "when the plugin uses Ohai.plugin instead of Ohai.plugins" do
110
- it "logs an unsupported operation warning" do
111
- expect(loader.logger).to receive(:warn).with(/Plugin Method Error: <#{path_to("extra_s.rb")}>:/)
112
- loader.load_plugin(path_to("extra_s.rb"))
113
- end
114
-
115
- it "does not raise an error" do
116
- expect { loader.load_plugin(path_to("extra_s.rb")) }.not_to raise_error
117
- end
118
- end
119
-
120
- describe "when the plugin tries to call an unexisting method" do
121
- it "shoud log an unsupported operation warning" do
122
- expect(loader.logger).to receive(:warn).with(/Plugin Method Error: <#{path_to("no_method.rb")}>:/)
123
- loader.load_plugin(path_to("no_method.rb"))
124
- end
125
-
126
- it "does not raise an error" do
127
- expect { loader.load_plugin(path_to("no_method.rb")) }.not_to raise_error
128
- end
129
- end
130
-
131
- describe "when the plugin defines collect_data on the same platform more than once" do
132
- it "shoud log an illegal plugin definition warning" do
133
- expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/)
134
- loader.load_plugin(path_to("illegal_def.rb"))
135
- end
136
-
137
- it "does not raise an error" do
138
- expect { loader.load_plugin(path_to("illegal_def.rb")) }.not_to raise_error
139
- end
140
- end
141
-
142
- describe "when an unexpected error is encountered" do
143
- it "logs a warning" do
144
- expect(loader.logger).to receive(:warn).with(/Plugin Error: <#{path_to("unexpected_error.rb")}>:/)
145
- loader.load_plugin(path_to("unexpected_error.rb"))
146
- end
147
-
148
- it "does not raise an error" do
149
- expect { loader.load_plugin(path_to("unexpected_error.rb")) }.not_to raise_error
150
- end
151
- end
152
-
153
- describe "when the plugin name symbol has bad syntax" do
154
- it "logs a syntax error warning" do
155
- expect(loader.logger).to receive(:warn).with(/Plugin Syntax Error: <#{path_to("bad_symbol.rb")}>:/)
156
- loader.load_plugin(path_to("bad_symbol.rb"))
157
- end
158
-
159
- it "does not raise an error" do
160
- expect { loader.load_plugin(path_to("bad_symbol.rb")) }.not_to raise_error
161
- end
162
- end
163
-
164
- describe "when the plugin forgets an 'end'" do
165
- it "logs a syntax error warning" do
166
- expect(loader.logger).to receive(:warn).with(/Plugin Syntax Error: <#{path_to("no_end.rb")}>:/)
167
- loader.load_plugin(path_to("no_end.rb"))
168
- end
169
-
170
- it "does not raise an error" do
171
- expect { loader.load_plugin(path_to("no_end.rb")) }.not_to raise_error
172
- end
173
- end
174
-
175
- describe "when the plugin has an invalid name" do
176
- it "logs an invalid plugin name warning" do
177
- expect(loader.logger).to receive(:warn).with(/Plugin Name Error: <#{path_to("bad_name.rb")}>:/)
178
- loader.load_plugin(path_to("bad_name.rb"))
179
- end
180
-
181
- it "does not raise an error" do
182
- expect { loader.load_plugin(path_to("bad_name.rb")) }.not_to raise_error
183
- end
184
- end
185
-
186
- describe "when plugin directory does not exist" do
187
- it "logs an invalid plugin path warning" do
188
- expect(Ohai::Log).to receive(:debug).with(/The plugin path.*does not exist/)
189
- allow(Dir).to receive(:exist?).with("/bogus/dir").and_return(false)
190
- loader.plugin_files_by_dir("/bogus/dir")
191
- end
192
- end
193
- end
194
- end
195
- end
@@ -1,72 +0,0 @@
1
- #
2
- # Author:: Tim Smith <tsmith@chef.io>
3
- # Copyright:: 2017 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 CONDIT"Net::HTTP Response"NS 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 "ohai/mixin/azure_metadata"
21
-
22
- describe Ohai::Mixin::AzureMetadata do
23
- let(:mixin) do
24
- mixin = Object.new.extend(::Ohai::Mixin::AzureMetadata)
25
- mixin
26
- end
27
-
28
- before do
29
- logger = instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil)
30
- allow(mixin).to receive(:logger).and_return(logger)
31
- end
32
-
33
- describe "#http_get" do
34
- it "gets the passed URI" do
35
- http_mock = double("http")
36
- allow(http_mock).to receive(:read_timeout=)
37
- allow(Net::HTTP).to receive(:start).with("169.254.169.254").and_return(http_mock)
38
-
39
- expect(http_mock).to receive(:get).with("http://www.chef.io", { "Metadata" => "true" })
40
- mixin.http_get("http://www.chef.io")
41
- end
42
- end
43
-
44
- describe "#fetch_metadata" do
45
- it "returns an empty hash given a non-200 response" do
46
- http_mock = double("http", { code: "500" })
47
- allow(mixin).to receive(:http_get).and_return(http_mock)
48
-
49
- expect(mixin.logger).to receive(:warn)
50
- vals = mixin.fetch_metadata
51
- expect(vals).to eq(nil)
52
- end
53
-
54
- it "returns an empty hash given invalid JSON response" do
55
- http_mock = double("http", { code: "200", body: '{ "foo" "bar"}' })
56
- allow(mixin).to receive(:http_get).and_return(http_mock)
57
-
58
- expect(mixin.logger).to receive(:warn)
59
- vals = mixin.fetch_metadata
60
- expect(vals).to eq(nil)
61
- end
62
-
63
- it "returns a populated hash given valid JSON response" do
64
- http_mock = double("http", { code: "200", body: '{ "foo": "bar"}' })
65
- allow(mixin).to receive(:http_get).and_return(http_mock)
66
-
67
- expect(mixin.logger).not_to receive(:warn)
68
- vals = mixin.fetch_metadata
69
- expect(vals).to eq({ "foo" => "bar" })
70
- end
71
- end
72
- end
@@ -1,151 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # Author:: Diego Algorta (diego@oboxodo.com)
4
- # Copyright:: Copyright (c) 2009 Diego Algorta
5
- # License:: Apache License, Version 2.0
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
-
20
- require "spec_helper"
21
-
22
- describe Ohai::Mixin::Command, "shell_out" do
23
- let(:cmd) { "sparkle-dream --version" }
24
-
25
- let(:shell_out) { double("Mixlib::ShellOut") }
26
-
27
- let(:plugin_name) { :OSSparkleDream }
28
-
29
- let(:options) { windows? ? { timeout: 30 } : { timeout: 30, env: { "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" } } }
30
-
31
- let(:logger) { instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil) }
32
-
33
- before do
34
- allow(Ohai::Mixin::Command).to receive(:logger).and_return(logger)
35
- allow(Ohai::Mixin::Command).to receive(:name).and_return(plugin_name)
36
- @original_env = ENV.to_hash
37
- ENV.clear
38
- end
39
-
40
- after do
41
- ENV.clear
42
- ENV.update(@original_env)
43
- end
44
-
45
- describe "when the command runs" do
46
- it "logs the command and exitstatus" do
47
- expect(Mixlib::ShellOut)
48
- .to receive(:new)
49
- .with(cmd, options)
50
- .and_return(shell_out)
51
-
52
- expect(shell_out)
53
- .to receive(:run_command)
54
-
55
- expect(shell_out)
56
- .to receive(:exitstatus)
57
- .and_return(256)
58
-
59
- expect(logger).to receive(:trace)
60
- .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and returned 256")
61
-
62
- Ohai::Mixin::Command.shell_out(cmd)
63
- end
64
- end
65
-
66
- describe "when the command does not exist" do
67
- it "logs the command and error message" do
68
- expect(Mixlib::ShellOut)
69
- .to receive(:new)
70
- .with(cmd, options)
71
- .and_return(shell_out)
72
-
73
- expect(shell_out)
74
- .to receive(:run_command)
75
- .and_raise(Errno::ENOENT, "sparkle-dream")
76
-
77
- expect(logger)
78
- .to receive(:trace)
79
- .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and failed " \
80
- "#<Errno::ENOENT: No such file or directory - sparkle-dream>")
81
-
82
- expect { Ohai::Mixin::Command.shell_out(cmd) }
83
- .to raise_error(Ohai::Exceptions::Exec)
84
- end
85
- end
86
-
87
- describe "when the command times out" do
88
- it "logs the command an timeout error message" do
89
- expect(Mixlib::ShellOut)
90
- .to receive(:new)
91
- .with(cmd, options)
92
- .and_return(shell_out)
93
-
94
- expect(shell_out)
95
- .to receive(:run_command)
96
- .and_raise(Mixlib::ShellOut::CommandTimeout)
97
-
98
- expect(logger)
99
- .to receive(:trace)
100
- .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed " \
101
- "out after 30 seconds")
102
-
103
- expect { Ohai::Mixin::Command.shell_out(cmd) }
104
- .to raise_error(Ohai::Exceptions::Exec)
105
- end
106
- end
107
-
108
- describe "when a timeout option is provided" do
109
- let(:options) { windows? ? { timeout: 10 } : { timeout: 10, env: { "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" } } }
110
-
111
- it "runs the command with the provided timeout" do
112
- expect(Mixlib::ShellOut)
113
- .to receive(:new)
114
- .with(cmd, options)
115
- .and_return(shell_out)
116
-
117
- expect(shell_out)
118
- .to receive(:run_command)
119
-
120
- expect(shell_out)
121
- .to receive(:exitstatus)
122
- .and_return(256)
123
-
124
- expect(logger).to receive(:trace)
125
- .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and returned 256")
126
-
127
- Ohai::Mixin::Command.shell_out(cmd, options)
128
- end
129
-
130
- describe "when the command times out" do
131
- it "logs the command an timeout error message" do
132
- expect(Mixlib::ShellOut)
133
- .to receive(:new)
134
- .with(cmd, options)
135
- .and_return(shell_out)
136
-
137
- expect(shell_out)
138
- .to receive(:run_command)
139
- .and_raise(Mixlib::ShellOut::CommandTimeout)
140
-
141
- expect(logger)
142
- .to receive(:trace)
143
- .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed " \
144
- "out after 10 seconds")
145
-
146
- expect { Ohai::Mixin::Command.shell_out(cmd, options) }
147
- .to raise_error(Ohai::Exceptions::Exec)
148
- end
149
- end
150
- end
151
- end