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,38 +0,0 @@
1
- #
2
- # License:: Apache License, Version 2.0
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you
5
- # may not use this file except in compliance with the License. You may
6
- # obtain a copy of the license at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or
13
- # implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License
16
- #
17
-
18
- def windows?
19
- !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
20
- end
21
-
22
- def unix?
23
- !windows?
24
- end
25
-
26
- def os_x?
27
- !!(RUBY_PLATFORM =~ /darwin/)
28
- end
29
-
30
- def solaris?
31
- !!(RUBY_PLATFORM =~ /solaris/)
32
- end
33
-
34
- def freebsd?
35
- !!(RUBY_PLATFORM =~ /freebsd/)
36
- end
37
-
38
- DEV_NULL = windows? ? "NUL" : "/dev/null"
@@ -1,96 +0,0 @@
1
- #
2
- # Author:: Claire McQuin <claire@chef.io>
3
- # Copyright:: Copyright (c) 2015-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 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/application"
21
-
22
- RSpec.describe "Ohai::Application" do
23
-
24
- let(:argv) { [] }
25
- let(:app) { Ohai::Application.new }
26
-
27
- before do
28
- @original_argv = ARGV
29
- ARGV.replace(argv)
30
- end
31
-
32
- after do
33
- ARGV.replace(@original_argv)
34
- end
35
-
36
- describe "#configure_ohai" do
37
- describe "loading configuration from a file" do
38
- let(:config_file) { "/local/workstation/config" }
39
- let(:config_loader) { instance_double("ChefConfig::WorkstationConfigLoader") }
40
-
41
- context "when specified on the command line" do
42
- let(:argv) { [ "-c", config_file ] }
43
-
44
- before do
45
- if windows?
46
- expect(ChefConfig::WorkstationConfigLoader).to receive(:new)
47
- .with("C:#{config_file}", Ohai::Log)
48
- .and_return(config_loader)
49
- else
50
- expect(ChefConfig::WorkstationConfigLoader).to receive(:new)
51
- .with(config_file, Ohai::Log)
52
- .and_return(config_loader)
53
- end
54
- end
55
-
56
- it "loads the configuration file" do
57
- expect(config_loader).to receive(:load)
58
- app.configure_ohai
59
- end
60
-
61
- context "when the configuration file does not exist" do
62
- it "terminates the application" do
63
- expect(config_loader).to receive(:load).and_raise(ChefConfig::ConfigurationError)
64
- expect(Ohai::Application).to receive(:fatal!)
65
- app.configure_ohai
66
- end
67
- end
68
- end
69
-
70
- context "when a local workstation config exists" do
71
- before do
72
- expect(ChefConfig::WorkstationConfigLoader).to receive(:new)
73
- .with(nil, Ohai::Log)
74
- .and_return(config_loader)
75
- end
76
-
77
- it "loads the configuration file" do
78
- expect(config_loader).to receive(:load)
79
- app.configure_ohai
80
- end
81
- end
82
- end
83
-
84
- context "when CLI options are provided" do
85
- let(:argv) { [ "-d", directory ] }
86
- let(:directory) { "/some/fantastic/plugins" }
87
-
88
- it "does not generate deprecated config warnings for cli options" do
89
- expect(Ohai::Log).not_to receive(:warn)
90
- .with(/Ohai::Config\[:directory\] is deprecated/)
91
- app.configure_ohai
92
- end
93
- end
94
-
95
- end
96
- end
@@ -1,57 +0,0 @@
1
- #
2
- # Author:: Claire McQuin (<claire@chef.io>)
3
- # Copyright:: Copyright (c) 2015-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 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/config"
21
-
22
- RSpec.describe Ohai::Config do
23
-
24
- describe "config_context :ohai" do
25
- describe "option :plugin" do
26
- it "gets configured with a value" do
27
- Ohai::Config.ohai[:plugin][:foo] = true
28
- expect(Ohai::Config.ohai[:plugin]).to have_key(:foo)
29
- expect(Ohai::Config.ohai[:plugin][:foo]).to be true
30
- end
31
-
32
- it "gets configured with a Hash" do
33
- value = { bar: true, baz: true }
34
- Ohai::Config.ohai[:plugin][:foo] = value
35
- expect(Ohai::Config.ohai[:plugin]).to have_key(:foo)
36
- expect(Ohai::Config.ohai[:plugin][:foo]).to eq(value)
37
- end
38
-
39
- it "raises an error if the plugin name is not a symbol" do
40
- expect { Ohai::Config.ohai[:plugin]["foo"] = false }
41
- .to raise_error(Ohai::Exceptions::PluginConfigError, /Expected Symbol/)
42
- end
43
-
44
- it "raises an error if the value Hash has non-Symbol key" do
45
- value = { :bar => true, "baz" => true }
46
- expect { Ohai::Config.ohai[:plugin][:foo] = value }
47
- .to raise_error(Ohai::Exceptions::PluginConfigError, /Expected Symbol/)
48
- end
49
- end
50
- end
51
-
52
- describe "Ohai.config" do
53
- it "returns the ohai config context" do
54
- expect(Ohai.config).to eq(Ohai::Config.ohai)
55
- end
56
- end
57
- end
@@ -1,634 +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"); you
7
- # may not use this file except in compliance with the License. You may
8
- # 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 expressed 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
- shared_examples "Ohai::DSL::Plugin" do
23
- context "#initialize" do
24
- it "sets has_run? to false" do
25
- expect(plugin.has_run?).to be false
26
- end
27
-
28
- it "sets the correct plugin version" do
29
- expect(plugin.version).to eql(version)
30
- end
31
- end
32
-
33
- context "#run" do
34
- before do
35
- allow(plugin).to receive(:run_plugin).and_return(true)
36
- allow(plugin).to receive(:name).and_return(:TestPlugin)
37
- end
38
-
39
- describe "when plugin is enabled" do
40
- before do
41
- allow(Ohai.config).to receive(:[]).with(:disabled_plugins).and_return([ ])
42
- end
43
-
44
- it "runs the plugin" do
45
- expect(plugin).to receive(:run_plugin)
46
- plugin.run
47
- end
48
-
49
- it "sets has_run? to true" do
50
- plugin.run
51
- expect(plugin.has_run?).to be true
52
- end
53
- end
54
-
55
- describe "if the plugin is disabled" do
56
- before do
57
- allow(Ohai.config).to receive(:[]).with(:disabled_plugins).and_return([ :TestPlugin ])
58
- end
59
-
60
- it "does not run the plugin" do
61
- expect(plugin).not_to receive(:run_plugin)
62
- plugin.run
63
- end
64
-
65
- it "logs a message to trace" do
66
- expect(plugin.logger).to receive(:trace).with(/Skipping disabled plugin TestPlugin/)
67
- plugin.run
68
- end
69
-
70
- it "sets has_run? to true" do
71
- plugin.run
72
- expect(plugin.has_run?).to be true
73
- end
74
- end
75
- end
76
-
77
- context "when accessing data via method_missing" do
78
- it "takes a missing method and store the method name as a key, with its arguments as values" do
79
- plugin.guns_n_roses("chinese democracy")
80
- expect(plugin.data["guns_n_roses"]).to eql("chinese democracy")
81
- end
82
-
83
- it "returns the current value of the method name" do
84
- expect(plugin.guns_n_roses("chinese democracy")).to eql("chinese democracy")
85
- end
86
-
87
- it "allows you to get the value of a key by calling method_missing with no arguments" do
88
- plugin.guns_n_roses("chinese democracy")
89
- expect(plugin.guns_n_roses).to eql("chinese democracy")
90
- end
91
- end
92
-
93
- describe "set_attribute" do
94
- it "raises an ArgumentError when given one argument" do
95
- expect { plugin.set_attribute(:tea) }.to raise_error(ArgumentError)
96
- end
97
-
98
- it "lets you set an attribute" do
99
- plugin.set_attribute(:tea, "is soothing")
100
- expect(plugin.data["tea"]).to eql("is soothing")
101
- end
102
-
103
- it "lets you set an attribute to an empty array" do
104
- plugin.set_attribute(:tea, [])
105
- expect(plugin.data["tea"]).to eql([])
106
- end
107
-
108
- it "lets you set an attribute to an empty Mash" do
109
- plugin.set_attribute(:tea, {})
110
- expect(plugin.data["tea"]).to eql({})
111
- end
112
-
113
- it "lets you modify an attribute" do
114
- plugin.data["tea"] = "is soothing"
115
- plugin.set_attribute(:tea, "tastes like plants")
116
- expect(plugin.data["tea"]).to eql("tastes like plants")
117
- end
118
-
119
- it "lets you set a subattribute" do
120
- plugin.data["tea"] = Mash.new
121
- plugin.set_attribute(:tea, :green, "tastes like green")
122
- expect(plugin.data["tea"]["green"]).to eql("tastes like green")
123
- end
124
-
125
- it "lets you set a subattribute to an empty array" do
126
- plugin.set_attribute(:tea, :green, [])
127
- expect(plugin.data["tea"]["green"]).to eql([])
128
- end
129
-
130
- it "lets you set a subattribute to an empty Mash" do
131
- plugin.set_attribute(:tea, :green, {})
132
- expect(plugin.data["tea"]["green"]).to eql({})
133
- end
134
-
135
- it "lets you modify a subattribute" do
136
- plugin.data["tea"] = Mash.new
137
- plugin.data["tea"]["green"] = "tastes like green"
138
- plugin.set_attribute(:tea, :green, "made from leaves")
139
- expect(plugin.data["tea"]["green"]).to eql("made from leaves")
140
- end
141
-
142
- it "raises a TypeError when modifying an attribute that is not a Mash" do
143
- plugin.data["tea"] = Mash.new
144
- plugin.data["tea"] = "is soothing"
145
- expect { plugin.set_attribute(:tea, :green, "tastes like green") }.to raise_error(TypeError)
146
- end
147
-
148
- it "lets you modify a subattribute with an array" do
149
- green = { flavor: "tastes like green" }
150
- black = { flavor: "tastes like black" }
151
- plugin.data[:tea] = [green, black]
152
- plugin.set_attribute(:tea, 0, :source, "made from leaves")
153
- expect(plugin.data[:tea][0][:source]).to eq("made from leaves")
154
- end
155
- end
156
-
157
- context "when getting attributes" do
158
- before do
159
- plugin.set_attribute(:tea, "is soothing")
160
- end
161
-
162
- it "lets you get an attribute" do
163
- expect(plugin.get_attribute("tea")).to eql("is soothing")
164
- end
165
- end
166
-
167
- describe "get_attribute" do
168
- it "requires at least one argument" do
169
- expect { plugin.get_attribute }.to raise_error(ArgumentError)
170
- end
171
-
172
- describe "a top-level attribute" do
173
- before do
174
- plugin.set_attribute(:tea, "is soothing")
175
- end
176
-
177
- describe "as a string" do
178
- it "returns nil when the attribute does not exist" do
179
- expect(plugin.get_attribute("coffee")).to be nil
180
- end
181
-
182
- it "returns the attribute when it exists" do
183
- expect(plugin.get_attribute("tea")).to eql("is soothing")
184
- end
185
- end
186
-
187
- describe "as a symbol" do
188
- it "returns false when the attribute does not exist" do
189
- expect(plugin.get_attribute(:coffee)).to be nil
190
- end
191
-
192
- it "returns true when the attribute exists" do
193
- expect(plugin.get_attribute(:tea)).to eql("is soothing")
194
- end
195
- end
196
- end
197
-
198
- describe "a nested attribute" do
199
- before do
200
- plugin.set_attribute(:the_monarch, { arch_rival: "dr_venture" })
201
- end
202
-
203
- describe "as a list" do
204
- describe "of strings" do
205
- it "returns true when the attribute exists" do
206
- expect(plugin.get_attribute("the_monarch", "arch_rival"))
207
- .to eql("dr_venture")
208
- end
209
-
210
- describe "when the attribute does not exist" do
211
- describe "and the subkey is missing" do
212
- it "returns nil" do
213
- expect(
214
- plugin.get_attribute("the_monarch", "henchmen")
215
- ).to be nil
216
- end
217
- end
218
-
219
- describe "and an intermediate key is missing" do
220
- it "returns nil" do
221
- expect(
222
- plugin.get_attribute("the_monarch", "henchmen",
223
- "corky_knightrider")
224
- ).to be nil
225
- end
226
- end
227
-
228
- describe "and an intermediate key is not a hash" do
229
- it "raises a TypeError" do
230
- expect do
231
- plugin.get_attribute("the_monarch", "arch_rival",
232
- "dr_venture", "since")
233
- end.to raise_error(TypeError,
234
- "Expected Hash but got String.")
235
- end
236
- end
237
- end
238
- end
239
-
240
- describe "of symbols" do
241
- it "returns true when the attribute exists" do
242
- expect(plugin.get_attribute(:the_monarch, :arch_rival))
243
- .to eql("dr_venture")
244
- end
245
-
246
- describe "when the attribute does not exist" do
247
- describe "and the subkey is missing" do
248
- it "returns nil" do
249
- expect(plugin.get_attribute(:the_monarch, :henchmen)).to be nil
250
- end
251
- end
252
-
253
- describe "and an intermediate key is missing" do
254
- it "returns nil" do
255
- expect(
256
- plugin.get_attribute(:the_monarch, :henchmen,
257
- :corky_knightrider)
258
- ).to be nil
259
- end
260
- end
261
-
262
- describe "and an intermediate key is not a hash" do
263
- it "raises a TypeError" do
264
- expect do
265
- plugin.get_attribute(:the_monarch, :arch_rival,
266
- :dr_venture, :since)
267
- end.to raise_error(TypeError,
268
- "Expected Hash but got String.")
269
- end
270
- end
271
- end
272
- end
273
- end
274
- end
275
- end
276
-
277
- describe "attribute?" do
278
- it "requires at least one argument" do
279
- expect { plugin.attribute? }.to raise_error(ArgumentError)
280
- end
281
-
282
- describe "a top-level attribute" do
283
- describe "as a string" do
284
- it "returns false when the attribute does not exist" do
285
- expect(plugin.attribute?("alice in chains")).to eql(false)
286
- end
287
-
288
- it "returns true if an attribute exists with the given name" do
289
- plugin.metallica("death magnetic")
290
- expect(plugin.attribute?("metallica")).to eql(true)
291
- end
292
- end
293
-
294
- describe "as a symbol" do
295
- it "returns false when the attribute does not exist" do
296
- expect(plugin.attribute?(:sparkle_dream)).to be false
297
- end
298
-
299
- it "returns true when the attribute exists" do
300
- plugin.set_attribute("sparkle_dream", { version: 256 })
301
- expect(plugin.attribute?(:sparkle_dream)).to be true
302
- end
303
- end
304
- end
305
-
306
- describe "a nested attribute" do
307
- before do
308
- plugin.set_attribute(:the_monarch, { arch_rival: "dr_venture" })
309
- end
310
-
311
- describe "as a list" do
312
- describe "of strings" do
313
- it "returns true when the attribute exists" do
314
- expect(plugin.attribute?("the_monarch", "arch_rival")).to be true
315
- end
316
-
317
- describe "when the attribute does not exist" do
318
- describe "and the subkey is missing" do
319
- it "returns false" do
320
- expect(
321
- plugin.attribute?("the_monarch", "henchmen")
322
- ).to be false
323
- end
324
- end
325
-
326
- describe "and an intermediate key is missing" do
327
- it "returns false" do
328
- expect(
329
- plugin.attribute?("the_monarch", "henchmen",
330
- "corky_knightrider")
331
- ).to be false
332
- end
333
- end
334
-
335
- describe "and an intermediate key is not a hash" do
336
- it "raises a TypeError" do
337
- expect do
338
- plugin.attribute?("the_monarch", "arch_rival",
339
- "dr_venture", "since")
340
- end.to raise_error(TypeError,
341
- "Expected Hash but got String.")
342
- end
343
- end
344
- end
345
- end
346
-
347
- describe "of symbols" do
348
- it "returns true when the attribute exists" do
349
- expect(plugin.attribute?(:the_monarch, :arch_rival)).to be true
350
- end
351
-
352
- describe "when the attribute does not exist" do
353
- describe "and the subkey is missing" do
354
- it "returns false" do
355
- expect(plugin.attribute?(:the_monarch, :henchmen)).to be false
356
- end
357
- end
358
-
359
- describe "and an intermediate key is missing" do
360
- it "returns false" do
361
- expect(
362
- plugin.attribute?(:the_monarch, :henchmen,
363
- :corky_knightrider)
364
- ).to be false
365
- end
366
- end
367
-
368
- describe "and an intermediate key is not a hash" do
369
- it "raises a TypeError" do
370
- expect do
371
- plugin.attribute?(:the_monarch, :arch_rival,
372
- :dr_venture, :since)
373
- end.to raise_error(TypeError,
374
- "Expected Hash but got String.")
375
- end
376
- end
377
- end
378
- end
379
- end
380
- end
381
- end
382
- end
383
-
384
- describe Ohai::DSL::Plugin::VersionVII do
385
- let(:logger) { Ohai::Log }
386
-
387
- it "does not modify the plugin name when the plugin is named correctly" do
388
- plugin = Ohai.plugin(:FunkyVALIDpluginName) {}.new({}, logger)
389
- expect(plugin.name).to be(:FunkyVALIDpluginName)
390
- end
391
-
392
- describe "when the plugin is named incorrectly" do
393
- context "because the plugin name doesn't start with a capital letter" do
394
- it "raises an Ohai::Exceptions::InvalidPluginName exception" do
395
- expect { Ohai.plugin(:badName) {} }.to raise_error(Ohai::Exceptions::InvalidPluginName, /badName is not a valid plugin name/)
396
- end
397
- end
398
-
399
- context "because the plugin name contains an underscore" do
400
- it "raises an Ohai::Exceptions::InvalidPluginName exception" do
401
- expect { Ohai.plugin(:Bad_Name) {} }.to raise_error(Ohai::Exceptions::InvalidPluginName, /Bad_Name is not a valid plugin name/)
402
- end
403
- end
404
-
405
- context "because the plugin name isn't a symbol" do
406
- it "raises an Ohai::Exceptions::InvalidPluginName exception" do
407
- expect { Ohai.plugin(1138) {} }.to raise_error(Ohai::Exceptions::InvalidPluginName, /1138 is not a valid plugin name/)
408
- end
409
- end
410
- end
411
-
412
- describe "#version" do
413
- it "saves the plugin version as :version7" do
414
- plugin = Ohai.plugin(:Test) {}
415
- expect(plugin.version).to be(:version7)
416
- end
417
- end
418
-
419
- describe "#provides" do
420
- it "collects a single attribute" do
421
- plugin = Ohai.plugin(:Test) { provides("one") }
422
- expect(plugin.provides_attrs).to eql(["one"])
423
- end
424
-
425
- it "collects a list of attributes" do
426
- plugin = Ohai.plugin(:Test) { provides("one", "two", "three") }
427
- expect(plugin.provides_attrs).to eql(%w{one two three})
428
- end
429
-
430
- it "collects from multiple provides statements" do
431
- plugin = Ohai.plugin(:Test) do
432
- provides("one")
433
- provides("two", "three")
434
- provides("four")
435
- end
436
- expect(plugin.provides_attrs).to eql(%w{one two three four})
437
- end
438
-
439
- it "collects attributes across multiple plugin files" do
440
- plugin = Ohai.plugin(:Test) { provides("one") } # rubocop: disable Lint/UselessAssignment
441
- plugin = Ohai.plugin(:Test) { provides("two", "three") }
442
- expect(plugin.provides_attrs).to eql(%w{one two three})
443
- end
444
-
445
- it "collects unique attributes" do
446
- plugin = Ohai.plugin(:Test) { provides("one") } # rubocop: disable Lint/UselessAssignment
447
- plugin = Ohai.plugin(:Test) { provides("one", "two") }
448
- expect(plugin.provides_attrs).to eql(%w{one two})
449
- end
450
- end
451
-
452
- describe "#depends" do
453
- it "collects a single dependency" do
454
- plugin = Ohai.plugin(:Test) { depends("one") }
455
- expect(plugin.depends_attrs).to eql(["one"])
456
- end
457
-
458
- it "collects a list of dependencies" do
459
- plugin = Ohai.plugin(:Test) { depends("one", "two", "three") }
460
- expect(plugin.depends_attrs).to eql(%w{one two three})
461
- end
462
-
463
- it "collects from multiple depends statements" do
464
- plugin = Ohai.plugin(:Test) do
465
- depends("one")
466
- depends("two", "three")
467
- depends("four")
468
- end
469
- expect(plugin.depends_attrs).to eql(%w{one two three four})
470
- end
471
-
472
- it "collects dependencies across multiple plugin files" do
473
- plugin = Ohai.plugin(:Test) { depends("one") } # rubocop: disable Lint/UselessAssignment
474
- plugin = Ohai.plugin(:Test) { depends("two", "three") }
475
- expect(plugin.depends_attrs).to eql(%w{one two three})
476
- end
477
-
478
- it "collects unique attributes" do
479
- plugin = Ohai.plugin(:Test) { depends("one") } # rubocop: disable Lint/UselessAssignment
480
- plugin = Ohai.plugin(:Test) { depends("one", "two") }
481
- expect(plugin.depends_attrs).to eql(%w{one two})
482
- end
483
- end
484
-
485
- describe "#collect_data" do
486
- it "saves as :default if no platform is given" do
487
- plugin = Ohai.plugin(:Test) { collect_data {} }
488
- expect(plugin.data_collector).to have_key(:default)
489
- end
490
-
491
- it "saves a single given platform" do
492
- plugin = Ohai.plugin(:Test) { collect_data(:ubuntu) {} }
493
- expect(plugin.data_collector).to have_key(:ubuntu)
494
- end
495
-
496
- it "saves a list of platforms" do
497
- plugin = Ohai.plugin(:Test) { collect_data(:freebsd, :netbsd, :openbsd) {} }
498
- %i{freebsd netbsd openbsd}.each do |platform|
499
- expect(plugin.data_collector).to have_key(platform)
500
- end
501
- end
502
-
503
- it "saves multiple collect_data blocks" do
504
- plugin = Ohai.plugin(:Test) do
505
- collect_data {}
506
- collect_data(:windows) {}
507
- collect_data(:darwin) {}
508
- end
509
- %i{darwin default windows}.each do |platform|
510
- expect(plugin.data_collector).to have_key(platform)
511
- end
512
- end
513
-
514
- it "saves platforms across multiple plugins" do
515
- plugin = Ohai.plugin(:Test) { collect_data {} }
516
- plugin = Ohai.plugin(:Test) { collect_data(:aix, :sigar) {} }
517
- %i{aix default sigar}.each do |platform|
518
- expect(plugin.data_collector).to have_key(platform)
519
- end
520
- end
521
-
522
- it "fails a platform has already been defined in the same plugin" do
523
- Ohai.plugin(:Test) { collect_data {} }
524
- expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/).twice
525
- Ohai.plugin(:Test) do
526
- collect_data {}
527
- collect_data {}
528
- end
529
- end
530
-
531
- it "fails if a platform has already been defined in another plugin file" do
532
- Ohai.plugin(:Test) { collect_data {} }
533
- expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/)
534
- Ohai.plugin(:Test) do
535
- collect_data {}
536
- end
537
- end
538
- end
539
-
540
- describe "#provides (deprecated)" do
541
- it "logs a warning" do
542
- plugin = Ohai.plugin(:Test).new(Mash.new, logger)
543
- expect_any_instance_of(Mixlib::Log::Child).to receive(:warn).with(/\[UNSUPPORTED OPERATION\]/)
544
- plugin.provides("attribute")
545
- end
546
- end
547
-
548
- describe "#require_plugin (deprecated)" do
549
- it "logs a warning" do
550
- plugin = Ohai.plugin(:Test).new(Mash.new, logger)
551
- expect_any_instance_of(Mixlib::Log::Child).to receive(:warn).with(/\[UNSUPPORTED OPERATION\]/)
552
- plugin.require_plugin("plugin")
553
- end
554
- end
555
-
556
- describe "#configuration" do
557
- let(:plugin) do
558
- klass = Ohai.plugin(camel_name) {}
559
- klass.new({}, logger)
560
- end
561
-
562
- shared_examples_for "plugin config lookup" do
563
- it "returns the configuration option value" do
564
- Ohai.config[:plugin][snake_name][:foo] = true
565
- expect(plugin.configuration(:foo)).to eq(true)
566
- end
567
- end
568
-
569
- describe "a plugin named Abc" do
570
- let(:camel_name) { :Abc }
571
- let(:snake_name) { :abc }
572
-
573
- it "returns nil when the plugin is not configured" do
574
- expect(plugin.configuration(:foo)).to eq(nil)
575
- end
576
-
577
- it "does not auto-vivify an un-configured plugin" do
578
- plugin.configuration(:foo)
579
- expect(Ohai.config[:plugin]).not_to have_key(:test)
580
- end
581
-
582
- it "returns nil when the option is not configured" do
583
- Ohai.config[:plugin][snake_name][:foo] = true
584
- expect(plugin.configuration(:bar)).to eq(nil)
585
- end
586
-
587
- it "returns nil when the suboption is not configured" do
588
- Ohai.config[:plugin][snake_name][:foo] = {}
589
- expect(plugin.configuration(:foo, :bar)).to eq(nil)
590
- end
591
-
592
- include_examples "plugin config lookup"
593
-
594
- it "returns the configuration sub-option value" do
595
- Ohai.config[:plugin][snake_name][:foo] = { bar: true }
596
- expect(plugin.configuration(:foo, :bar)).to eq(true)
597
- end
598
- end
599
-
600
- describe "a plugin named ABC" do
601
- let(:camel_name) { :ABC }
602
- let(:snake_name) { :abc }
603
-
604
- include_examples "plugin config lookup"
605
- end
606
-
607
- describe "a plugin named Abc2" do
608
- let(:camel_name) { :Abc2 }
609
- let(:snake_name) { :abc_2 }
610
-
611
- include_examples "plugin config lookup"
612
- end
613
-
614
- describe "a plugin named AbcAbc" do
615
- let(:camel_name) { :AbcXyz }
616
- let(:snake_name) { :abc_xyz }
617
-
618
- include_examples "plugin config lookup"
619
- end
620
-
621
- describe "a plugin named ABCLmnoXyz" do
622
- let(:camel_name) { :ABCLmnoXyz }
623
- let(:snake_name) { :abc_lmno_xyz }
624
-
625
- include_examples "plugin config lookup"
626
- end
627
- end
628
-
629
- it_behaves_like "Ohai::DSL::Plugin" do
630
- let(:ohai) { Ohai::System.new }
631
- let(:plugin) { Ohai.plugin(:Test).new(ohai.data, ohai.logger) }
632
- let(:version) { :version7 }
633
- end
634
- end