kpm 0.7.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +138 -0
  4. data/Gemfile +2 -0
  5. data/README.adoc +144 -107
  6. data/Rakefile +2 -1
  7. data/bin/kpm +4 -2
  8. data/kpm.gemspec +11 -8
  9. data/lib/kpm.rb +3 -0
  10. data/lib/kpm/account.rb +268 -338
  11. data/lib/kpm/base_artifact.rb +33 -39
  12. data/lib/kpm/base_installer.rb +69 -83
  13. data/lib/kpm/blob.rb +29 -0
  14. data/lib/kpm/cli.rb +3 -1
  15. data/lib/kpm/coordinates.rb +10 -12
  16. data/lib/kpm/database.rb +94 -113
  17. data/lib/kpm/diagnostic_file.rb +126 -147
  18. data/lib/kpm/formatter.rb +76 -48
  19. data/lib/kpm/inspector.rb +24 -34
  20. data/lib/kpm/installer.rb +53 -46
  21. data/lib/kpm/kaui_artifact.rb +4 -3
  22. data/lib/kpm/killbill_plugin_artifact.rb +10 -7
  23. data/lib/kpm/killbill_server_artifact.rb +13 -12
  24. data/lib/kpm/migrations.rb +26 -11
  25. data/lib/kpm/nexus_helper/actions.rb +52 -9
  26. data/lib/kpm/nexus_helper/cloudsmith_api_calls.rb +83 -0
  27. data/lib/kpm/nexus_helper/github_api_calls.rb +70 -0
  28. data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +130 -108
  29. data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
  30. data/lib/kpm/plugins_directory.rb +9 -8
  31. data/lib/kpm/plugins_directory.yml +14 -173
  32. data/lib/kpm/plugins_manager.rb +29 -24
  33. data/lib/kpm/sha1_checker.rb +31 -18
  34. data/lib/kpm/system.rb +104 -135
  35. data/lib/kpm/system_helpers/cpu_information.rb +56 -55
  36. data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
  37. data/lib/kpm/system_helpers/entropy_available.rb +37 -39
  38. data/lib/kpm/system_helpers/memory_information.rb +52 -51
  39. data/lib/kpm/system_helpers/os_information.rb +45 -47
  40. data/lib/kpm/system_helpers/system_proxy.rb +10 -10
  41. data/lib/kpm/tasks.rb +381 -438
  42. data/lib/kpm/tenant_config.rb +68 -83
  43. data/lib/kpm/tomcat_manager.rb +10 -8
  44. data/lib/kpm/trace_logger.rb +18 -16
  45. data/lib/kpm/uninstaller.rb +81 -14
  46. data/lib/kpm/utils.rb +13 -14
  47. data/lib/kpm/version.rb +3 -1
  48. data/packaging/Gemfile +2 -0
  49. data/pom.xml +211 -40
  50. data/spec/kpm/remote/base_artifact_spec.rb +20 -20
  51. data/spec/kpm/remote/base_installer_spec.rb +35 -34
  52. data/spec/kpm/remote/cloudsmith_api_calls_spec.rb +40 -0
  53. data/spec/kpm/remote/github_api_calls_spec.rb +40 -0
  54. data/spec/kpm/remote/installer_spec.rb +80 -79
  55. data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
  56. data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +25 -30
  57. data/spec/kpm/remote/killbill_server_artifact_spec.rb +17 -16
  58. data/spec/kpm/remote/migrations_spec.rb +12 -11
  59. data/spec/kpm/remote/nexus_facade_spec.rb +32 -28
  60. data/spec/kpm/remote/tenant_config_spec.rb +30 -29
  61. data/spec/kpm/remote/tomcat_manager_spec.rb +4 -3
  62. data/spec/kpm/unit/actions_spec.rb +52 -0
  63. data/spec/kpm/unit/base_artifact_spec.rb +19 -18
  64. data/spec/kpm/unit/cpu_information_spec.rb +67 -0
  65. data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
  66. data/spec/kpm/unit/entropy_information_spec.rb +36 -0
  67. data/spec/kpm/unit/formatter_spec.rb +163 -0
  68. data/spec/kpm/unit/inspector_spec.rb +34 -42
  69. data/spec/kpm/unit/installer_spec.rb +7 -6
  70. data/spec/kpm/unit/memory_information_spec.rb +102 -0
  71. data/spec/kpm/unit/os_information_spec.rb +38 -0
  72. data/spec/kpm/unit/plugins_directory_spec.rb +38 -22
  73. data/spec/kpm/unit/plugins_manager_spec.rb +62 -66
  74. data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
  75. data/spec/kpm/unit/uninstaller_spec.rb +118 -72
  76. data/spec/kpm/unit_mysql/account_spec.rb +127 -142
  77. data/spec/spec_helper.rb +20 -18
  78. data/tasks/package.rake +18 -18
  79. metadata +42 -22
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'kpm/system_helpers/system_proxy'
5
+ require 'kpm/system_helpers/entropy_available'
6
+
7
+ describe KPM::SystemProxy::EntropyAvailable do
8
+ subject { described_class.new }
9
+ let(:entropy_info) { subject.send(:build_hash, data) }
10
+
11
+ context 'when running on Linux' do
12
+ let(:data) { '182' }
13
+
14
+ it {
15
+ expect(subject.labels).to eq([{ label: :entropy },
16
+ { label: :value }])
17
+ }
18
+
19
+ it {
20
+ expect(entropy_info).to eq({ 'entropy_available' => { entropy: 'available', value: '182' } })
21
+ }
22
+ end
23
+
24
+ context 'when running on MacOS' do
25
+ let(:data) { '-' }
26
+
27
+ it {
28
+ expect(subject.labels).to eq([{ label: :entropy },
29
+ { label: :value }])
30
+ }
31
+
32
+ it {
33
+ expect(entropy_info).to eq({ 'entropy_available' => { entropy: 'available', value: '-' } })
34
+ }
35
+ end
36
+ end
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Formatter' do
6
+ describe KPM::Formatter::DefaultFormatter do
7
+ subject { described_class.new(label, input) }
8
+
9
+ context 'when arguments are nil' do
10
+ let(:label) { nil }
11
+ let(:input) { nil }
12
+
13
+ it { expect(subject.size).to eq(0) }
14
+ it { expect(subject.to_s).to eq('') }
15
+ it { expect(subject.label).to eq('') }
16
+ end
17
+
18
+ context 'when arguments are non-nil' do
19
+ let(:label) { 'my_label' }
20
+ let(:input) { 'my_value' }
21
+
22
+ it { expect(subject.size).to eq(8) }
23
+ it { expect(subject.to_s).to eq('my_value') }
24
+ it { expect(subject.label).to eq('MY LABEL') }
25
+ end
26
+ end
27
+
28
+ describe KPM::Formatter::VersionFormatter do
29
+ subject { described_class.new(label, versions) }
30
+
31
+ context 'when arguments are nil/empty' do
32
+ let(:label) { nil }
33
+ let(:versions) { [] }
34
+
35
+ it { expect(subject.size).to eq(0) }
36
+ it { expect(subject.to_s).to eq('') }
37
+ it { expect(subject.label).to eq(' sha1=[], def=(*), del=(x)') }
38
+ end
39
+
40
+ context 'when arguments are non-nil' do
41
+ let(:label) { 'my_label' }
42
+ let(:versions) do
43
+ [{ version: '1.0', is_default: false, is_disabled: false, sha1: nil },
44
+ { version: '2.0', is_default: true, is_disabled: true, sha1: '123456789' }]
45
+ end
46
+
47
+ it { expect(subject.size).to eq(29) }
48
+ it { expect(subject.to_s).to eq('1.0[???], 2.0[123456..](*)(x)') }
49
+ it { expect(subject.label).to eq('MY LABEL sha1=[], def=(*), del=(x)') }
50
+ end
51
+ end
52
+
53
+ describe KPM::Formatter do
54
+ subject { described_class.new }
55
+
56
+ context 'when running inspect' do
57
+ let(:data) do
58
+ { 'killbill-kpm' => { plugin_name: 'killbill-kpm', plugin_path: '/var/tmp/bundles/plugins/ruby/killbill-kpm', type: 'ruby', versions: [{ version: '1.3.0', is_default: true, is_disabled: false, sha1: 'b350016c539abc48e51c97605ac1f08b441843d3' }], plugin_key: 'kpm', group_id: 'org.kill-bill.billing.plugin.ruby', artifact_id: 'kpm-plugin', packaging: 'tar.gz', classifier: nil },
59
+ 'hello-world-plugin' => { plugin_name: 'hello-world-plugin', plugin_path: '/var/tmp/bundles/plugins/java/hello-world-plugin', type: 'java', versions: [{ version: '1.0.1-SNAPSHOT', is_default: true, is_disabled: false, sha1: nil }], plugin_key: 'dev:hello', group_id: nil, artifact_id: nil, packaging: nil, classifier: nil },
60
+ 'analytics-plugin' => { plugin_name: 'analytics-plugin', plugin_path: '/var/tmp/bundles/plugins/java/analytics-plugin', type: 'java', versions: [{ version: '7.0.3-SNAPSHOT', is_default: true, is_disabled: false, sha1: nil }], plugin_key: 'analytics', group_id: nil, artifact_id: nil, packaging: nil, classifier: nil } }
61
+ end
62
+ let(:labels) do
63
+ [{ label: :plugin_name },
64
+ { label: :plugin_key },
65
+ { label: :type },
66
+ { label: :group_id },
67
+ { label: :artifact_id },
68
+ { label: :packaging },
69
+ { label: :versions, formatter: KPM::Formatter::VersionFormatter.name }]
70
+ end
71
+ let!(:labels_format_argument) { subject.send(:compute_labels, data, labels) }
72
+
73
+ it {
74
+ expect(labels_format_argument).to eq(['PLUGIN NAME',
75
+ 'PLUGIN KEY',
76
+ 'TYPE',
77
+ 'GROUP ID',
78
+ 'ARTIFACT ID',
79
+ 'PACKAGING',
80
+ 'VERSIONS sha1=[], def=(*), del=(x)'])
81
+ }
82
+
83
+ it {
84
+ expect(labels).to eq([{ label: :plugin_name, size: 18 },
85
+ { label: :plugin_key, size: 10 },
86
+ { label: :type, size: 4 },
87
+ { label: :group_id, size: 33 },
88
+ { label: :artifact_id, size: 11 },
89
+ { label: :packaging, size: 9 },
90
+ { label: :versions, formatter: KPM::Formatter::VersionFormatter.name, size: 34 }])
91
+ }
92
+
93
+ it {
94
+ # labels have the size computed here already
95
+ expect(subject.send(:compute_border, labels)).to eq('_____________________________________________________________________________________________________________________________________________')
96
+ }
97
+
98
+ it {
99
+ # labels have the size computed here already
100
+ expect(subject.send(:compute_format, labels)).to eq('| %18s | %10s | %4s | %33s | %11s | %9s | %34s |')
101
+ }
102
+
103
+ it {
104
+ expect(subject.send(:format_only, data, labels)).to eq("\n_____________________________________________________________________________________________________________________________________________
105
+ | PLUGIN NAME | PLUGIN KEY | TYPE | GROUP ID | ARTIFACT ID | PACKAGING | VERSIONS sha1=[], def=(*), del=(x) |
106
+ _____________________________________________________________________________________________________________________________________________
107
+ | killbill-kpm | kpm | ruby | org.kill-bill.billing.plugin.ruby | kpm-plugin | tar.gz | 1.3.0[b35001..](*) |
108
+ | hello-world-plugin | dev:hello | java | ??? | ??? | ??? | 1.0.1-SNAPSHOT[???](*) |
109
+ | analytics-plugin | analytics | java | ??? | ??? | ??? | 7.0.3-SNAPSHOT[???](*) |
110
+ _____________________________________________________________________________________________________________________________________________\n\n")
111
+ }
112
+ end
113
+
114
+ context 'when formatting CPU information' do
115
+ let(:data) do
116
+ { 'Processor Name' => { cpu_detail: 'Processor Name', value: 'Intel Core i5' },
117
+ 'Processor Speed' => { cpu_detail: 'Processor Speed', value: '3.1 GHz' },
118
+ 'Number of Processors' => { cpu_detail: 'Number of Processors', value: '1' },
119
+ 'Total Number of Cores' => { cpu_detail: 'Total Number of Cores', value: '2' },
120
+ 'L2 Cache (per Core)' => { cpu_detail: 'L2 Cache (per Core)', value: '256 KB' },
121
+ 'L3 Cache' => { cpu_detail: 'L3 Cache', value: '4 MB' } }
122
+ end
123
+ let(:labels) do
124
+ [{ label: :cpu_detail },
125
+ { label: :value }]
126
+ end
127
+ let!(:labels_format_argument) { subject.send(:compute_labels, data, labels) }
128
+
129
+ it {
130
+ expect(labels_format_argument).to eq(['CPU DETAIL',
131
+ 'VALUE'])
132
+ }
133
+
134
+ it {
135
+ expect(labels).to eq([{ label: :cpu_detail, size: 21 },
136
+ { label: :value, size: 13 }])
137
+ }
138
+
139
+ it {
140
+ # labels have the size computed here already
141
+ expect(subject.send(:compute_border, labels)).to eq('_________________________________________')
142
+ }
143
+
144
+ it {
145
+ # labels have the size computed here already
146
+ expect(subject.send(:compute_format, labels)).to eq('| %21s | %13s |')
147
+ }
148
+
149
+ it {
150
+ expect(subject.send(:format_only, data, labels)).to eq("\n_________________________________________
151
+ | CPU DETAIL | VALUE |
152
+ _________________________________________
153
+ | Processor Name | Intel Core i5 |
154
+ | Processor Speed | 3.1 GHz |
155
+ | Number of Processors | 1 |
156
+ | Total Number of Cores | 2 |
157
+ | L2 Cache (per Core) | 256 KB |
158
+ | L3 Cache | 4 MB |
159
+ _________________________________________\n\n")
160
+ }
161
+ end
162
+ end
163
+ end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe KPM::Inspector do
4
-
5
6
  before(:each) do
6
7
  @logger = Logger.new(STDOUT)
7
8
  @logger.level = Logger::INFO
@@ -20,72 +21,64 @@ describe KPM::Inspector do
20
21
 
21
22
  @manager = KPM::PluginsManager.new(@plugins_dir, @logger)
22
23
 
23
- @sha1_file = @bundles_dir.join("sha1.yml")
24
+ @sha1_file = @bundles_dir.join('sha1.yml')
24
25
  @sha1_checker = KPM::Sha1Checker.from_file(@sha1_file)
25
-
26
26
  end
27
27
 
28
-
29
28
  it 'should parse a correctly setup env' do
30
-
31
- add_plugin('foo', 'plugin_foo', ['1.2.3', '2.0.0', '2.0.1'], 'ruby', 'com.foo', 'foo', 'tar.gz', nil, ['12345', '23456', '34567'], '2.0.1', ['1.2.3'])
29
+ add_plugin('foo', 'plugin_foo', ['1.2.3', '2.0.0', '2.0.1'], 'ruby', 'com.foo', 'foo', 'tar.gz', nil, %w[12345 23456 34567], '2.0.1', ['1.2.3'])
32
30
  add_plugin('bar', 'plugin_bar', ['1.0.0'], 'java', 'com.bar', 'bar', 'jar', nil, ['98765'], nil, [])
33
31
 
34
32
  inspector = KPM::Inspector.new
35
33
  all_plugins = inspector.inspect(@bundles_dir)
36
- all_plugins.size == 2
37
-
38
- all_plugins['plugin_bar']['plugin_key'] == 'bar'
39
- all_plugins['plugin_bar']['plugin_path'] == @java_plugins_dir.join('plugin_bar').to_s
40
- all_plugins['plugin_bar'][:versions].size == 1
41
- all_plugins['plugin_bar'][:versions][0][:version] == '1.0.0'
42
- all_plugins['plugin_bar'][:versions][0][:is_default] == true
43
- all_plugins['plugin_bar'][:versions][0][:is_disabled] == false
44
- all_plugins['plugin_bar'][:versions][0][:sha1] == '98765'
45
-
46
- all_plugins['plugin_foo']['plugin_key'] == 'foo'
47
- all_plugins['plugin_foo']['plugin_path'] == @ruby_plugins_dir.join('plugin_foo').to_s
48
- all_plugins['plugin_foo'][:versions].size == 3
49
-
50
- all_plugins['plugin_foo'][:versions][0][:version] == '1.2.3'
51
- all_plugins['plugin_foo'][:versions][0][:is_default] == false
52
- all_plugins['plugin_foo'][:versions][0][:is_disabled] == true
53
- all_plugins['plugin_foo'][:versions][0][:sha1] == '12345'
54
-
55
- all_plugins['plugin_foo'][:versions][1][:version] == '2.0.0'
56
- all_plugins['plugin_foo'][:versions][1][:is_default] == false
57
- all_plugins['plugin_foo'][:versions][1][:is_disabled] == false
58
- all_plugins['plugin_foo'][:versions][1][:sha1] == '23456'
59
-
60
- all_plugins['plugin_foo'][:versions][2][:version] == '2.0.1'
61
- all_plugins['plugin_foo'][:versions][2][:is_default] == true
62
- all_plugins['plugin_foo'][:versions][2][:is_disabled] == false
63
- all_plugins['plugin_foo'][:versions][2][:sha1] == '34567'
64
-
34
+ expect(all_plugins.size).to eq 2
35
+
36
+ expect(all_plugins['plugin_bar'][:plugin_key]).to eq 'bar'
37
+ expect(all_plugins['plugin_bar'][:plugin_path]).to eq @java_plugins_dir.join('plugin_bar').to_s
38
+ expect(all_plugins['plugin_bar'][:versions].size).to eq 1
39
+ expect(all_plugins['plugin_bar'][:versions][0][:version]).to eq '1.0.0'
40
+ expect(all_plugins['plugin_bar'][:versions][0][:is_default]).to eq false
41
+ expect(all_plugins['plugin_bar'][:versions][0][:is_disabled]).to eq false
42
+ expect(all_plugins['plugin_bar'][:versions][0][:sha1]).to eq '98765'
43
+
44
+ expect(all_plugins['plugin_foo'][:plugin_key]).to eq 'foo'
45
+ expect(all_plugins['plugin_foo'][:plugin_path]).to eq @ruby_plugins_dir.join('plugin_foo').to_s
46
+ expect(all_plugins['plugin_foo'][:versions].size).to eq 3
47
+
48
+ expect(all_plugins['plugin_foo'][:versions][0][:version]).to eq '1.2.3'
49
+ expect(all_plugins['plugin_foo'][:versions][0][:is_default]).to eq false
50
+ expect(all_plugins['plugin_foo'][:versions][0][:is_disabled]).to eq true
51
+ expect(all_plugins['plugin_foo'][:versions][0][:sha1]).to eq '12345'
52
+
53
+ expect(all_plugins['plugin_foo'][:versions][1][:version]).to eq '2.0.0'
54
+ expect(all_plugins['plugin_foo'][:versions][1][:is_default]).to eq false
55
+ expect(all_plugins['plugin_foo'][:versions][1][:is_disabled]).to eq false
56
+ expect(all_plugins['plugin_foo'][:versions][1][:sha1]).to eq '23456'
57
+
58
+ expect(all_plugins['plugin_foo'][:versions][2][:version]).to eq '2.0.1'
59
+ expect(all_plugins['plugin_foo'][:versions][2][:is_default]).to eq true
60
+ expect(all_plugins['plugin_foo'][:versions][2][:is_disabled]).to eq false
61
+ expect(all_plugins['plugin_foo'][:versions][2][:sha1]).to eq '34567'
65
62
  end
66
63
 
67
-
68
64
  private
69
65
 
70
66
  def add_plugin(plugin_key, plugin_name, versions, language, group_id, artifact_id, packaging, classifier, sha1, active_version, disabled_versions)
71
-
72
67
  plugin_dir = language == 'ruby' ? @ruby_plugins_dir.join(plugin_name) : @java_plugins_dir.join(plugin_name)
73
68
 
74
69
  versions.each_with_index do |v, idx|
75
-
76
- coordinate_map = {:group_id => group_id, :artifact_id => artifact_id, :version => v, :packaging => packaging, :classifier => classifier}
70
+ coordinate_map = { group_id: group_id, artifact_id: artifact_id, version: v, packaging: packaging, classifier: classifier }
77
71
  coordinates = KPM::Coordinates.build_coordinates(coordinate_map)
78
72
 
79
73
  @manager.add_plugin_identifier_key(plugin_key, plugin_name, language, coordinate_map)
80
74
  @sha1_checker.add_or_modify_entry!(coordinates, sha1[idx])
81
75
 
82
-
83
76
  plugin_dir_version = plugin_dir.join(v)
84
77
 
85
78
  FileUtils.mkdir_p(plugin_dir_version)
86
79
 
87
80
  # Create some entry to look real
88
- some_file = 'ruby' ? 'ROOT' : '#{plugin_name}.jar'
81
+ some_file = language == 'ruby' ? 'ROOT' : "#{plugin_name}.jar"
89
82
  FileUtils.touch(plugin_dir_version.join(some_file))
90
83
  end
91
84
 
@@ -95,5 +88,4 @@ describe KPM::Inspector do
95
88
  @manager.uninstall(plugin_dir, v)
96
89
  end
97
90
  end
98
-
99
91
  end
@@ -1,17 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe KPM::Installer do
4
-
5
6
  context 'when no config file is specified' do
6
- let(:all_kb_versions) { %w(0.15.0 0.15.1 0.15.10 0.15.11-SNAPSHOT 0.15.2 0.15.3 0.16.0 0.16.1 0.16.10 0.16.11 0.16.12-SNAPSHOT 0.16.2 0.16.3 0.17.0 0.17.1 0.17.2 0.17.2-SNAPSHOT 0.17.3-SNAPSHOT) }
7
+ let(:all_kb_versions) { %w[0.15.0 0.15.1 0.15.10 0.15.11-SNAPSHOT 0.15.2 0.15.3 0.16.0 0.16.1 0.16.10 0.16.11 0.16.12-SNAPSHOT 0.16.2 0.16.3 0.17.0 0.17.1 0.17.2 0.17.2-SNAPSHOT 0.17.3-SNAPSHOT] }
7
8
 
8
9
  it 'finds the right stable versions' do
9
10
  config = KPM::Installer.build_default_config(all_kb_versions)
10
- config['killbill'].should_not be_nil
11
- config['killbill']['version'].should == '0.16.11'
11
+ expect(config['killbill']).not_to be_nil
12
+ expect(config['killbill']['version']).to eq '0.16.11'
12
13
 
13
- config['kaui'].should_not be_nil
14
- config['kaui']['version'].should == 'LATEST'
14
+ expect(config['kaui']).not_to be_nil
15
+ expect(config['kaui']['version']).to eq 'LATEST'
15
16
  end
16
17
  end
17
18
  end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'kpm/system_helpers/system_proxy'
5
+ require 'kpm/system_helpers/memory_information'
6
+
7
+ describe KPM::SystemProxy::MemoryInformation do
8
+ subject { described_class.new }
9
+
10
+ context 'when running on Linux' do
11
+ let(:data) { "MemTotal: 10774024 kB\nMemFree: 3788232 kB\nMemAvailable: 9483696 kB\nBuffers: 269216 kB\nCached: 5448624 kB\nSwapCached: 0 kB\nActive: 3562072 kB\nInactive: 2913296 kB\nActive(anon): 827072 kB\nInactive(anon): 124844 kB\nActive(file): 2735000 kB\nInactive(file): 2788452 kB\nUnevictable: 0 kB\nMlocked: 0 kB\nSwapTotal: 3620520 kB\nSwapFree: 3620520 kB\nDirty: 16 kB\nWriteback: 0 kB\nAnonPages: 757472 kB\nMapped: 71548 kB\nShmem: 194392 kB\nSlab: 468096 kB\nSReclaimable: 425428 kB\nSUnreclaim: 42668 kB\nKernelStack: 4816 kB\nPageTables: 3420 kB\nNFS_Unstable: 0 kB\nBounce: 0 kB\nWritebackTmp: 0 kB\nCommitLimit: 9007532 kB\nCommitted_AS: 1711072 kB\nVmallocTotal: 34359738367 kB\nVmallocUsed: 0 kB\nVmallocChunk: 0 kB\nAnonHugePages: 622592 kB\nHugePages_Total: 0\nHugePages_Free: 0\nHugePages_Rsvd: 0\nHugePages_Surp: 0\nHugepagesize: 2048 kB\nDirectMap4k: 166848 kB\nDirectMap2M: 10883072 kB\n" }
12
+ let(:memory_info) { subject.send(:build_hash, data) }
13
+
14
+ it {
15
+ expect(subject.labels).to eq([{ label: :memory_detail },
16
+ { label: :value }])
17
+ }
18
+
19
+ it {
20
+ expect(memory_info).to eq({ 'MemTotal' => { memory_detail: 'MemTotal', value: '10774024 kB' },
21
+ 'MemFree' => { memory_detail: 'MemFree', value: '3788232 kB' },
22
+ 'MemAvailable' => { memory_detail: 'MemAvailable', value: '9483696 kB' },
23
+ 'Buffers' => { memory_detail: 'Buffers', value: '269216 kB' },
24
+ 'Cached' => { memory_detail: 'Cached', value: '5448624 kB' },
25
+ 'SwapCached' => { memory_detail: 'SwapCached', value: '0 kB' },
26
+ 'Active' => { memory_detail: 'Active', value: '3562072 kB' },
27
+ 'Inactive' => { memory_detail: 'Inactive', value: '2913296 kB' },
28
+ 'Active(anon)' => { memory_detail: 'Active(anon)', value: '827072 kB' },
29
+ 'Inactive(anon)' => { memory_detail: 'Inactive(anon)', value: '124844 kB' },
30
+ 'Active(file)' => { memory_detail: 'Active(file)', value: '2735000 kB' },
31
+ 'Inactive(file)' => { memory_detail: 'Inactive(file)', value: '2788452 kB' },
32
+ 'Unevictable' => { memory_detail: 'Unevictable', value: '0 kB' },
33
+ 'Mlocked' => { memory_detail: 'Mlocked', value: '0 kB' },
34
+ 'SwapTotal' => { memory_detail: 'SwapTotal', value: '3620520 kB' },
35
+ 'SwapFree' => { memory_detail: 'SwapFree', value: '3620520 kB' },
36
+ 'Dirty' => { memory_detail: 'Dirty', value: '16 kB' },
37
+ 'Writeback' => { memory_detail: 'Writeback', value: '0 kB' },
38
+ 'AnonPages' => { memory_detail: 'AnonPages', value: '757472 kB' },
39
+ 'Mapped' => { memory_detail: 'Mapped', value: '71548 kB' },
40
+ 'Shmem' => { memory_detail: 'Shmem', value: '194392 kB' },
41
+ 'Slab' => { memory_detail: 'Slab', value: '468096 kB' },
42
+ 'SReclaimable' => { memory_detail: 'SReclaimable', value: '425428 kB' },
43
+ 'SUnreclaim' => { memory_detail: 'SUnreclaim', value: '42668 kB' },
44
+ 'KernelStack' => { memory_detail: 'KernelStack', value: '4816 kB' },
45
+ 'PageTables' => { memory_detail: 'PageTables', value: '3420 kB' },
46
+ 'NFS_Unstable' => { memory_detail: 'NFS_Unstable', value: '0 kB' },
47
+ 'Bounce' => { memory_detail: 'Bounce', value: '0 kB' },
48
+ 'WritebackTmp' => { memory_detail: 'WritebackTmp', value: '0 kB' },
49
+ 'CommitLimit' => { memory_detail: 'CommitLimit', value: '9007532 kB' },
50
+ 'Committed_AS' => { memory_detail: 'Committed_AS', value: '1711072 kB' },
51
+ 'VmallocTotal' => { memory_detail: 'VmallocTotal', value: '34359738367 kB' },
52
+ 'VmallocUsed' => { memory_detail: 'VmallocUsed', value: '0 kB' },
53
+ 'VmallocChunk' => { memory_detail: 'VmallocChunk', value: '0 kB' },
54
+ 'AnonHugePages' => { memory_detail: 'AnonHugePages', value: '622592 kB' },
55
+ 'HugePages_Total' => { memory_detail: 'HugePages_Total', value: '0' },
56
+ 'HugePages_Free' => { memory_detail: 'HugePages_Free', value: '0' },
57
+ 'HugePages_Rsvd' => { memory_detail: 'HugePages_Rsvd', value: '0' },
58
+ 'HugePages_Surp' => { memory_detail: 'HugePages_Surp', value: '0' },
59
+ 'Hugepagesize' => { memory_detail: 'Hugepagesize', value: '2048 kB' },
60
+ 'DirectMap4k' => { memory_detail: 'DirectMap4k', value: '166848 kB' },
61
+ 'DirectMap2M' => { memory_detail: 'DirectMap2M', value: '10883072 kB' } })
62
+ }
63
+ end
64
+
65
+ context 'when running on MacOS' do
66
+ let(:mem_data) { "Mach Virtual Memory Statistics: (page size of 4096 bytes)\nPages free: 20436\nPages active: 279093\nPages inactive: 276175\nPages speculative: 2492\nPages throttled: 0\nPages wired down: 3328540\nPages purgeable: 47378\n\"Translation faults\": 1774872371\nPages copy-on-write: 34313850\nPages zero filled: 1023660277\nPages reactivated: 194623586\nPages purged: 70443047\nFile-backed pages: 119033\nAnonymous pages: 438727\nPages stored in compressor: 2771982\nPages occupied by compressor: 287324\nDecompressions: 252938013\nCompressions: 328708973\nPageins: 66884005\nPageouts: 1122278\nSwapins: 110783726\nSwapouts: 113589173\n" }
67
+ let(:mem_total_data) { " Memory: 16 GB\n" }
68
+ let(:memory_info) { subject.send(:build_hash_mac, mem_data, mem_total_data) }
69
+
70
+ it {
71
+ expect(subject.labels).to eq([{ label: :memory_detail },
72
+ { label: :value }])
73
+ }
74
+
75
+ it {
76
+ expect(memory_info).to eq({ 'Memory' => { memory_detail: 'Memory', value: '16 GB' },
77
+ 'Mach Virtual Memory Statistics' => { memory_detail: 'Mach Virtual Memory Statistics', value: '0MB' },
78
+ 'Pages free' => { memory_detail: 'Memory free', value: '79MB' },
79
+ 'Pages active' => { memory_detail: 'Memory active', value: '1090MB' },
80
+ 'Pages inactive' => { memory_detail: 'Memory inactive', value: '1078MB' },
81
+ 'Pages speculative' => { memory_detail: 'Memory speculative', value: '9MB' },
82
+ 'Pages throttled' => { memory_detail: 'Memory throttled', value: '0MB' },
83
+ 'Pages wired down' => { memory_detail: 'Memory wired down', value: '13002MB' },
84
+ 'Pages purgeable' => { memory_detail: 'Memory purgeable', value: '185MB' },
85
+ 'Translation faults' => { memory_detail: 'Translation faults', value: '6933095MB' },
86
+ 'Pages copy-on-write' => { memory_detail: 'Memory copy-on-write', value: '134038MB' },
87
+ 'Pages zero filled' => { memory_detail: 'Memory zero filled', value: '3998672MB' },
88
+ 'Pages reactivated' => { memory_detail: 'Memory reactivated', value: '760248MB' },
89
+ 'Pages purged' => { memory_detail: 'Memory purged', value: '275168MB' },
90
+ 'File-backed pages' => { memory_detail: 'File-backed pages', value: '464MB' },
91
+ 'Anonymous pages' => { memory_detail: 'Anonymous pages', value: '1713MB' },
92
+ 'Pages stored in compressor' => { memory_detail: 'Memory stored in compressor', value: '10828MB' },
93
+ 'Pages occupied by compressor' => { memory_detail: 'Memory occupied by compressor', value: '1122MB' },
94
+ 'Decompressions' => { memory_detail: 'Decompressions', value: '988039MB' },
95
+ 'Compressions' => { memory_detail: 'Compressions', value: '1284019MB' },
96
+ 'Pageins' => { memory_detail: 'Pageins', value: '261265MB' },
97
+ 'Pageouts' => { memory_detail: 'Pageouts', value: '4383MB' },
98
+ 'Swapins' => { memory_detail: 'Swapins', value: '432748MB' },
99
+ 'Swapouts' => { memory_detail: 'Swapouts', value: '443707MB' } })
100
+ }
101
+ end
102
+ end