kpm 0.7.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'kpm/system_helpers/system_proxy'
5
+ require 'kpm/system_helpers/os_information'
6
+
7
+ describe KPM::SystemProxy::OsInformation do
8
+ subject { described_class.new }
9
+ let(:os_data) { subject.send(:build_hash, data) }
10
+
11
+ context 'when running on Linux' do
12
+ let(:data) { "Description:Ubuntu 16.04.1 LTS \n\n" }
13
+
14
+ it {
15
+ expect(subject.labels).to eq([{ label: :os_detail },
16
+ { label: :value }])
17
+ }
18
+
19
+ it {
20
+ expect(os_data).to eq({ 'Description' => { :os_detail => 'Description', :value => 'Ubuntu 16.04.1 LTS' } })
21
+ }
22
+ end
23
+
24
+ context 'when running on MacOS' do
25
+ let(:data) { "ProductName:\tMac OS X\nProductVersion:\t10.14.6\nBuildVersion:\t18G87\n" }
26
+
27
+ it {
28
+ expect(subject.labels).to eq([{ label: :os_detail },
29
+ { label: :value }])
30
+ }
31
+
32
+ it {
33
+ expect(os_data).to eq({ 'ProductName' => { :os_detail => 'ProductName', :value => 'Mac OS X' },
34
+ 'ProductVersion' => { :os_detail => 'ProductVersion', :value => '10.14.6' },
35
+ 'BuildVersion' => { :os_detail => 'BuildVersion', :value => '18G87' } })
36
+ }
37
+ end
38
+ end
@@ -1,36 +1,52 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe KPM::PluginsDirectory do
4
-
5
6
  it 'should parse the plugins directory' do
6
7
  directory = KPM::PluginsDirectory.all(false)
7
- directory.size.should > 0
8
+ expect(directory.size).to be > 0
8
9
  end
9
10
 
10
-
11
11
  it 'should lookup plugins' do
12
- group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, '0.14')
13
- group_id.should == 'org.kill-bill.billing.plugin.java'
14
- artifact_id.should == 'analytics-plugin'
15
- packaging.should == 'jar'
16
- classifier.should be_nil
17
- version.should == '1.0.3'
18
- type.should == :java
12
+ group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, '0.20.11')
13
+ expect(group_id).to eq 'org.kill-bill.billing.plugin.java'
14
+ expect(artifact_id).to eq 'analytics-plugin'
15
+ expect(packaging).to eq 'jar'
16
+ expect(classifier).to be_nil
17
+ expect(version).to eq '6.0.1'
18
+ expect(type).to eq :java
19
+
20
+ group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, '0.20.11-SNAPSHOT')
21
+ expect(group_id).to eq 'org.kill-bill.billing.plugin.java'
22
+ expect(artifact_id).to eq 'analytics-plugin'
23
+ expect(packaging).to eq 'jar'
24
+ expect(classifier).to be_nil
25
+ expect(version).to eq '6.0.1'
26
+ expect(type).to eq :java
27
+
28
+ group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, '0.20')
29
+ expect(group_id).to eq 'org.kill-bill.billing.plugin.java'
30
+ expect(artifact_id).to eq 'analytics-plugin'
31
+ expect(packaging).to eq 'jar'
32
+ expect(classifier).to be_nil
33
+ expect(version).to eq '6.0.1'
34
+ expect(type).to eq :java
19
35
 
20
36
  group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, 'LATEST')
21
- group_id.should == 'org.kill-bill.billing.plugin.java'
22
- artifact_id.should == 'analytics-plugin'
23
- packaging.should == 'jar'
24
- classifier.should be_nil
25
- version.should == 'LATEST'
26
- type.should == :java
37
+ expect(group_id).to eq 'org.kill-bill.billing.plugin.java'
38
+ expect(artifact_id).to eq 'analytics-plugin'
39
+ expect(packaging).to eq 'jar'
40
+ expect(classifier).to be_nil
41
+ expect(version).to eq 'LATEST'
42
+ expect(type).to eq :java
27
43
 
28
44
  group_id, artifact_id, packaging, classifier, version, type = KPM::PluginsDirectory.lookup('analytics', false, '0.42')
29
- group_id.should == 'org.kill-bill.billing.plugin.java'
30
- artifact_id.should == 'analytics-plugin'
31
- packaging.should == 'jar'
32
- classifier.should be_nil
33
- version.should == 'LATEST'
34
- type.should == :java
45
+ expect(group_id).to eq 'org.kill-bill.billing.plugin.java'
46
+ expect(artifact_id).to eq 'analytics-plugin'
47
+ expect(packaging).to eq 'jar'
48
+ expect(classifier).to be_nil
49
+ expect(version).to eq 'LATEST'
50
+ expect(type).to eq :java
35
51
  end
36
52
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe KPM::PluginsManager do
4
-
5
6
  before(:each) do
6
7
  logger = Logger.new(STDOUT)
7
8
  logger.level = Logger::INFO
@@ -14,7 +15,7 @@ describe KPM::PluginsManager do
14
15
  FileUtils.mkdir_p(@plugin_dir.join('1.0.0'))
15
16
  FileUtils.mkdir_p(@plugin_dir.join('2.0.0'))
16
17
 
17
- File.exists?(@plugin_dir.join('SET_DEFAULT')).should be_false
18
+ expect(File.exist?(@plugin_dir.join('SET_DEFAULT'))).to be_falsey
18
19
  end
19
20
 
20
21
  after(:each) do
@@ -24,133 +25,128 @@ describe KPM::PluginsManager do
24
25
  it 'creates a plugin identifier entry with no coordinate' do
25
26
  # Verifies file gets created if does not exist
26
27
  identifiers = @manager.add_plugin_identifier_key('foo', 'foo_name', 'type', nil)
27
- identifiers.size.should == 1
28
- identifiers['foo']['plugin_name'].should == 'foo_name'
28
+ expect(identifiers.size).to eq 1
29
+ expect(identifiers['foo']['plugin_name']).to eq 'foo_name'
29
30
  end
30
31
 
31
32
  it 'creates a plugin identifier entry with coordinates' do
32
33
  # Verifies file gets created if does not exist
33
- coordinate_map = {:group_id => 'group', :artifact_id => 'artifact', :packaging => 'packaging', :version => 'version'}
34
+ coordinate_map = { group_id: 'group', artifact_id: 'artifact', packaging: 'packaging', version: 'version' }
34
35
  identifiers = @manager.add_plugin_identifier_key('bar', 'bar_name', 'type', coordinate_map)
35
- identifiers.size.should == 1
36
- identifiers['bar']['plugin_name'].should == 'bar_name'
37
- identifiers['bar']['group_id'].should == 'group'
38
- identifiers['bar']['artifact_id'].should == 'artifact'
39
- identifiers['bar']['packaging'].should == 'packaging'
40
- identifiers['bar']['classifier'].should == nil
41
- identifiers['bar']['version'].should == 'version'
36
+ expect(identifiers.size).to eq 1
37
+ expect(identifiers['bar']['plugin_name']).to eq 'bar_name'
38
+ expect(identifiers['bar']['group_id']).to eq 'group'
39
+ expect(identifiers['bar']['artifact_id']).to eq 'artifact'
40
+ expect(identifiers['bar']['packaging']).to eq 'packaging'
41
+ expect(identifiers['bar']['classifier']).to be_nil
42
+ expect(identifiers['bar']['version']).to eq 'version'
42
43
  end
43
44
 
44
-
45
45
  it 'creates plugin identifier with multiple entries' do
46
46
  # Verifies file gets created if does not exist
47
47
  identifiers = @manager.add_plugin_identifier_key('foo', 'foo_name', 'type', nil)
48
- identifiers.size.should == 1
49
- identifiers['foo']['plugin_name'].should == 'foo_name'
48
+ expect(identifiers.size).to eq 1
49
+ expect(identifiers['foo']['plugin_name']).to eq 'foo_name'
50
50
 
51
51
  # Verify file was created from previous entry (prev value was read)
52
52
  identifiers = @manager.add_plugin_identifier_key('bar', 'bar_name', 'type', nil)
53
- identifiers.size.should == 2
54
- identifiers['foo']['plugin_name'].should == 'foo_name'
55
- identifiers['bar']['plugin_name'].should == 'bar_name'
56
-
53
+ expect(identifiers.size).to eq 2
54
+ expect(identifiers['foo']['plugin_name']).to eq 'foo_name'
55
+ expect(identifiers['bar']['plugin_name']).to eq 'bar_name'
57
56
 
58
57
  # Verify file was created from previous entry (prev value was read)
59
58
  identifiers = @manager.add_plugin_identifier_key('zoe', 'zoe_name', 'type', nil)
60
- identifiers.size.should == 3
61
- identifiers['bar']['plugin_name'].should == 'bar_name'
62
- identifiers['foo']['plugin_name'].should == 'foo_name'
63
- identifiers['zoe']['plugin_name'].should == 'zoe_name'
59
+ expect(identifiers.size).to eq 3
60
+ expect(identifiers['bar']['plugin_name']).to eq 'bar_name'
61
+ expect(identifiers['foo']['plugin_name']).to eq 'foo_name'
62
+ expect(identifiers['zoe']['plugin_name']).to eq 'zoe_name'
64
63
  end
65
64
 
66
65
  it 'creates plugin identifiers with duplicate entries' do
67
66
  # Verifies file gets created if does not exist
68
67
  identifiers = @manager.add_plugin_identifier_key('kewl', 'kewl_name', 'type', nil)
69
- identifiers.size.should == 1
70
- identifiers['kewl']['plugin_name'].should == 'kewl_name'
68
+ expect(identifiers.size).to eq 1
69
+ expect(identifiers['kewl']['plugin_name']).to eq 'kewl_name'
71
70
 
72
71
  # Add with a different plugin_name
73
72
  identifiers = @manager.add_plugin_identifier_key('kewl', 'kewl_name2', 'type', nil)
74
- identifiers.size.should == 1
75
- identifiers['kewl']['plugin_name'].should == 'kewl_name'
73
+ expect(identifiers.size).to eq 1
74
+ expect(identifiers['kewl']['plugin_name']).to eq 'kewl_name'
76
75
  end
77
76
 
78
-
79
77
  it 'creates plugin identifiers and remove entry' do
80
78
  # Verifies file gets created if does not exist
81
79
  identifiers = @manager.add_plugin_identifier_key('lol', 'lol_name', 'type', nil)
82
- identifiers.size.should == 1
83
- identifiers['lol']['plugin_name'].should == 'lol_name'
80
+ expect(identifiers.size).to eq 1
81
+ expect(identifiers['lol']['plugin_name']).to eq 'lol_name'
84
82
 
85
83
  # Remove wrong entry, nothing happens
86
84
  identifiers = @manager.remove_plugin_identifier_key('lol2')
87
- identifiers.size.should == 1
88
- identifiers['lol']['plugin_name'].should == 'lol_name'
85
+ expect(identifiers.size).to eq 1
86
+ expect(identifiers['lol']['plugin_name']).to eq 'lol_name'
89
87
 
90
88
  # Remove correct entry
91
89
  identifiers = @manager.remove_plugin_identifier_key('lol')
92
- identifiers.size.should == 0
90
+ expect(identifiers.size).to eq 0
93
91
 
94
92
  # Add same entry again
95
93
  identifiers = @manager.add_plugin_identifier_key('lol', 'lol_name', 'type', nil)
96
- identifiers.size.should == 1
97
- identifiers['lol']['plugin_name'].should == 'lol_name'
94
+ expect(identifiers.size).to eq 1
95
+ expect(identifiers['lol']['plugin_name']).to eq 'lol_name'
98
96
  end
99
97
 
100
98
  it 'creates plugin identifiers and validate entry' do
101
99
  # Verifies file gets created if does not exist
102
- coordinate_map = {:group_id => 'group', :artifact_id => 'artifact', :packaging => 'packaging', :version => 'version'}
100
+ coordinate_map = { group_id: 'group', artifact_id: 'artifact', packaging: 'packaging', version: 'version' }
103
101
 
104
- identifiers = @manager.add_plugin_identifier_key('yoyo', 'yoyo_name', 'type', coordinate_map)
105
- identifiers.size.should == 1
106
- identifiers['yoyo']['plugin_name'].should == 'yoyo_name'
102
+ identifiers = @manager.add_plugin_identifier_key('yoyo', 'yoyo_name', 'type', coordinate_map)
103
+ expect(identifiers.size).to eq 1
104
+ expect(identifiers['yoyo']['plugin_name']).to eq 'yoyo_name'
107
105
 
108
- @manager.validate_plugin_identifier_key('yoyo', coordinate_map).should == true
106
+ expect(@manager.validate_plugin_identifier_key('yoyo', coordinate_map)).to eq true
109
107
 
110
108
  # Negative validation
111
- invalid_coordinate_map = {:group_id => 'group1', :artifact_id => 'artifact', :packaging => 'packaging', :version => 'version'}
109
+ invalid_coordinate_map = { group_id: 'group1', artifact_id: 'artifact', packaging: 'packaging', version: 'version' }
112
110
 
113
- @manager.validate_plugin_identifier_key('yoyo', invalid_coordinate_map).should == false
111
+ expect(@manager.validate_plugin_identifier_key('yoyo', invalid_coordinate_map)).to eq false
114
112
  end
115
113
 
116
-
117
114
  it 'creates a plugin identifier entry with a new version' do
118
115
  # Verifies file gets created if does not exist
119
116
 
120
- coordinate_map1 = {:group_id => 'group', :artifact_id => 'artifact', :packaging => 'packaging', :version => 'version1'}
117
+ coordinate_map1 = { group_id: 'group', artifact_id: 'artifact', packaging: 'packaging', version: 'version1' }
121
118
 
122
119
  identifiers = @manager.add_plugin_identifier_key('bar', 'bar_name', 'type', coordinate_map1)
123
- identifiers.size.should == 1
124
- identifiers['bar']['plugin_name'].should == 'bar_name'
125
- identifiers['bar']['version'].should == 'version1'
120
+ expect(identifiers.size).to eq 1
121
+ expect(identifiers['bar']['plugin_name']).to eq 'bar_name'
122
+ expect(identifiers['bar']['version']).to eq 'version1'
126
123
 
127
- coordinate_map2 = {:group_id => 'group', :artifact_id => 'artifact', :packaging => 'packaging', :version => 'version2'}
124
+ coordinate_map2 = { group_id: 'group', artifact_id: 'artifact', packaging: 'packaging', version: 'version2' }
128
125
 
129
126
  identifiers = @manager.add_plugin_identifier_key('bar', 'bar_name', 'type', coordinate_map2)
130
- identifiers.size.should == 1
131
- identifiers['bar']['plugin_name'].should == 'bar_name'
132
- identifiers['bar']['version'].should == 'version2'
133
-
127
+ expect(identifiers.size).to eq 1
128
+ expect(identifiers['bar']['plugin_name']).to eq 'bar_name'
129
+ expect(identifiers['bar']['version']).to eq 'version2'
134
130
  end
135
131
 
136
132
  it 'sets a path as active' do
137
133
  @manager.set_active(@plugin_dir.join('1.0.0'))
138
- File.exists?(@plugin_dir.join('SET_DEFAULT')).should be_true
139
- File.readlink(@plugin_dir.join('SET_DEFAULT')).should == @plugin_dir.join('1.0.0').to_s
134
+ expect(File.exist?(@plugin_dir.join('SET_DEFAULT'))).to be_truthy
135
+ expect(File.readlink(@plugin_dir.join('SET_DEFAULT'))).to eq @plugin_dir.join('1.0.0').to_s
140
136
 
141
137
  @manager.set_active(@plugin_dir.join('2.0.0'))
142
- File.exists?(@plugin_dir.join('SET_DEFAULT')).should be_true
143
- File.readlink(@plugin_dir.join('SET_DEFAULT')).should == @plugin_dir.join('2.0.0').to_s
138
+ expect(File.exist?(@plugin_dir.join('SET_DEFAULT'))).to be_truthy
139
+ expect(File.readlink(@plugin_dir.join('SET_DEFAULT'))).to eq @plugin_dir.join('2.0.0').to_s
144
140
  end
145
141
 
146
142
  it 'sets a plugin version as active' do
147
143
  @manager.set_active('killbill-stripe', '2.0.0')
148
- File.exists?(@plugin_dir.join('SET_DEFAULT')).should be_true
149
- File.readlink(@plugin_dir.join('SET_DEFAULT')).should == @plugin_dir.join('2.0.0').to_s
144
+ expect(File.exist?(@plugin_dir.join('SET_DEFAULT'))).to be_truthy
145
+ expect(File.readlink(@plugin_dir.join('SET_DEFAULT'))).to eq @plugin_dir.join('2.0.0').to_s
150
146
 
151
147
  @manager.set_active('killbill-stripe', '1.0.0')
152
- File.exists?(@plugin_dir.join('SET_DEFAULT')).should be_true
153
- File.readlink(@plugin_dir.join('SET_DEFAULT')).should == @plugin_dir.join('1.0.0').to_s
148
+ expect(File.exist?(@plugin_dir.join('SET_DEFAULT'))).to be_truthy
149
+ expect(File.readlink(@plugin_dir.join('SET_DEFAULT'))).to eq @plugin_dir.join('1.0.0').to_s
154
150
  end
155
151
 
156
152
  it 'uninstalls a plugin via a path' do
@@ -194,19 +190,19 @@ describe KPM::PluginsManager do
194
190
  end
195
191
 
196
192
  it 'guesses the plugin name' do
197
- @manager.guess_plugin_name('tripe').should be_nil
193
+ expect(@manager.guess_plugin_name('tripe')).to be_nil
198
194
  # Short name
199
- @manager.guess_plugin_name('stripe').should == 'killbill-stripe'
195
+ expect(@manager.guess_plugin_name('stripe')).to eq 'killbill-stripe'
200
196
  # Artifact id
201
- @manager.guess_plugin_name('stripe-plugin').should == 'killbill-stripe'
197
+ expect(@manager.guess_plugin_name('stripe-plugin')).to eq 'killbill-stripe'
202
198
  # Plugin name (top directory in the .tar.gz)
203
- @manager.guess_plugin_name('killbill-stripe').should == 'killbill-stripe'
199
+ expect(@manager.guess_plugin_name('killbill-stripe')).to eq 'killbill-stripe'
204
200
  end
205
201
 
206
202
  private
207
203
 
208
204
  def check_state(version, has_restart, has_disabled)
209
- File.exists?(@plugin_dir.join(version).join('tmp').join('restart.txt')).should == has_restart
210
- File.exists?(@plugin_dir.join(version).join('tmp').join('disabled.txt')).should == has_disabled
205
+ expect(File.exist?(@plugin_dir.join(version).join('tmp').join('restart.txt'))).to eq has_restart
206
+ expect(File.exist?(@plugin_dir.join(version).join('tmp').join('disabled.txt'))).to eq has_disabled
211
207
  end
212
208
  end
@@ -1,103 +1,150 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe KPM::Sha1Checker do
6
+ let(:tmp_dir) { Dir.mktmpdir('sha1_checker_spec') }
7
+ let(:sha1_file) { File.join(tmp_dir, 'sha1.yml') }
8
+ let(:sha1_checker) { KPM::Sha1Checker.from_file(sha1_file) }
9
+ let(:sha1_content) do
10
+ {
11
+ 'sha1' => { 'org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0' => 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9',
12
+ 'org.kill-bill.billing.plugin.ruby:killbill-plugin-nomatch:tar.gz:1.0.0' => 'ace068c3fd5f95646ce0d09852f43ff67f06f0b8',
13
+ 'org.kill-bill.billing.plugin.ruby:killbill-plugin-other:tar.gz:1.0.0' => 'bbb068c3fd5f95646ce0d09852f43ff67f06fccc' },
14
+ 'nexus' => { 'org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0' => { :sha1 => 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9',
15
+ :version => '1.0.0',
16
+ :repository_path => '/org/kill-bill/billing/plugin/ruby/killbill-plugin-match/1.0.0/killbill-plugin-match-1.0.0.tar.gz',
17
+ :is_tgz => true },
18
+ 'org.kill-bill.billing.plugin.ruby:killbill-plugin-nomatch:tar.gz:1.0.0' => { :sha1 => 'ace068c3fd5f95646ce0d09852f43ff67f06f0b8',
19
+ :version => '1.0.0',
20
+ :repository_path => '/org/kill-bill/billing/plugin/ruby/killbill-plugin-nomatch/1.0.0/killbill-plugin-nomatch-1.0.0.tar.gz',
21
+ :is_tgz => true },
22
+ 'org.kill-bill.billing.plugin.ruby:killbill-plugin-other:tar.gz:1.0.0' => { :sha1 => 'bbb068c3fd5f95646ce0d09852f43ff67f06fccc',
23
+ :version => '1.0.0',
24
+ :repository_path => '/org/kill-bill/billing/plugin/ruby/killbill-plugin-other/1.0.0/killbill-plugin-other-1.0.0.tar.gz',
25
+ :is_tgz => true } },
26
+ 'killbill' => { '0.20.10' => { 'killbill' => '0.20.10', 'killbill-oss-parent' => '0.142.7', 'killbill-api' => '0.52.0', 'killbill-plugin-api' => '0.25.0', 'killbill-commons' => '0.22.3', 'killbill-platform' => '0.38.3' },
27
+ '0.20.12' => { 'killbill' => '0.20.12', 'killbill-oss-parent' => '0.142.7', 'killbill-api' => '0.52.0', 'killbill-plugin-api' => '0.25.0', 'killbill-commons' => '0.22.3', 'killbill-platform' => '0.38.3' },
28
+ '0.18.5' => { 'killbill' => '0.18.5', 'killbill-oss-parent' => '0.140.18', 'killbill-api' => '0.50.1', 'killbill-plugin-api' => '0.23.1', 'killbill-commons' => '0.20.5', 'killbill-platform' => '0.36.5' } }
29
+ }
30
+ end
4
31
 
5
- before(:all) do
6
- @logger = Logger.new(STDOUT)
7
- @logger.level = Logger::INFO
8
-
9
- tmp_destination_dir = Dir.tmpdir()
10
- init_config = File.join(File.dirname(__FILE__), 'sha1_test.yml')
11
- FileUtils.copy(init_config, tmp_destination_dir)
12
- @tmp_config = File.join(tmp_destination_dir, 'sha1_test.yml')
13
- @sha1_checker = KPM::Sha1Checker.from_file(@tmp_config)
32
+ before do
33
+ File.open(sha1_file.to_s, 'w') { |l| l.puts(sha1_content.to_yaml) }
14
34
  end
15
35
 
16
36
  it 'should create intermediate directories' do
17
37
  Dir.mktmpdir do |dir|
18
- config = File.join(dir, 'foo', 'bar', 'baz', 'sha1_test.yml')
38
+ config = File.join(dir, 'foo', 'bar', 'baz', 'sha1.yml')
39
+ expect(File.exist?(config)).to be_falsey
19
40
  KPM::Sha1Checker.from_file(config)
41
+ expect(File.exist?(config)).to be_truthy
20
42
  end
21
43
  end
22
44
 
23
- it 'should find matching sha1' do
24
- existing = @sha1_checker.sha1('killbill-plugin-match-1.0.0.tar.gz')
25
- existing.should_not be_nil
26
- existing.should == 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9'
45
+ it 'translates LATEST when caching nexus info' do
46
+ sha1_checker.cache_artifact_info('org.kill-bill.billing.plugin.java:analytics-plugin:jar:LATEST', { :sha1 => '050594dd73a54d229ca3efcf69785345b8cd1681',
47
+ :version => '7.0.4',
48
+ :repository_path => '/org/kill-bill/billing/plugin/java/analytics-plugin/7.0.4/analytics-plugin-7.0.4.jar',
49
+ :is_tgz => false })
50
+ expect(sha1_checker.artifact_info('org.kill-bill.billing.plugin.java:analytics-plugin:jar:LATEST')).to be_nil
51
+ expect(sha1_checker.artifact_info('org.kill-bill.billing.plugin.java:analytics-plugin:jar:7.0.4')[:sha1]).to eq('050594dd73a54d229ca3efcf69785345b8cd1681')
27
52
  end
28
53
 
29
- it 'should NOT find sha1' do
30
- existing = @sha1_checker.sha1('killbill-plugin-nomatch-1.0.0.tar.gz')
31
- existing.should_not be_nil
32
- existing.should_not == 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9'
54
+ it 'never caches nexus info without version info' do
55
+ sha1_checker.cache_artifact_info('org.kill-bill.billing.plugin.java:analytics-plugin:jar:LATEST', { :sha1 => '050594dd73a54d229ca3efcf69785345b8cd1681',
56
+ :repository_path => '/org/kill-bill/billing/plugin/java/analytics-plugin/7.0.4/analytics-plugin-7.0.4.jar',
57
+ :is_tgz => false })
58
+ expect(sha1_checker.artifact_info('org.kill-bill.billing.plugin.java:analytics-plugin:jar:LATEST')).to be_nil
59
+ expect(sha1_checker.artifact_info('org.kill-bill.billing.plugin.java:analytics-plugin:jar:7.0.4')).to be_nil
33
60
  end
34
61
 
35
- it 'should NOT find matching sha1' do
36
- existing = @sha1_checker.sha1('killbill-plugin-foo-1.0.0.tar.gz')
37
- existing.should be_nil
62
+ it 'finds matching sha1' do
63
+ existing_sha1 = sha1_checker.sha1('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0')
64
+ expect(existing_sha1).to eq('fce068c3fd5f95646ce0d09852f43ff67f06f0b9')
65
+
66
+ existing_nexus = sha1_checker.artifact_info('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0')
67
+ expect(existing_nexus[:sha1]).to eq(existing_sha1)
68
+ end
69
+
70
+ it 'does not find matching sha1' do
71
+ existing_sha1 = sha1_checker.sha1('killbill-plugin-foo:tar.gz:1.0.0')
72
+ expect(existing_sha1).to be_nil
73
+
74
+ existing_nexus = sha1_checker.artifact_info('killbill-plugin-foo:tar.gz:1.0.0')
75
+ expect(existing_nexus).to be_nil
38
76
  end
39
77
 
40
- it 'should add an entry and find them all' do
41
- @sha1_checker.add_or_modify_entry!('killbill-plugin-new-1.1.0.0.tar.gz', 'abc068c3fd5f95646ce0d09852f43ff67f06f111')
78
+ it 'adds an entry and find them all' do
79
+ sha1_checker.add_or_modify_entry!('killbill-plugin-new:tar.gz:1.1.0.0', 'abc068c3fd5f95646ce0d09852f43ff67f06f111')
42
80
 
43
- existing = @sha1_checker.sha1('killbill-plugin-match-1.0.0.tar.gz')
44
- existing.should_not be_nil
45
- existing.should == 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9'
81
+ existing = sha1_checker.sha1('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0')
82
+ expect(existing).to eq('fce068c3fd5f95646ce0d09852f43ff67f06f0b9')
46
83
 
47
- existing = @sha1_checker.sha1('killbill-plugin-new-1.1.0.0.tar.gz')
48
- existing.should_not be_nil
49
- existing.should == 'abc068c3fd5f95646ce0d09852f43ff67f06f111'
84
+ # Nexus cache untouched
85
+ existing_nexus = sha1_checker.artifact_info('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0')
86
+ expect(existing_nexus[:sha1]).to eq(existing)
50
87
 
88
+ existing = sha1_checker.sha1('killbill-plugin-new:tar.gz:1.1.0.0')
89
+ expect(existing).to eq('abc068c3fd5f95646ce0d09852f43ff67f06f111')
51
90
 
52
- existing = @sha1_checker.sha1('killbill-plugin-other-1.0.0.tar.gz')
53
- existing.should_not be_nil
54
- existing.should == 'bbb068c3fd5f95646ce0d09852f43ff67f06fccc'
91
+ # Nexus cache not updated
92
+ expect(sha1_checker.artifact_info('killbill-plugin-new:tar.gz:1.1.0.0')).to be_nil
93
+
94
+ existing = sha1_checker.sha1('org.kill-bill.billing.plugin.ruby:killbill-plugin-other:tar.gz:1.0.0')
95
+ expect(existing).to eq('bbb068c3fd5f95646ce0d09852f43ff67f06fccc')
96
+
97
+ # Nexus cache untouched
98
+ existing_nexus = sha1_checker.artifact_info('org.kill-bill.billing.plugin.ruby:killbill-plugin-other:tar.gz:1.0.0')
99
+ expect(existing_nexus[:sha1]).to eq(existing)
55
100
  end
56
101
 
57
- it 'should add allow to modify an entry and find them all' do
58
- existing = @sha1_checker.sha1('killbill-plugin-match-1.0.0.tar.gz')
59
- existing.should_not be_nil
60
- existing.should == 'fce068c3fd5f95646ce0d09852f43ff67f06f0b9'
102
+ it 'modifies an entry and find them all' do
103
+ existing = sha1_checker.sha1('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0')
104
+ expect(existing).to eq('fce068c3fd5f95646ce0d09852f43ff67f06f0b9')
105
+
106
+ existing_nexus = sha1_checker.artifact_info('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0')
107
+ expect(existing_nexus[:sha1]).to eq(existing)
108
+
109
+ sha1_checker.add_or_modify_entry!('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0', 'dde068c3fd5f95646ce0d09852f43ff67f06f0aa')
61
110
 
62
- @sha1_checker.add_or_modify_entry!('killbill-plugin-match-1.0.0.tar.gz', 'dde068c3fd5f95646ce0d09852f43ff67f06f0aa')
111
+ existing = sha1_checker.sha1('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0')
112
+ expect(existing).to eq('dde068c3fd5f95646ce0d09852f43ff67f06f0aa')
63
113
 
64
- existing = @sha1_checker.sha1('killbill-plugin-match-1.0.0.tar.gz')
65
- existing.should_not be_nil
66
- existing.should == 'dde068c3fd5f95646ce0d09852f43ff67f06f0aa'
114
+ # Nexus cache untouched (modified in another code path)
115
+ existing_nexus = sha1_checker.artifact_info('org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0')
116
+ expect(existing_nexus[:sha1]).to eq('fce068c3fd5f95646ce0d09852f43ff67f06f0b9')
67
117
 
68
- existing = @sha1_checker.sha1('killbill-plugin-other-1.0.0.tar.gz')
69
- existing.should_not be_nil
70
- existing.should == 'bbb068c3fd5f95646ce0d09852f43ff67f06fccc'
118
+ existing = sha1_checker.sha1('org.kill-bill.billing.plugin.ruby:killbill-plugin-other:tar.gz:1.0.0')
119
+ expect(existing).to eq('bbb068c3fd5f95646ce0d09852f43ff67f06fccc')
120
+
121
+ existing_nexus = sha1_checker.artifact_info('org.kill-bill.billing.plugin.ruby:killbill-plugin-other:tar.gz:1.0.0')
122
+ expect(existing_nexus[:sha1]).to eq(existing)
71
123
  end
72
124
 
73
125
  context 'when removing an entry' do
74
- let(:identifier) { 'killbill-plugin-match-1.0.0.tar.gz' }
126
+ let(:identifier) { 'org.kill-bill.billing.plugin.ruby:killbill-plugin-match:tar.gz:1.0.0' }
75
127
  before do
76
- @sha1_checker.remove_entry!(identifier)
128
+ sha1_checker.remove_entry!(identifier)
77
129
  end
78
130
 
79
131
  it 'does not find the entry' do
80
- @sha1_checker.sha1(identifier).should be_nil
132
+ expect(sha1_checker.sha1(identifier)).to be_nil
133
+ expect(sha1_checker.artifact_info(identifier)).to be_nil
81
134
  end
82
135
 
83
- let(:reloaded_checker) { KPM::Sha1Checker.from_file(@tmp_config) }
84
136
  it 'does not find entry in file system' do
85
- reloaded_checker.sha1(identifier).should be_nil
137
+ expect(KPM::Sha1Checker.from_file(sha1_file).sha1(identifier)).to be_nil
86
138
  end
87
139
  end
88
140
 
89
- it 'should work with empty config' do
90
- tmp_destination_dir = Dir.tmpdir()
91
- empty_config = File.join(tmp_destination_dir, 'sha1_test.yml')
92
- if File.exists?(empty_config)
93
- # Just to be sure
94
- File.delete(empty_config)
141
+ it 'works with empty config' do
142
+ Dir.mktmpdir do |dir|
143
+ empty_config = File.join(dir, 'sha1.yml')
144
+ sha1_checker = KPM::Sha1Checker.from_file(empty_config)
145
+ sha1_checker.add_or_modify_entry!('killbill-plugin-new:tar.gz:1.1.0.0', 'abc068c3fd5f95646ce0d09852f43ff67f06f111')
146
+ existing = sha1_checker.sha1('killbill-plugin-new:tar.gz:1.1.0.0')
147
+ expect(existing).to eq('abc068c3fd5f95646ce0d09852f43ff67f06f111')
95
148
  end
96
- @sha1_checker = KPM::Sha1Checker.from_file(empty_config)
97
-
98
- @sha1_checker.add_or_modify_entry!('killbill-plugin-new-1.1.0.0.tar.gz', 'abc068c3fd5f95646ce0d09852f43ff67f06f111')
99
- existing = @sha1_checker.sha1('killbill-plugin-new-1.1.0.0.tar.gz')
100
- existing.should_not be_nil
101
- existing.should == 'abc068c3fd5f95646ce0d09852f43ff67f06f111'
102
149
  end
103
150
  end