kpm 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +66 -0
  3. data/Gemfile +2 -0
  4. data/README.adoc +111 -109
  5. data/Rakefile +2 -1
  6. data/bin/kpm +4 -2
  7. data/kpm.gemspec +8 -6
  8. data/lib/kpm.rb +3 -0
  9. data/lib/kpm/account.rb +267 -338
  10. data/lib/kpm/base_artifact.rb +33 -39
  11. data/lib/kpm/base_installer.rb +69 -83
  12. data/lib/kpm/blob.rb +29 -0
  13. data/lib/kpm/cli.rb +3 -1
  14. data/lib/kpm/coordinates.rb +6 -9
  15. data/lib/kpm/database.rb +90 -114
  16. data/lib/kpm/diagnostic_file.rb +126 -147
  17. data/lib/kpm/formatter.rb +74 -46
  18. data/lib/kpm/inspector.rb +22 -32
  19. data/lib/kpm/installer.rb +53 -46
  20. data/lib/kpm/kaui_artifact.rb +4 -3
  21. data/lib/kpm/killbill_plugin_artifact.rb +10 -7
  22. data/lib/kpm/killbill_server_artifact.rb +13 -12
  23. data/lib/kpm/migrations.rb +8 -7
  24. data/lib/kpm/nexus_helper/actions.rb +47 -8
  25. data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +87 -94
  26. data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
  27. data/lib/kpm/plugins_directory.rb +9 -8
  28. data/lib/kpm/plugins_directory.yml +8 -175
  29. data/lib/kpm/plugins_manager.rb +29 -24
  30. data/lib/kpm/sha1_checker.rb +31 -18
  31. data/lib/kpm/system.rb +105 -136
  32. data/lib/kpm/system_helpers/cpu_information.rb +56 -55
  33. data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
  34. data/lib/kpm/system_helpers/entropy_available.rb +37 -39
  35. data/lib/kpm/system_helpers/memory_information.rb +52 -51
  36. data/lib/kpm/system_helpers/os_information.rb +45 -47
  37. data/lib/kpm/system_helpers/system_proxy.rb +10 -10
  38. data/lib/kpm/tasks.rb +364 -437
  39. data/lib/kpm/tenant_config.rb +68 -83
  40. data/lib/kpm/tomcat_manager.rb +9 -8
  41. data/lib/kpm/trace_logger.rb +18 -16
  42. data/lib/kpm/uninstaller.rb +81 -14
  43. data/lib/kpm/utils.rb +13 -14
  44. data/lib/kpm/version.rb +3 -1
  45. data/packaging/Gemfile +2 -0
  46. data/pom.xml +1 -1
  47. data/spec/kpm/remote/base_artifact_spec.rb +13 -15
  48. data/spec/kpm/remote/base_installer_spec.rb +30 -29
  49. data/spec/kpm/remote/installer_spec.rb +73 -73
  50. data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
  51. data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +19 -24
  52. data/spec/kpm/remote/killbill_server_artifact_spec.rb +17 -16
  53. data/spec/kpm/remote/migrations_spec.rb +12 -11
  54. data/spec/kpm/remote/nexus_facade_spec.rb +30 -26
  55. data/spec/kpm/remote/tenant_config_spec.rb +27 -26
  56. data/spec/kpm/remote/tomcat_manager_spec.rb +2 -1
  57. data/spec/kpm/unit/actions_spec.rb +52 -0
  58. data/spec/kpm/unit/base_artifact_spec.rb +17 -16
  59. data/spec/kpm/unit/cpu_information_spec.rb +67 -0
  60. data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
  61. data/spec/kpm/unit/entropy_information_spec.rb +36 -0
  62. data/spec/kpm/unit/formatter_spec.rb +163 -0
  63. data/spec/kpm/unit/inspector_spec.rb +34 -42
  64. data/spec/kpm/unit/installer_spec.rb +5 -4
  65. data/spec/kpm/unit/memory_information_spec.rb +102 -0
  66. data/spec/kpm/unit/os_information_spec.rb +38 -0
  67. data/spec/kpm/unit/plugins_directory_spec.rb +34 -18
  68. data/spec/kpm/unit/plugins_manager_spec.rb +61 -65
  69. data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
  70. data/spec/kpm/unit/uninstaller_spec.rb +107 -61
  71. data/spec/kpm/unit_mysql/account_spec.rb +120 -135
  72. data/spec/spec_helper.rb +19 -17
  73. data/tasks/package.rake +18 -18
  74. metadata +17 -8
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe KPM::BaseArtifact do
4
-
5
6
  before(:all) do
6
7
  @logger = Logger.new(STDOUT)
7
8
  @logger.level = Logger::INFO
@@ -15,14 +16,14 @@ describe KPM::BaseArtifact do
15
16
 
16
17
  info[:skipped].should be_false
17
18
  info[:is_tgz].should be_false
18
- info[:repository_path].should == file_path
19
- info[:dir_name].should == dir
20
- info[:bundle_dir].should == dir
21
- info[:file_name].should == 'sha1_test.yml'
19
+ info[:repository_path].should eq file_path
20
+ info[:dir_name].should eq dir
21
+ info[:bundle_dir].should eq dir
22
+ info[:file_name].should eq 'sha1_test.yml'
22
23
 
23
24
  files_in_dir = Dir[dir + '/*']
24
- files_in_dir.size.should == 1
25
- files_in_dir[0].should == info[:file_path]
25
+ files_in_dir.size.should eq 1
26
+ files_in_dir[0].should eq info[:file_path]
26
27
  end
27
28
  end
28
29
 
@@ -75,18 +76,18 @@ describe KPM::BaseArtifact do
75
76
 
76
77
  def check_fs_info(specified_destination_path, repository_path, is_tgz, version, expected_dir_name, expected_file_name, expected_file_path)
77
78
  info = {
78
- :repository_path => repository_path,
79
- :is_tgz => is_tgz,
80
- :version => version
79
+ repository_path: repository_path,
80
+ is_tgz: is_tgz,
81
+ version: version
81
82
  }
82
83
 
83
84
  KPM::BaseArtifact.send('populate_fs_info', info, specified_destination_path)
84
85
 
85
- info[:repository_path].should == repository_path
86
- info[:is_tgz].should == is_tgz
87
- info[:version].should == version
88
- info[:dir_name].should == expected_dir_name
89
- info[:file_name].should == expected_file_name
90
- info[:file_path].should == expected_file_path
86
+ info[:repository_path].should eq repository_path
87
+ info[:is_tgz].should eq is_tgz
88
+ info[:version].should eq version
89
+ info[:dir_name].should eq expected_dir_name
90
+ info[:file_name].should eq expected_file_name
91
+ info[:file_path].should eq expected_file_path
91
92
  end
92
93
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'kpm/system_helpers/system_proxy'
5
+ require 'kpm/system_helpers/cpu_information'
6
+
7
+ describe KPM::SystemProxy::CpuInformation do
8
+ subject { described_class.new }
9
+ let(:cpu_info) { subject.send(:build_hash, data) }
10
+
11
+ context 'when running on Linux' do
12
+ let(:data) { "processor: 0\nvendor_id: GenuineIntel\ncpu family: 6\nmodel: 78\nmodel name: Intel(R) Core(TM) i5-6287U CPU @ 3.10GHz\nstepping: 3\ncpu MHz: 3096.000\ncache size: 4096 KB\nphysical id: 0\nsiblings: 2\ncore id: 0\ncpu cores: 2\napicid: 0\ninitial apicid: 0\nfpu: yes\nfpu_exception: yes\ncpuid level: 22\nwp: yes\nflags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase avx2 invpcid rdseed clflushopt\nbugs:\nbogomips: 6192.00\nclflush size: 64\ncache_alignment: 64\naddress sizes: 39 bits physical, 48 bits virtual\npower management:\n\nprocessor: 1\nvendor_id: GenuineIntel\ncpu family: 6\nmodel: 78\nmodel name: Intel(R) Core(TM) i5-6287U CPU @ 3.10GHz\nstepping: 3\ncpu MHz: 3096.000\ncache size: 4096 KB\nphysical id: 0\nsiblings: 2\ncore id: 1\ncpu cores: 2\napicid: 1\ninitial apicid: 1\nfpu: yes\nfpu_exception: yes\ncpuid level: 22\nwp: yes\nflags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase avx2 invpcid rdseed clflushopt\nbugs:\nbogomips: 6192.00\nclflush size: 64\ncache_alignment: 64\naddress sizes: 39 bits physical, 48 bits virtual\npower management:\n\n" }
13
+
14
+ it {
15
+ expect(subject.labels).to eq([{ label: :cpu_detail },
16
+ { label: :value }])
17
+ }
18
+
19
+ it {
20
+ expect(cpu_info).to eq({ 'processor' => { cpu_detail: 'processor', value: '1' },
21
+ 'vendor_id' => { cpu_detail: 'vendor_id', value: 'GenuineIntel' },
22
+ 'cpu family' => { cpu_detail: 'cpu family', value: '6' },
23
+ 'model' => { cpu_detail: 'model', value: '78' },
24
+ 'model name' =>
25
+ { cpu_detail: 'model name',
26
+ value: 'Intel(R) Core(TM) i5-6287U CPU @ 3.10GHz' },
27
+ 'stepping' => { cpu_detail: 'stepping', value: '3' },
28
+ 'cpu MHz' => { cpu_detail: 'cpu MHz', value: '3096.000' },
29
+ 'cache size' => { cpu_detail: 'cache size', value: '4096 KB' },
30
+ 'physical id' => { cpu_detail: 'physical id', value: '0' },
31
+ 'siblings' => { cpu_detail: 'siblings', value: '2' },
32
+ 'core id' => { cpu_detail: 'core id', value: '1' },
33
+ 'cpu cores' => { cpu_detail: 'cpu cores', value: '2' },
34
+ 'apicid' => { cpu_detail: 'apicid', value: '1' },
35
+ 'initial apicid' => { cpu_detail: 'initial apicid', value: '1' },
36
+ 'fpu' => { cpu_detail: 'fpu', value: 'yes' },
37
+ 'fpu_exception' => { cpu_detail: 'fpu_exception', value: 'yes' },
38
+ 'cpuid level' => { cpu_detail: 'cpuid level', value: '22' },
39
+ 'wp' => { cpu_detail: 'wp', value: 'yes' },
40
+ 'bugs' => { cpu_detail: 'bugs', value: '' },
41
+ 'bogomips' => { cpu_detail: 'bogomips', value: '6192.00' },
42
+ 'clflush size' => { cpu_detail: 'clflush size', value: '64' },
43
+ 'cache_alignment' => { cpu_detail: 'cache_alignment', value: '64' },
44
+ 'address sizes' =>
45
+ { cpu_detail: 'address sizes', value: '39 bits physical, 48 bits virtual' },
46
+ 'power management' => { cpu_detail: 'power management', value: '' } })
47
+ }
48
+ end
49
+
50
+ context 'when running on MacOS' do
51
+ let(:data) { " Processor Name: Intel Core i5\n Processor Speed: 3.1 GHz\n Number of Processors: 1\n Total Number of Cores: 2\n L2 Cache (per Core): 256 KB\n L3 Cache: 4 MB\n" }
52
+
53
+ it {
54
+ expect(subject.labels).to eq([{ label: :cpu_detail },
55
+ { label: :value }])
56
+ }
57
+
58
+ it {
59
+ expect(cpu_info).to eq({ 'Processor Name' => { cpu_detail: 'Processor Name', value: 'Intel Core i5' },
60
+ 'Processor Speed' => { cpu_detail: 'Processor Speed', value: '3.1 GHz' },
61
+ 'Number of Processors' => { cpu_detail: 'Number of Processors', value: '1' },
62
+ 'Total Number of Cores' => { cpu_detail: 'Total Number of Cores', value: '2' },
63
+ 'L2 Cache (per Core)' => { cpu_detail: 'L2 Cache (per Core)', value: '256 KB' },
64
+ 'L3 Cache' => { cpu_detail: 'L3 Cache', value: '4 MB' } })
65
+ }
66
+ end
67
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'kpm/system_helpers/system_proxy'
5
+ require 'kpm/system_helpers/disk_space_information'
6
+
7
+ describe KPM::SystemProxy::DiskSpaceInformation do
8
+ subject { described_class.new }
9
+ let(:data_keys) { [] }
10
+ let!(:disk_space_info) { subject.send(:build_hash, data, cols_count, true, data_keys) }
11
+
12
+ context 'when running on Linux' do
13
+ let(:cols_count) { 5 }
14
+ let(:data) { "Filesystem 1K-blocks Used Available Use% Mounted on\nnone 58419028 24656532 30723884 45% /\ntmpfs 65536 0 65536 0% /dev\ntmpfs 5387012 0 5387012 0% /sys/fs/cgroup\n/dev/sda1 58419028 24656532 30723884 45% /etc/hosts\nshm 65536 0 65536 0% /dev/shm\ntmpfs 5387012 0 5387012 0% /sys/firmware\n" }
15
+
16
+ it {
17
+ expect(data_keys).to eq(['Filesystem', '1K-blocks', 'Used', 'Available', 'Use%', 'Mounted on'])
18
+ }
19
+
20
+ it {
21
+ expect(disk_space_info).to eq({ 'DiskInfo_2' => { :Filesystem => 'none', :"1K-blocks" => '58419028', :Used => '24656532', :Available => '30723884', :"Use%" => '45%', :Mounted_on => '/' },
22
+ 'DiskInfo_3' => { :Filesystem => 'tmpfs', :"1K-blocks" => '65536', :Used => '0', :Available => '65536', :"Use%" => '0%', :Mounted_on => '/dev' },
23
+ 'DiskInfo_4' => { :Filesystem => 'tmpfs', :"1K-blocks" => '5387012', :Used => '0', :Available => '5387012', :"Use%" => '0%', :Mounted_on => '/sys/fs/cgroup' },
24
+ 'DiskInfo_5' => { :Filesystem => '/dev/sda1', :"1K-blocks" => '58419028', :Used => '24656532', :Available => '30723884', :"Use%" => '45%', :Mounted_on => '/etc/hosts' },
25
+ 'DiskInfo_6' => { :Filesystem => 'shm', :"1K-blocks" => '65536', :Used => '0', :Available => '65536', :"Use%" => '0%', :Mounted_on => '/dev/shm' },
26
+ 'DiskInfo_7' => { :Filesystem => 'tmpfs', :"1K-blocks" => '5387012', :Used => '0', :Available => '5387012', :"Use%" => '0%', :Mounted_on => '/sys/firmware' } })
27
+ }
28
+ end
29
+
30
+ context 'when running on MacOS' do
31
+ let(:cols_count) { 8 }
32
+ let(:data) { "Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on\n/dev/disk1s1 976490576 778131600 173031648 82% 2431747 9223372036852344060 0% /\ndevfs 690 690 0 100% 1194 0 100% /dev\n/dev/disk1s4 976490576 23925200 173031648 13% 5 9223372036854775802 0% /private/var/vm\nmap -hosts 0 0 0 100% 0 0 100% /net\nmap auto_home 0 0 0 100% 0 0 100% /home\n/dev/disk1s3 976490576 996584 173031648 1% 34 9223372036854775773 0% /Volumes/Recovery\n" }
33
+
34
+ it {
35
+ expect(data_keys).to eq(['Filesystem', '512-blocks', 'Used', 'Available', 'Capacity', 'iused', 'ifree', '%iused', 'Mounted on'])
36
+ }
37
+
38
+ it {
39
+ expect(disk_space_info).to eq({ 'DiskInfo_2' => { :Filesystem => '/dev/disk1s1', :"512-blocks" => '976490576', :Used => '778131600', :Available => '173031648', :Capacity => '82%', :iused => '2431747', :ifree => '9223372036852344060', :"%iused" => '0%', :Mounted_on => '/' },
40
+ 'DiskInfo_3' => { :Filesystem => 'devfs', :"512-blocks" => '690', :Used => '690', :Available => '0', :Capacity => '100%', :iused => '1194', :ifree => '0', :"%iused" => '100%', :Mounted_on => '/dev' },
41
+ 'DiskInfo_4' => { :Filesystem => '/dev/disk1s4', :"512-blocks" => '976490576', :Used => '23925200', :Available => '173031648', :Capacity => '13%', :iused => '5', :ifree => '9223372036854775802', :"%iused" => '0%', :Mounted_on => '/private/var/vm' },
42
+ 'DiskInfo_5' => { :Filesystem => 'map', :"512-blocks" => '-hosts', :Used => '0', :Available => '0', :Capacity => '0', :iused => '100%', :ifree => '0', :"%iused" => '0', :Mounted_on => '100% /net ' },
43
+ 'DiskInfo_6' => { :Filesystem => 'map', :"512-blocks" => 'auto_home', :Used => '0', :Available => '0', :Capacity => '0', :iused => '100%', :ifree => '0', :"%iused" => '0', :Mounted_on => '100% /home ' },
44
+ 'DiskInfo_7' => { :Filesystem => '/dev/disk1s3', :"512-blocks" => '976490576', :Used => '996584', :Available => '173031648', :Capacity => '1%', :iused => '34', :ifree => '9223372036854775773', :"%iused" => '0%', :Mounted_on => '/Volumes/Recovery' } })
45
+ }
46
+ end
47
+ end
@@ -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
+ all_plugins.size.should eq 2
35
+
36
+ all_plugins['plugin_bar'][:plugin_key].should eq 'bar'
37
+ all_plugins['plugin_bar'][:plugin_path].should eq @java_plugins_dir.join('plugin_bar').to_s
38
+ all_plugins['plugin_bar'][:versions].size.should eq 1
39
+ all_plugins['plugin_bar'][:versions][0][:version].should eq '1.0.0'
40
+ all_plugins['plugin_bar'][:versions][0][:is_default].should eq false
41
+ all_plugins['plugin_bar'][:versions][0][:is_disabled].should eq false
42
+ all_plugins['plugin_bar'][:versions][0][:sha1].should eq '98765'
43
+
44
+ all_plugins['plugin_foo'][:plugin_key].should eq 'foo'
45
+ all_plugins['plugin_foo'][:plugin_path].should eq @ruby_plugins_dir.join('plugin_foo').to_s
46
+ all_plugins['plugin_foo'][:versions].size.should eq 3
47
+
48
+ all_plugins['plugin_foo'][:versions][0][:version].should eq '1.2.3'
49
+ all_plugins['plugin_foo'][:versions][0][:is_default].should eq false
50
+ all_plugins['plugin_foo'][:versions][0][:is_disabled].should eq true
51
+ all_plugins['plugin_foo'][:versions][0][:sha1].should eq '12345'
52
+
53
+ all_plugins['plugin_foo'][:versions][1][:version].should eq '2.0.0'
54
+ all_plugins['plugin_foo'][:versions][1][:is_default].should eq false
55
+ all_plugins['plugin_foo'][:versions][1][:is_disabled].should eq false
56
+ all_plugins['plugin_foo'][:versions][1][:sha1].should eq '23456'
57
+
58
+ all_plugins['plugin_foo'][:versions][2][:version].should eq '2.0.1'
59
+ all_plugins['plugin_foo'][:versions][2][:is_default].should eq true
60
+ all_plugins['plugin_foo'][:versions][2][:is_disabled].should eq false
61
+ all_plugins['plugin_foo'][:versions][2][:sha1].should 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