kpm 0.7.1 → 0.9.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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +138 -0
- data/Gemfile +2 -0
- data/README.adoc +126 -109
- data/Rakefile +2 -1
- data/bin/kpm +4 -2
- data/kpm.gemspec +10 -8
- data/lib/kpm.rb +3 -0
- data/lib/kpm/account.rb +269 -337
- data/lib/kpm/base_artifact.rb +40 -36
- data/lib/kpm/base_installer.rb +71 -84
- data/lib/kpm/blob.rb +29 -0
- data/lib/kpm/cli.rb +3 -1
- data/lib/kpm/coordinates.rb +10 -12
- data/lib/kpm/database.rb +93 -103
- data/lib/kpm/diagnostic_file.rb +126 -146
- data/lib/kpm/formatter.rb +76 -48
- data/lib/kpm/inspector.rb +24 -34
- data/lib/kpm/installer.rb +53 -46
- data/lib/kpm/kaui_artifact.rb +4 -3
- data/lib/kpm/killbill_plugin_artifact.rb +10 -7
- data/lib/kpm/killbill_server_artifact.rb +24 -10
- data/lib/kpm/migrations.rb +26 -11
- data/lib/kpm/nexus_helper/actions.rb +45 -9
- data/lib/kpm/nexus_helper/github_api_calls.rb +70 -0
- data/lib/kpm/nexus_helper/nexus_api_calls_v2.rb +130 -108
- data/lib/kpm/nexus_helper/nexus_facade.rb +5 -3
- data/lib/kpm/plugins_directory.rb +14 -9
- data/lib/kpm/plugins_directory.yml +16 -175
- data/lib/kpm/plugins_manager.rb +29 -24
- data/lib/kpm/sha1_checker.rb +56 -15
- data/lib/kpm/system.rb +104 -135
- data/lib/kpm/system_helpers/cpu_information.rb +56 -55
- data/lib/kpm/system_helpers/disk_space_information.rb +60 -63
- data/lib/kpm/system_helpers/entropy_available.rb +37 -39
- data/lib/kpm/system_helpers/memory_information.rb +52 -51
- data/lib/kpm/system_helpers/os_information.rb +45 -47
- data/lib/kpm/system_helpers/system_proxy.rb +10 -10
- data/lib/kpm/tasks.rb +370 -443
- data/lib/kpm/tenant_config.rb +68 -83
- data/lib/kpm/tomcat_manager.rb +10 -8
- data/lib/kpm/trace_logger.rb +18 -16
- data/lib/kpm/uninstaller.rb +81 -14
- data/lib/kpm/utils.rb +13 -14
- data/lib/kpm/version.rb +3 -1
- data/packaging/Gemfile +2 -0
- data/pom.xml +1 -1
- data/spec/kpm/remote/base_artifact_spec.rb +33 -17
- data/spec/kpm/remote/base_installer_spec.rb +35 -34
- data/spec/kpm/remote/github_api_calls_spec.rb +40 -0
- data/spec/kpm/remote/installer_spec.rb +80 -78
- data/spec/kpm/remote/kaui_artifact_spec.rb +7 -6
- data/spec/kpm/remote/killbill_plugin_artifact_spec.rb +25 -30
- data/spec/kpm/remote/killbill_server_artifact_spec.rb +30 -13
- data/spec/kpm/remote/migrations_spec.rb +12 -11
- data/spec/kpm/remote/nexus_facade_spec.rb +32 -28
- data/spec/kpm/remote/tenant_config_spec.rb +30 -29
- data/spec/kpm/remote/tomcat_manager_spec.rb +4 -3
- data/spec/kpm/unit/actions_spec.rb +52 -0
- data/spec/kpm/unit/base_artifact_spec.rb +19 -18
- data/spec/kpm/unit/cpu_information_spec.rb +67 -0
- data/spec/kpm/unit/disk_space_information_spec.rb +47 -0
- data/spec/kpm/unit/entropy_information_spec.rb +36 -0
- data/spec/kpm/unit/formatter_spec.rb +163 -0
- data/spec/kpm/unit/inspector_spec.rb +34 -42
- data/spec/kpm/unit/installer_spec.rb +7 -6
- data/spec/kpm/unit/memory_information_spec.rb +102 -0
- data/spec/kpm/unit/os_information_spec.rb +38 -0
- data/spec/kpm/unit/plugins_directory_spec.rb +38 -22
- data/spec/kpm/unit/plugins_manager_spec.rb +62 -66
- data/spec/kpm/unit/sha1_checker_spec.rb +107 -60
- data/spec/kpm/unit/uninstaller_spec.rb +118 -72
- data/spec/kpm/unit_mysql/account_spec.rb +144 -143
- data/spec/spec_helper.rb +20 -18
- data/tasks/package.rake +18 -18
- metadata +26 -22
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe KPM::NexusFacade::Actions do
|
6
|
+
subject { described_class.new({}, nil, logger) }
|
7
|
+
let(:logger) { Logger.new(STDOUT) }
|
8
|
+
let(:nexus_mock) { double(KPM::NexusFacade::NexusApiCallsV2) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow(KPM::NexusFacade::NexusApiCallsV2).to receive(:new).and_return(nexus_mock)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when Nexus throws a non-retryable exception' do
|
15
|
+
it 'never retries' do
|
16
|
+
calls = 0
|
17
|
+
expect do
|
18
|
+
subject.send(:retry_exceptions, 'foo') do
|
19
|
+
calls += 1
|
20
|
+
raise StandardError, '404'
|
21
|
+
end
|
22
|
+
end.to raise_error(StandardError)
|
23
|
+
expect(calls).to eq(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when Nexus throws a retryable exception' do
|
28
|
+
it 'retries until giving up' do
|
29
|
+
calls = 0
|
30
|
+
expect do
|
31
|
+
subject.send(:retry_exceptions, 'foo') do
|
32
|
+
calls += 1
|
33
|
+
raise KPM::NexusFacade::UnexpectedStatusCodeException, 503
|
34
|
+
end
|
35
|
+
end.to raise_error(StandardError)
|
36
|
+
expect(calls).to eq(3)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when networking is flaky' do
|
41
|
+
it 'retries until call succeeds' do
|
42
|
+
calls = 0
|
43
|
+
expect(subject.send(:retry_exceptions, 'foo') do
|
44
|
+
calls += 1
|
45
|
+
raise OpenSSL::SSL::SSLErrorWaitReadable if calls < 2
|
46
|
+
|
47
|
+
true
|
48
|
+
end).to be_truthy
|
49
|
+
expect(calls).to eq(2)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -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
|
@@ -13,16 +14,16 @@ describe KPM::BaseArtifact do
|
|
13
14
|
Dir.mktmpdir do |dir|
|
14
15
|
info = KPM::BaseArtifact.pull_from_fs(@logger, file_path, dir)
|
15
16
|
|
16
|
-
info[:skipped].
|
17
|
-
info[:is_tgz].
|
18
|
-
info[:repository_path].
|
19
|
-
info[:dir_name].
|
20
|
-
info[:bundle_dir].
|
21
|
-
info[:file_name].
|
17
|
+
expect(info[:skipped]).to be_falsey
|
18
|
+
expect(info[:is_tgz]).to be_falsey
|
19
|
+
expect(info[:repository_path]).to eq file_path
|
20
|
+
expect(info[:dir_name]).to eq dir
|
21
|
+
expect(info[:bundle_dir]).to eq dir
|
22
|
+
expect(info[:file_name]).to eq 'sha1_test.yml'
|
22
23
|
|
23
24
|
files_in_dir = Dir[dir + '/*']
|
24
|
-
files_in_dir.size.
|
25
|
-
files_in_dir[0].
|
25
|
+
expect(files_in_dir.size).to eq 1
|
26
|
+
expect(files_in_dir[0]).to 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
|
-
|
79
|
-
|
80
|
-
|
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].
|
86
|
-
info[:is_tgz].
|
87
|
-
info[:version].
|
88
|
-
info[:dir_name].
|
89
|
-
info[:file_name].
|
90
|
-
info[:file_path].
|
86
|
+
expect(info[:repository_path]).to eq repository_path
|
87
|
+
expect(info[:is_tgz]).to eq is_tgz
|
88
|
+
expect(info[:version]).to eq version
|
89
|
+
expect(info[:dir_name]).to eq expected_dir_name
|
90
|
+
expect(info[:file_name]).to eq expected_file_name
|
91
|
+
expect(info[:file_path]).to 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(
|
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
|
37
|
-
|
38
|
-
all_plugins['plugin_bar'][
|
39
|
-
all_plugins['plugin_bar'][
|
40
|
-
all_plugins['plugin_bar'][:versions].size
|
41
|
-
all_plugins['plugin_bar'][:versions][0][:version]
|
42
|
-
all_plugins['plugin_bar'][:versions][0][:is_default]
|
43
|
-
all_plugins['plugin_bar'][:versions][0][:is_disabled]
|
44
|
-
all_plugins['plugin_bar'][:versions][0][:sha1]
|
45
|
-
|
46
|
-
all_plugins['plugin_foo'][
|
47
|
-
all_plugins['plugin_foo'][
|
48
|
-
all_plugins['plugin_foo'][:versions].size
|
49
|
-
|
50
|
-
all_plugins['plugin_foo'][:versions][0][:version]
|
51
|
-
all_plugins['plugin_foo'][:versions][0][:is_default]
|
52
|
-
all_plugins['plugin_foo'][:versions][0][:is_disabled]
|
53
|
-
all_plugins['plugin_foo'][:versions][0][:sha1]
|
54
|
-
|
55
|
-
all_plugins['plugin_foo'][:versions][1][:version]
|
56
|
-
all_plugins['plugin_foo'][:versions][1][:is_default]
|
57
|
-
all_plugins['plugin_foo'][:versions][1][:is_disabled]
|
58
|
-
all_plugins['plugin_foo'][:versions][1][:sha1]
|
59
|
-
|
60
|
-
all_plugins['plugin_foo'][:versions][2][:version]
|
61
|
-
all_plugins['plugin_foo'][:versions][2][:is_default]
|
62
|
-
all_plugins['plugin_foo'][:versions][2][:is_disabled]
|
63
|
-
all_plugins['plugin_foo'][:versions][2][:sha1]
|
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' :
|
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
|