ohey 1.0.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.
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ohey::NetBSD do
4
+ subject { described_class.new }
5
+
6
+ before do
7
+ allow(subject).to receive(:uname_s).and_return("NetBSD\n")
8
+ allow(subject).to receive(:uname_r).and_return("4.5\n")
9
+ end
10
+
11
+ describe '#platform' do
12
+ it 'correctly identifies the platform' do
13
+ expect(subject.name).to eq('netbsd')
14
+ end
15
+ end
16
+
17
+ describe '#family' do
18
+ it 'correctly identifies the platform family' do
19
+ expect(subject.family).to eq('netbsd')
20
+ end
21
+ end
22
+
23
+ describe '#build' do
24
+ it 'correctly identifies the platform build' do
25
+ expect(subject.build).to eq(nil)
26
+ end
27
+ end
28
+
29
+ describe '#version' do
30
+ it 'correctly identifies the platform version' do
31
+ expect(subject.version).to eq('4.5')
32
+ end
33
+ end
34
+ end
data/spec/ohey_spec.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ohey do
4
+ describe '#current_platform' do
5
+ before do
6
+ allow(Ohey).to receive(:os).and_return(:linux)
7
+ end
8
+
9
+ it 'returns the registered platform' do
10
+ expect(Ohey.current_platform).to be_a(Ohey::Linux)
11
+ end
12
+ end
13
+
14
+ describe '#register_platform' do
15
+ it 'registers the platform' do
16
+ Ohey.register_platform(:foo, :foo)
17
+ expect(Ohey.registered_platforms).to include(:foo)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ohey::OpenBSD do
4
+ subject { described_class.new }
5
+
6
+ before do
7
+ allow(subject).to receive(:uname_s).and_return("OpenBSD\n")
8
+ allow(subject).to receive(:uname_r).and_return("4.5\n")
9
+ end
10
+
11
+ describe '#name' do
12
+ it 'correctly identifies the platform' do
13
+ expect(subject.name).to eq('openbsd')
14
+ end
15
+ end
16
+
17
+ describe '#family' do
18
+ it 'correctly identifies the platform family' do
19
+ expect(subject.family).to eq('openbsd')
20
+ end
21
+ end
22
+
23
+ describe '#build' do
24
+ it 'correctly identifies the platform build' do
25
+ expect(subject.build).to eq(nil)
26
+ end
27
+ end
28
+
29
+ describe '#version' do
30
+ it 'correctly identifies the platform version' do
31
+ expect(subject.version).to eq('4.5')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,256 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ohey::Solaris2 do
4
+ subject { described_class.new }
5
+
6
+ before do
7
+ allow(subject).to receive(:uname).and_return(uname_x)
8
+ allow(subject).to receive(:release).and_return(release)
9
+ allow(File).to receive(:exist?).with('/sbin/uname').and_return(true)
10
+ end
11
+
12
+ describe 'on SmartOS' do
13
+ let(:uname_x) do
14
+ <<~UNAME_X.split("\n")
15
+ System = SunOS
16
+ Node = node.example.com
17
+ Release = 5.11
18
+ KernelID = joyent_20120130T201844Z
19
+ Machine = i86pc
20
+ BusType = <unknown>
21
+ Serial = <unknown>
22
+ Users = <unknown>
23
+ OEM# = 0
24
+ Origin# = 1
25
+ NumCPU = 16
26
+ UNAME_X
27
+ end
28
+
29
+ let(:release) do
30
+ [" SmartOS 20120130T201844Z x86_64\n"]
31
+ end
32
+
33
+ describe '#name' do
34
+ it 'correctly identifies the platform' do
35
+ expect(subject.name).to eq('smartos')
36
+ end
37
+ end
38
+
39
+ describe '#family' do
40
+ it 'correctly identifies the platform family' do
41
+ expect(subject.family).to eq('smartos')
42
+ end
43
+ end
44
+
45
+ describe '#build' do
46
+ it 'correctly identifies the platform build' do
47
+ expect(subject.build).to eq('joyent_20120130T201844Z')
48
+ end
49
+ end
50
+
51
+ describe '#version' do
52
+ it 'correctly identifies the platform version' do
53
+ expect(subject.version).to eq('5.11')
54
+ end
55
+ end
56
+ end
57
+
58
+ describe 'on Solaris 11' do
59
+ let(:uname_x) do
60
+ <<~UNAME_X.split("\n")
61
+ System = SunOS
62
+ Node = node.example.com
63
+ Release = 5.11
64
+ KernelID = 11.1
65
+ Machine = i86pc
66
+ BusType = <unknown>
67
+ Serial = <unknown>
68
+ Users = <unknown>
69
+ OEM# = 0
70
+ Origin# = 1
71
+ NumCPU = 1
72
+ UNAME_X
73
+ end
74
+
75
+ let(:release) do
76
+ [" Oracle Solaris 11.1 X86\n"]
77
+ end
78
+
79
+ describe '#name' do
80
+ it 'correctly identifies the platform' do
81
+ expect(subject.name).to eq('solaris2')
82
+ end
83
+ end
84
+
85
+ describe '#family' do
86
+ it 'correctly identifies the platform family' do
87
+ expect(subject.family).to eq('solaris2')
88
+ end
89
+ end
90
+
91
+ describe '#build' do
92
+ it 'correctly identifies the platform build' do
93
+ expect(subject.build).to eq('11.1')
94
+ end
95
+ end
96
+
97
+ describe '#version' do
98
+ it 'correctly identifies the platform version' do
99
+ expect(subject.version).to eq('5.11')
100
+ end
101
+ end
102
+ end
103
+
104
+ describe 'on OmniOS' do
105
+ let(:uname_x) do
106
+ <<~UNAME_X.split("\n")
107
+ System = SunOS
108
+ Node = omniosce-vagrant
109
+ Release = 5.11
110
+ KernelID = omnios-r151026-673c59f55d
111
+ Machine = i86pc
112
+ BusType = <unknown>
113
+ Serial = <unknown>
114
+ Users = <unknown>
115
+ OEM# = 0
116
+ Origin# = 1
117
+ NumCPU = 1
118
+ UNAME_X
119
+ end
120
+
121
+ let(:release) do
122
+ [
123
+ " OmniOS v11 r151026\n Copyright 2017 OmniTI Computer "\
124
+ "Consulting, Inc. All rights reserved.\n Copyright 2018 "\
125
+ "OmniOS Community Edition (OmniOSce) Association.\n All "\
126
+ "rights reserved. Use is subject to licence terms."
127
+ ]
128
+ end
129
+
130
+ describe '#name' do
131
+ it 'correctly identifies the platform' do
132
+ expect(subject.name).to eq('omnios')
133
+ end
134
+ end
135
+
136
+ describe '#family' do
137
+ it 'correctly identifies the platform family' do
138
+ expect(subject.family).to eq('omnios')
139
+ end
140
+ end
141
+
142
+ describe '#build' do
143
+ it 'correctly identifies the platform build' do
144
+ expect(subject.build).to eq('omnios-r151026-673c59f55d')
145
+ end
146
+ end
147
+
148
+ describe '#version' do
149
+ it 'correctly identifies the platform version' do
150
+ expect(subject.version).to eq('151026')
151
+ end
152
+ end
153
+ end
154
+
155
+ describe 'on OpenIndiana Hipster' do
156
+ let(:uname_x) do
157
+ <<~UNAME_X.split("\n")
158
+ System = SunOS
159
+ Node = openindiana
160
+ Release = 5.11
161
+ KernelID = illumos-c3e16711de
162
+ Machine = i86pc
163
+ BusType = <unknown>
164
+ Serial = <unknown>
165
+ Users = <unknown>
166
+ OEM# = 0
167
+ Origin# = 1
168
+ NumCPU = 1
169
+ UNAME_X
170
+ end
171
+
172
+ let(:release) do
173
+ [
174
+ " OpenIndiana Hipster 2020.04 (powered by illumos)\n"\
175
+ " OpenIndiana Project, part of The Illumos Foundation (C) 2010-2020\n"\
176
+ " Use is subject to license terms.\n"\
177
+ " Assembled 03 May 2020"
178
+ ]
179
+ end
180
+
181
+ describe '#name' do
182
+ it 'correctly identifies the platform' do
183
+ expect(subject.name).to eq('openindiana')
184
+ end
185
+ end
186
+
187
+ describe '#family' do
188
+ it 'correctly identifies the platform family' do
189
+ expect(subject.family).to eq('openindiana')
190
+ end
191
+ end
192
+
193
+ describe '#build' do
194
+ it 'correctly identifies the platform build' do
195
+ expect(subject.build).to eq('illumos-c3e16711de')
196
+ end
197
+ end
198
+
199
+ describe '#version' do
200
+ it 'correctly identifies the platform version' do
201
+ expect(subject.version).to eq('2020.04')
202
+ end
203
+ end
204
+ end
205
+
206
+ describe 'on OpenIndiana pre-Hipster' do
207
+ let(:uname_x) do
208
+ <<~UNAME_X.split("\n")
209
+ System = SunOS
210
+ Node = openindiana
211
+ Release = 5.11
212
+ KernelID = illumos-cf2fa55
213
+ Machine = i86pc
214
+ BusType = <unknown>
215
+ Serial = <unknown>
216
+ Users = <unknown>
217
+ OEM# = 0
218
+ Origin# = 1
219
+ NumCPU = 2
220
+ UNAME_X
221
+ end
222
+
223
+ let(:release) do
224
+ [
225
+ " OpenIndiana Development oi_151.1.8 (powered by illumos)\n"\
226
+ " Copyright 2011 Oracle and/or its affiliates. All rights reserved\n"\
227
+ " Use is subject to license terms.\n"\
228
+ " Assembled 20 July 2013"
229
+ ]
230
+ end
231
+
232
+ describe '#name' do
233
+ it 'correctly identifies the platform' do
234
+ expect(subject.name).to eq('openindiana')
235
+ end
236
+ end
237
+
238
+ describe '#family' do
239
+ it 'correctly identifies the platform family' do
240
+ expect(subject.family).to eq('openindiana')
241
+ end
242
+ end
243
+
244
+ describe '#build' do
245
+ it 'correctly identifies the platform build' do
246
+ expect(subject.build).to eq('illumos-cf2fa55')
247
+ end
248
+ end
249
+
250
+ describe '#version' do
251
+ it 'correctly identifies the platform version' do
252
+ expect(subject.version).to eq('151.1.8')
253
+ end
254
+ end
255
+ end
256
+ end
@@ -0,0 +1,17 @@
1
+ $:.push(File.expand_path('.', __dir__))
2
+
3
+ require 'ohey'
4
+ require 'pry-byebug'
5
+
6
+ module SpecHelpers
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.include(SpecHelpers)
11
+
12
+ # config.before do
13
+ # Ohey.registered_platforms.dup.each do |name, klass|
14
+ # Ohey.register_platform(name, klass.new)
15
+ # end
16
+ # end
17
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ohey::Windows do
4
+ subject { described_class.new }
5
+
6
+ before do
7
+ version = double('WIN32OLE', name: 'Version')
8
+ os_type = double('WIN32OLE', name: 'OsType')
9
+ os = double('WIN32OLE', properties_: [version, os_type])
10
+
11
+ allow(os).to receive(:invoke).with(version.name).and_return('6.1.7601')
12
+ allow(os).to receive(:invoke).with(os_type.name).and_return(18)
13
+
14
+ os_wmi = WmiLite::Wmi::Instance.new(os)
15
+ allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).with('Win32_OperatingSystem').and_return(os_wmi)
16
+ end
17
+
18
+ describe '#name' do
19
+ it 'correctly identifies the platform' do
20
+ expect(subject.name).to eq('WINNT')
21
+ end
22
+ end
23
+
24
+ describe '#family' do
25
+ it 'correctly identifies the platform family' do
26
+ expect(subject.family).to eq('windows')
27
+ end
28
+ end
29
+
30
+ describe '#build' do
31
+ it 'correctly identifies the platform build' do
32
+ expect(subject.build).to eq(nil)
33
+ end
34
+ end
35
+
36
+ describe '#version' do
37
+ it 'correctly identifies the platform version' do
38
+ expect(subject.version).to eq('6.1.7601')
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohey
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Dutro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wmi-lite
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: A rewrite of the platform detection logic in ohai, but with fewer dependencies
28
+ and 100% less metaprogramming.
29
+ email:
30
+ - camertron@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - lib/ohey.rb
40
+ - lib/ohey/aix.rb
41
+ - lib/ohey/darwin.rb
42
+ - lib/ohey/dragonflybsd.rb
43
+ - lib/ohey/freebsd.rb
44
+ - lib/ohey/linux.rb
45
+ - lib/ohey/netbsd.rb
46
+ - lib/ohey/openbsd.rb
47
+ - lib/ohey/solaris2.rb
48
+ - lib/ohey/version.rb
49
+ - lib/ohey/windows.rb
50
+ - ohey.gemspec
51
+ - spec/aix_spec.rb
52
+ - spec/darwin_spec.rb
53
+ - spec/dragonflybsd_spec.rb
54
+ - spec/freebsd_spec.rb
55
+ - spec/linux_spec.rb
56
+ - spec/netbsd_spec.rb
57
+ - spec/ohey_spec.rb
58
+ - spec/openbsd_spec.rb
59
+ - spec/solaris2_spec.rb
60
+ - spec/spec_helper.rb
61
+ - spec/windows_spec.rb
62
+ homepage: http://github.com/camertron/ohey
63
+ licenses: []
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.1.4
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: A rewrite of the platform detection logic in ohai, but with fewer dependencies
84
+ and 100% less metaprogramming.
85
+ test_files: []