kpm 0.7.0 → 0.8.2

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 (74) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +73 -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 +268 -337
  10. data/lib/kpm/base_artifact.rb +40 -36
  11. data/lib/kpm/base_installer.rb +71 -84
  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 +92 -103
  16. data/lib/kpm/diagnostic_file.rb +126 -146
  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 +24 -10
  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 +14 -9
  28. data/lib/kpm/plugins_directory.yml +16 -175
  29. data/lib/kpm/plugins_manager.rb +29 -24
  30. data/lib/kpm/sha1_checker.rb +56 -15
  31. data/lib/kpm/system.rb +104 -135
  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 +370 -443
  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 +26 -12
  48. data/spec/kpm/remote/base_installer_spec.rb +30 -29
  49. data/spec/kpm/remote/installer_spec.rb +74 -72
  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 +30 -13
  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 +137 -136
  72. data/spec/spec_helper.rb +19 -17
  73. data/tasks/package.rake +18 -18
  74. metadata +19 -34
@@ -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_false
19
40
  KPM::Sha1Checker.from_file(config)
41
+ expect(File.exist?(config)).to be_true
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
@@ -1,88 +1,101 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe KPM::Uninstaller do
4
-
6
+ let(:destination) { Dir.mktmpdir('uninstaller_spec') }
5
7
  let(:uninstaller) { KPM::Uninstaller.new(destination) }
6
- let(:destination) { 'somedir' }
7
8
 
8
9
  let(:plugins_manager_mock) { double(KPM::PluginsManager) }
9
10
  let(:sha1_checker_mock) { double(KPM::Sha1Checker) }
11
+
12
+ let(:plugin_info) do
13
+ {
14
+ plugin_name: plugin_name,
15
+ plugin_key: plugin_key,
16
+ plugin_path: plugin_path,
17
+ versions: [{ version: version1, :is_default => false, :is_disabled => false, :sha1 => nil }, { version: version2, :is_default => true, :is_disabled => false, :sha1 => nil }],
18
+ type: 'java',
19
+ group_id: 'group',
20
+ artifact_id: 'artifact',
21
+ packaging: 'jar',
22
+ classifier: nil
23
+ }
24
+ end
25
+ let(:plugin_name) { 'plugin-name' }
26
+ let(:plugin_key) { 'plugin-key' }
27
+ let(:plugin_path) { "#{destination}/plugins/java/#{plugin_name}" }
28
+ let(:version1) { '1.0' }
29
+ let(:version2) { '2.0' }
30
+
10
31
  before do
11
- KPM::Inspector.stub_chain(:new, :inspect).and_return(installed_plugins)
12
32
  KPM::PluginsManager.stub(:new).and_return(plugins_manager_mock)
13
33
  KPM::Sha1Checker.stub(:from_file).and_return(sha1_checker_mock)
14
- end
15
-
16
- context 'when plugin is not installed' do
17
- let(:installed_plugins) { {} }
18
34
 
19
- it 'raises a plugin not found error' do
20
- expect {
21
- uninstaller.uninstall_plugin('adyen')
22
- }.to raise_error(StandardError, "No plugin with key/name 'adyen' found installed. Try running 'kpm inspect' for more info")
35
+ # Calls by the Inspector
36
+ plugins_manager_mock.stub(:get_identifier_key_and_entry) do
37
+ [plugin_key, { 'group_id' => plugin_info[:group_id],
38
+ 'artifact_id' => plugin_info[:artifact_id],
39
+ 'packaging' => plugin_info[:packaging] }]
23
40
  end
41
+ sha1_checker_mock.stub(:all_sha1) { {} }
24
42
  end
25
43
 
26
- context 'when plugin is installed' do
27
- let(:installed_plugins) do
28
- {
29
- plugin_name => {
30
- plugin_key: plugin_key,
31
- plugin_path: plugin_path,
32
- versions: [{version: version}],
33
- group_id: 'group',
34
- artifact_id: 'artifact',
35
- packaging: 'jar'
36
- }
37
- }
38
- end
39
-
40
- let(:plugin_name) { 'plugin-name' }
41
- let(:plugin_key) { 'plugin-key' }
42
- let(:plugin_path) { 'plugin-path' }
43
- let(:version) { '1.0' }
44
-
45
- it 'uninstalls a plugin by name' do
46
- FileUtils.should_receive(:rmtree).with(plugin_path)
47
- plugins_manager_mock.should_receive(:remove_plugin_identifier_key).with(plugin_key)
48
- sha1_checker_mock.should_receive(:remove_entry!).with("group:artifact:jar:#{version}")
44
+ context 'utility methods' do
45
+ it 'raises an error when directory to delete is invalid' do
46
+ expect do
47
+ uninstaller.send(:validate_dir_for_rmrf, '/home/john')
48
+ end.to raise_error(ArgumentError, 'Path /home/john is not a valid directory')
49
+ end
50
+ it 'raises an error when directory to delete is not safe' do
51
+ expect do
52
+ uninstaller.send(:validate_dir_for_rmrf, '/tmp')
53
+ end.to raise_error(ArgumentError, "Path /tmp is not a subdirectory of #{destination}")
54
+ end
55
+ end
49
56
 
50
- uninstaller.uninstall_plugin(plugin_name).should be_true
57
+ context 'when no plugin is installed' do
58
+ it 'raises an error when uninstalling a plugin' do
59
+ expect do
60
+ uninstaller.uninstall_plugin(plugin_name)
61
+ end.to raise_error(StandardError, "No plugin with key/name '#{plugin_name}' found installed. Try running 'kpm inspect' for more info")
51
62
  end
52
63
 
53
- it 'uninstalls a plugin by key' do
54
- FileUtils.should_receive(:rmtree).with(plugin_path)
55
- plugins_manager_mock.should_receive(:remove_plugin_identifier_key).with(plugin_key)
56
- sha1_checker_mock.should_receive(:remove_entry!).with("group:artifact:jar:#{version}")
64
+ it 'raises an internal error when uninstalling a plugin' do
65
+ expect do
66
+ uninstaller.send(:remove_plugin_versions, plugin_info, true, [version1, version2])
67
+ end.to raise_error(ArgumentError, "Path #{plugin_info[:plugin_path]}/#{version1} is not a valid directory")
68
+ end
57
69
 
58
- uninstaller.uninstall_plugin(plugin_key).should be_true
70
+ it 'raises an error when uninstalling a plugin version' do
71
+ expect do
72
+ uninstaller.send(:remove_plugin_version, plugin_info, '3.0')
73
+ end.to raise_error(ArgumentError, "Path #{plugin_info[:plugin_path]}/3.0 is not a valid directory")
59
74
  end
75
+
76
+ it { expect(uninstaller.send(:categorize_plugins)).to eq({ to_be_deleted: [], to_keep: [] }) }
60
77
  end
61
78
 
62
79
  context 'when plugin is installed' do
63
- let(:installed_plugins) do
64
- {
65
- plugin_name => {
66
- plugin_key: plugin_key,
67
- plugin_path: plugin_path,
68
- versions: [{version: version1},{version: version2}],
69
- group_id: 'group',
70
- artifact_id: 'artifact',
71
- packaging: 'jar'
72
- }
73
- }
74
- end
75
-
76
- let(:plugin_name) { 'plugin-name' }
77
- let(:plugin_key) { 'plugin-key' }
78
- let(:plugin_path) { 'plugin-path' }
79
- let(:version1) { '1.0' }
80
- let(:version2) { '2.0' }
80
+ before do
81
+ FileUtils.mkdir_p(plugin_version1_path)
82
+ FileUtils.mkdir_p(plugin_version2_path)
83
+ FileUtils.ln_s(plugin_version2_path, Pathname.new(plugin_path).join('SET_DEFAULT'))
84
+ end
85
+ let(:plugin_version1_path) { File.join(plugin_path, version1) }
86
+ let(:plugin_version2_path) { File.join(plugin_path, version2) }
87
+
88
+ it 'looks up a plugin by name' do
89
+ expect(uninstaller.send(:find_plugin, plugin_name)).to eq(plugin_info)
90
+ end
91
+
92
+ it 'looks up a plugin by key' do
93
+ expect(uninstaller.send(:find_plugin, plugin_key)).to eq(plugin_info)
94
+ end
81
95
 
82
96
  it 'uninstalls if user confirms action' do
83
97
  KPM.ui.should_receive(:ask).and_return('y')
84
98
 
85
- FileUtils.should_receive(:rmtree).with(plugin_path)
86
99
  plugins_manager_mock.should_receive(:remove_plugin_identifier_key).with(plugin_key)
87
100
  sha1_checker_mock.should_receive(:remove_entry!).with("group:artifact:jar:#{version1}")
88
101
  sha1_checker_mock.should_receive(:remove_entry!).with("group:artifact:jar:#{version2}")
@@ -96,13 +109,46 @@ describe KPM::Uninstaller do
96
109
  uninstaller.uninstall_plugin(plugin_name).should be_false
97
110
  end
98
111
 
99
- it 'uninstalls without confirmation if the force option is given' do
100
- FileUtils.should_receive(:rmtree).with(plugin_path)
112
+ it 'uninstalls all plugins without confirmation if the force option is given' do
101
113
  plugins_manager_mock.should_receive(:remove_plugin_identifier_key).with(plugin_key)
102
114
  sha1_checker_mock.should_receive(:remove_entry!).with("group:artifact:jar:#{version1}")
103
115
  sha1_checker_mock.should_receive(:remove_entry!).with("group:artifact:jar:#{version2}")
104
116
 
105
117
  uninstaller.uninstall_plugin(plugin_name, true).should be_true
106
118
  end
119
+
120
+ it 'uninstalls one version without confirmation if the force option is given' do
121
+ sha1_checker_mock.should_receive(:remove_entry!).with("group:artifact:jar:#{version1}")
122
+
123
+ uninstaller.uninstall_plugin(plugin_name, true, version1).should be_true
124
+ end
125
+
126
+ it 'raises an error when uninstalling a version that does not exist' do
127
+ expect do
128
+ uninstaller.uninstall_plugin(plugin_name, true, '3.0')
129
+ end.to raise_error(ArgumentError)
130
+ end
131
+
132
+ it 'categorizes plugins depending on default flag' do
133
+ expect(uninstaller.send(:categorize_plugins)).to eq({ to_be_deleted: [[plugin_info, version1]], to_keep: [[plugin_info, version2]] })
134
+ end
135
+
136
+ it 'does not cleanup if dry-run is set' do
137
+ expect(uninstaller.uninstall_non_default_plugins(true)).to be_false
138
+ end
139
+
140
+ it 'does cleanup if dry-run isn\'t set' do
141
+ sha1_checker_mock.should_receive(:remove_entry!).with("group:artifact:jar:#{version1}")
142
+
143
+ plugin_info_copy = Marshal.load(Marshal.dump(plugin_info))
144
+ expect(KPM::Inspector.new.inspect(destination)).to eq({ plugin_name => plugin_info_copy })
145
+
146
+ expect(uninstaller.uninstall_non_default_plugins(false)).to be_true
147
+ plugin_info_copy[:versions].delete_at(0)
148
+ expect(KPM::Inspector.new.inspect(destination)).to eq({ plugin_name => plugin_info_copy })
149
+
150
+ # Second time is a no-op
151
+ expect(uninstaller.uninstall_non_default_plugins).to be_false
152
+ end
107
153
  end
108
154
  end
@@ -1,35 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe KPM::Account do
4
-
5
6
  shared_context 'account' do
6
7
  include_context 'connection_setup'
7
8
 
8
- let(:account_class) { described_class.new(nil,[killbill_api_key,killbill_api_secrets],
9
- [killbill_user, killbill_password],url,
10
- db_name, [db_username, db_password],db_host,db_port,nil,logger)}
11
- let(:dummy_account_id) {SecureRandom.uuid}
12
- let(:account_id_invalid) {SecureRandom.uuid}
13
- let(:dummy_data) {
9
+ let(:account_class) do
10
+ described_class.new(nil, [killbill_api_key, killbill_api_secret],
11
+ [killbill_user, killbill_password], url,
12
+ db_name, [db_username, db_password], db_host, db_port, nil, logger)
13
+ end
14
+ let(:dummy_account_id) { SecureRandom.uuid }
15
+ let(:account_id_invalid) { SecureRandom.uuid }
16
+ let(:account_id) { creating_account_with_client }
17
+ let(:dummy_data) do
14
18
  "-- accounts record_id|id|external_key|email|name|first_name_length|currency|billing_cycle_day_local|parent_account_id|is_payment_delegated_to_parent|payment_method_id|time_zone|locale|address1|address2|company_name|city|state_or_province|country|postal_code|phone|notes|migrated|is_notified_for_invoices|created_date|created_by|updated_date|updated_by|tenant_record_id\n"\
15
- "5|#{dummy_account_id}|#{dummy_account_id}|willharnet@example.com|Will Harnet||USD|0||||UTC||||||||||||false|2017-04-03T15:50:14.000+0000|demo|2017-04-05T15:01:39.000+0000|Killbill::Stripe::PaymentPlugin|2\n"\
19
+ "5|#{dummy_account_id}|#{dummy_account_id}|willharnet@example.com|Will Harnet||USD|0||||UTC||||Company\\N{VERTICAL LINE}\\N{LINE FEED}Name||||||||false|2017-04-03T15:50:14.000+0000|demo|2017-04-05T15:01:39.000+0000|Killbill::Stripe::PaymentPlugin|2\n"\
16
20
  "-- account_history record_id|id|target_record_id|external_key|email|name|first_name_length|currency|billing_cycle_day_local|parent_account_id|payment_method_id|is_payment_delegated_to_parent|time_zone|locale|address1|address2|company_name|city|state_or_province|country|postal_code|phone|notes|migrated|is_notified_for_invoices|change_type|created_by|created_date|updated_by|updated_date|tenant_record_id\n"\
17
- "3|#{SecureRandom.uuid}|5|#{dummy_account_id}|willharnet@example.com|Will Harnet||USD|0||||UTC||||||||||||false|INSERT|demo|2017-04-03T15:50:14.000+0000|demo|2017-04-03T15:50:14.000+0000|2\n"
18
- }
19
- let(:cols_names) {dummy_data.split("\n")[0].split(" ")[2]}
20
- let(:cols_data) {dummy_data.split("\n")[1]}
21
- let(:table_name) {dummy_data.split("\n")[0].split(" ")[1]}
22
- let(:obfuscating_marker) {:email}
23
- let(:mysql_cli) {"mysql --user=#{db_username} --password=#{db_password} --host=#{db_host} --port=#{db_port} "}
24
- let(:test_ddl) {Dir["#{Dir.pwd}/**/account_test_ddl.sql"][0]}
25
-
21
+ "3|#{SecureRandom.uuid}|5|#{dummy_account_id}|willharnet@example.com|Will Harnet||USD|0||||UTC||||Company\\N{VERTICAL LINE}\\N{LINE FEED}Name||||||||false|INSERT|demo|2017-04-03T15:50:14.000+0000|demo|2017-04-03T15:50:14.000+0000|2\n"
22
+ end
23
+ let(:cols_names) { dummy_data.split("\n")[0].split(' ')[2] }
24
+ let(:cols_data) { dummy_data.split("\n")[1] }
25
+ let(:table_name) { dummy_data.split("\n")[0].split(' ')[1] }
26
+ let(:obfuscating_marker) { :email }
27
+ let(:mysql_cli) { "mysql --user=#{db_username} --password=#{db_password} --host=#{db_host} --port=#{db_port} " }
28
+ let(:test_ddl) { Dir["#{Dir.pwd}/**/account_test_ddl.sql"][0] }
26
29
  end
27
30
 
28
31
  describe '#initialize' do
29
- include_context 'account'
32
+ include_context 'account'
30
33
 
31
34
  context 'when creating an instance of account class' do
32
-
33
35
  it 'when initialized with defaults' do
34
36
  expect(described_class.new).to be_an_instance_of(KPM::Account)
35
37
  end
@@ -37,15 +39,12 @@ describe KPM::Account do
37
39
  it 'when initialized with options' do
38
40
  account_class.should be_an_instance_of(KPM::Account)
39
41
  expect(account_class.instance_variable_get(:@killbill_api_key)).to eq(killbill_api_key)
40
- expect(account_class.instance_variable_get(:@killbill_api_secrets)).to eq(killbill_api_secrets)
42
+ expect(account_class.instance_variable_get(:@killbill_api_secret)).to eq(killbill_api_secret)
41
43
  expect(account_class.instance_variable_get(:@killbill_user)).to eq(killbill_user)
42
44
  expect(account_class.instance_variable_get(:@killbill_password)).to eq(killbill_password)
43
45
  expect(account_class.instance_variable_get(:@killbill_url)).to eq(url)
44
-
45
46
  end
46
-
47
47
  end
48
-
49
48
  end
50
49
 
51
50
  # export data tests
@@ -53,46 +52,38 @@ describe KPM::Account do
53
52
  include_context 'account'
54
53
 
55
54
  context 'when fetching account from api' do
56
-
57
55
  it 'when account id not found' do
58
- expect{ account_class.send(:fetch_export_data, account_id_invalid) }.to raise_error(Interrupt, 'Account id not found')
56
+ expect { account_class.send(:fetch_export_data, account_id_invalid) }.to raise_error(Interrupt, 'Account id not found')
59
57
  end
60
58
 
61
59
  it 'when account id found' do
62
- account_id = creating_account_with_client
63
60
  expect(account_id).to match(/\w{8}(-\w{4}){3}-\w{12}?/)
64
- expect{ account_class.send(:fetch_export_data, account_id) }.not_to raise_error(Interrupt, 'Account id not found')
61
+ expect { account_class.send(:fetch_export_data, account_id) }.not_to raise_error(Interrupt, 'Account id not found')
65
62
  expect(account_class.send(:fetch_export_data, account_id)).to match(account_id)
66
63
  end
67
-
68
64
  end
69
-
70
65
  end
71
66
 
72
67
  describe '#process_export_data' do
73
68
  include_context 'account'
74
69
 
75
70
  context 'when processing data to export' do
76
-
77
71
  it 'when column name qty eq column data qty' do
78
- expect(account_class.send(:process_export_data, cols_data, table_name, cols_names.split("|")).split("|").size).to eq(cols_names.split("|").size)
72
+ expect(account_class.send(:process_export_data, cols_data, table_name, cols_names.split('|')).split('|').size).to eq(cols_names.split('|').size)
79
73
  end
80
74
 
81
75
  it 'when obfuscating data' do
82
76
  marker_index = 0
83
- cols_names.split("|").each do |col_name|
84
- if col_name.equal?(obfuscating_marker.to_s)
85
- break
86
- end
77
+ cols_names.split('|').each do |col_name|
78
+ break if col_name.equal?(obfuscating_marker.to_s)
79
+
87
80
  marker_index += 1
88
81
  end
89
82
 
90
- obfuscating_marker_data = account_class.send(:process_export_data, cols_data, table_name, cols_names.split("|")).split("|")
83
+ obfuscating_marker_data = account_class.send(:process_export_data, cols_data, table_name, cols_names.split('|')).split('|')
91
84
  expect(obfuscating_marker_data[marker_index]).to be_nil
92
85
  end
93
-
94
86
  end
95
-
96
87
  end
97
88
 
98
89
  describe '#remove_export_data' do
@@ -101,14 +92,12 @@ describe KPM::Account do
101
92
  it 'when obfuscating value' do
102
93
  expect(account_class.send(:remove_export_data, table_name, obfuscating_marker.to_s, 'willharnet@example.com')).to be_nil
103
94
  end
104
-
105
95
  end
106
96
 
107
97
  describe '#export' do
108
98
  include_context 'account'
109
99
 
110
100
  context 'when exporting data' do
111
-
112
101
  it 'when file created' do
113
102
  expect(File.exist?(account_class.send(:export, dummy_data))).to be_true
114
103
  end
@@ -117,35 +106,28 @@ describe KPM::Account do
117
106
  expect(File.readlines(account_class.send(:export, dummy_data)).grep(/#{table_name}/)).to be_true
118
107
  expect(File.readlines(account_class.send(:export, dummy_data)).grep(/#{cols_names}/)).to be_true
119
108
  end
120
-
121
109
  end
122
-
123
110
  end
124
111
 
125
112
  describe '#export_data' do
126
113
  include_context 'account'
127
114
 
128
115
  context 'when exporting data; main method' do
129
-
130
116
  it 'when no account id' do
131
- expect{ account_class.export_data }.to raise_error(Interrupt, 'Account id not found')
117
+ expect { account_class.export_data }.to raise_error(Interrupt, 'Account id not found')
132
118
  end
133
119
 
134
120
  it 'when file created' do
135
- account_id = creating_account_with_client
136
121
  expect(account_id).to match(/\w{8}(-\w{4}){3}-\w{12}?/)
137
122
  expect(File.exist?(account_class.export_data(account_id))).to be_true
138
123
  end
139
124
 
140
125
  it 'when file contains account record' do
141
- account_id = creating_account_with_client
142
126
  expect(account_id).to match(/\w{8}(-\w{4}){3}-\w{12}?/)
143
127
  expect(File.readlines(account_class.export_data(account_id)).grep(/#{table_name}/)).to be_true
144
128
  expect(File.readlines(account_class.export_data(account_id)).grep(/#{cols_names}/)).to be_true
145
129
  end
146
-
147
130
  end
148
-
149
131
  end
150
132
 
151
133
  # import data tests
@@ -153,14 +135,14 @@ describe KPM::Account do
153
135
  include_context 'account'
154
136
 
155
137
  it 'when data delimiter is sniffed as "|"' do
156
- open (dummy_data_file), 'w' do |io|
157
- io.puts(dummy_data)
138
+ File.open(dummy_data_file, 'w') do |io|
139
+ io.puts(dummy_data)
158
140
  end
159
-
141
+
160
142
  expect(account_class.send(:sniff_delimiter, dummy_data_file)).to eq('|')
161
143
  end
162
144
  end
163
-
145
+
164
146
  describe '#fill_empty_column' do
165
147
  include_context 'account'
166
148
 
@@ -173,7 +155,7 @@ describe KPM::Account do
173
155
  include_context 'account'
174
156
 
175
157
  it 'when valid date value' do
176
- expect{DateTime.parse(account_class.send(:fix_dates, '2017-04-05T15:01:39.000+0000'))}.not_to raise_error(ArgumentError)
158
+ expect { DateTime.parse(account_class.send(:fix_dates, '2017-04-05T15:01:39.000+0000')) }.not_to raise_error(ArgumentError)
177
159
  end
178
160
 
179
161
  it 'when valid date value match YYYY-MM-DD HH:MM:SS' do
@@ -181,7 +163,7 @@ describe KPM::Account do
181
163
  end
182
164
 
183
165
  it 'when invalid date value' do
184
- expect{DateTime.parse(account_class.send(:fix_dates, 'JO'))}.to raise_error(ArgumentError)
166
+ expect { DateTime.parse(account_class.send(:fix_dates, 'JO')) }.to raise_error(ArgumentError)
185
167
  end
186
168
  end
187
169
 
@@ -196,7 +178,6 @@ describe KPM::Account do
196
178
  it 'when false' do
197
179
  expect(account_class.send(:replace_boolean, false)).to eq(0)
198
180
  end
199
-
200
181
  end
201
182
  end
202
183
 
@@ -222,7 +203,6 @@ describe KPM::Account do
222
203
  it 'when field is search_key1 and table bus_events_history' do
223
204
  expect(account_class.send(:replace_account_record_id, 'bus_events_history', 'search_key1', '1')).to eq(:@account_record_id)
224
205
  end
225
-
226
206
  end
227
207
 
228
208
  describe '#replace_tenant_record_id' do
@@ -242,7 +222,6 @@ describe KPM::Account do
242
222
  account_class.instance_variable_set(:@tenant_record_id, 10)
243
223
  expect(account_class.send(:replace_tenant_record_id, 'bus_events_history', 'search_key2', '1')).to eq(10)
244
224
  end
245
-
246
225
  end
247
226
 
248
227
  describe '#replace_uuid' do
@@ -259,19 +238,39 @@ describe KPM::Account do
259
238
  expect(account_class.send(:replace_uuid, table_name, 'other_id', dummy_account_id)).to eq(dummy_account_id)
260
239
  end
261
240
  end
262
-
263
241
  end
264
242
 
265
243
  describe '#sanitize' do
266
244
  include_context 'account'
267
245
 
268
246
  it 'when skip payment method' do
269
- expect(account_class.send(:sanitize, 'payment_methods', 'plugin_name', 'Payment Method',true)).to eq('__EXTERNAL_PAYMENT__')
247
+ expect(account_class.send(:sanitize, 'payment_methods', 'plugin_name', 'Payment Method', true)).to eq('__EXTERNAL_PAYMENT__')
270
248
  end
271
249
  it 'when nothing to sanitize' do
272
- expect(account_class.send(:sanitize, table_name, 'id', dummy_account_id,false)).to eq(dummy_account_id)
250
+ expect(account_class.send(:sanitize, table_name, 'id', dummy_account_id, false)).to eq(dummy_account_id)
273
251
  end
252
+ end
253
+
254
+ describe '#sanitize_for_b64_date' do
255
+ include_context 'account'
274
256
 
257
+ let(:non_encoded_b64) do
258
+ # This is my test data
259
+ 'This is my test data'
260
+ end
261
+
262
+ let(:encoded_b64) do
263
+ # This is my test data
264
+ 'VGhpcyBpcyBteSB0ZXN0IGRhdGE='
265
+ end
266
+
267
+ it 'when b64 encoded data' do
268
+ expect(account_class.send(:b64_decode_if_needed, encoded_b64).value).to start_with('LOAD_FILE("')
269
+ end
270
+
271
+ it 'when b64 non encoded data' do
272
+ expect(account_class.send(:b64_decode_if_needed, non_encoded_b64)).to eq(non_encoded_b64)
273
+ end
275
274
  end
276
275
 
277
276
  describe '#process_import_data' do
@@ -279,137 +278,139 @@ describe KPM::Account do
279
278
 
280
279
  context 'when processing data to import' do
281
280
  it 'when column name qty eq column data qty without record_id' do
282
- account_class.instance_variable_set(:@generate_record_id,true)
283
- expect(account_class.send(:process_import_data, cols_data, table_name, cols_names.split('|'), false, []).size).to eq(cols_names.split("|").size-1)
281
+ account_class.instance_variable_set(:@generate_record_id, true)
282
+ expect(account_class.send(:process_import_data, cols_data, table_name, cols_names.split('|'), false, []).size).to eq(cols_names.split('|').size - 1)
284
283
  end
285
284
  end
286
-
287
285
  end
288
286
 
289
287
  describe '#import_data' do
290
288
  include_context 'account'
291
289
 
292
290
  context 'when data to import; main import method' do
293
-
294
291
  it 'when creating test schema' do
295
292
  db = create_test_schema
296
293
  expect(db).to eq(db_name)
297
294
  end
298
-
295
+
299
296
  it 'when importing data with empty file' do
300
297
  File.new(dummy_data_file, 'w+').close
301
- expect{account_class.import_data(dummy_data_file,nil,true,false,true) }.to raise_error(Interrupt,"Data on #{dummy_data_file} is invalid")
298
+ expect { account_class.import_data(dummy_data_file, nil, true, false, true) }.to raise_error(Interrupt, "Data on #{dummy_data_file} is invalid")
302
299
  File.delete(dummy_data_file)
303
300
  end
304
-
301
+
305
302
  it 'when importing data with no file' do
306
- expect{account_class.import_data(dummy_data_file,nil,true,false,true) }.to raise_error(Interrupt,'Need to specify a valid file')
303
+ expect { account_class.import_data(dummy_data_file, nil, true, false, true) }.to raise_error(Interrupt, "File #{dummy_data_file} does not exist")
307
304
  end
308
-
305
+
309
306
  it 'when importing data with new record_id' do
310
- open (dummy_data_file), 'w' do |io|
307
+ File.open(dummy_data_file, 'w') do |io|
311
308
  io.puts(dummy_data)
312
309
  end
313
- expect{account_class.import_data(dummy_data_file,nil,true,false,true) }.not_to raise_error(Interrupt)
310
+ expect { account_class.import_data(dummy_data_file, nil, true, false, true) }.not_to raise_error(Interrupt)
311
+
312
+ verify_data(dummy_account_id)
314
313
 
315
- row_count_inserted = delete_statement('accounts','id',dummy_account_id)
314
+ row_count_inserted = delete_statement('accounts', 'id', dummy_account_id)
316
315
  expect(row_count_inserted).to eq('1')
317
- row_count_inserted = delete_statement('account_history','external_key',dummy_account_id)
316
+ row_count_inserted = delete_statement('account_history', 'external_key', dummy_account_id)
318
317
  expect(row_count_inserted).to eq('1')
319
318
  end
320
319
 
321
320
  it 'when importing data reusing record_id' do
322
- open (dummy_data_file), 'w' do |io|
321
+ File.open(dummy_data_file, 'w') do |io|
323
322
  io.puts(dummy_data)
324
323
  end
325
- expect{account_class.import_data(dummy_data_file,nil,true,false,false) }.not_to raise_error(Interrupt)
324
+ expect { account_class.import_data(dummy_data_file, nil, true, false, false) }.not_to raise_error(Interrupt)
326
325
 
327
- row_count_inserted = delete_statement('accounts','id',dummy_account_id)
326
+ verify_data(dummy_account_id)
327
+
328
+ row_count_inserted = delete_statement('accounts', 'id', dummy_account_id)
328
329
  expect(row_count_inserted).to eq('1')
329
- row_count_inserted = delete_statement('account_history','external_key',dummy_account_id)
330
+ row_count_inserted = delete_statement('account_history', 'external_key', dummy_account_id)
330
331
  expect(row_count_inserted).to eq('1')
331
332
  end
332
333
 
333
334
  it 'when importing data with different tenant_record_id' do
334
- open (dummy_data_file), 'w' do |io|
335
+ File.open(dummy_data_file, 'w') do |io|
335
336
  io.puts(dummy_data)
336
337
  end
337
- expect{account_class.import_data(dummy_data_file,10,true,false,true) }.not_to raise_error(Interrupt)
338
+ expect { account_class.import_data(dummy_data_file, 10, true, false, true) }.not_to raise_error(Interrupt)
339
+
340
+ verify_data(dummy_account_id)
338
341
 
339
- row_count_inserted = delete_statement('accounts','id',dummy_account_id)
342
+ row_count_inserted = delete_statement('accounts', 'id', dummy_account_id)
340
343
  expect(row_count_inserted).to eq('1')
341
- row_count_inserted = delete_statement('account_history','external_key',dummy_account_id)
344
+ row_count_inserted = delete_statement('account_history', 'external_key', dummy_account_id)
342
345
  expect(row_count_inserted).to eq('1')
343
346
  end
344
347
 
345
348
  it 'when round trip' do
346
- open (dummy_data_file), 'w' do |io|
349
+ File.open(dummy_data_file, 'w') do |io|
347
350
  io.puts(dummy_data)
348
351
  end
349
- expect{account_class.import_data(dummy_data_file,10,true,true,true) }.not_to raise_error(Interrupt)
352
+ expect { account_class.import_data(dummy_data_file, 10, true, true, true) }.not_to raise_error(Interrupt)
350
353
  new_account_id = account_class.instance_variable_get(:@tables_id)
351
354
 
352
- row_count_inserted = delete_statement('accounts','id',new_account_id['accounts_id'])
355
+ verify_data(new_account_id['accounts_id'])
356
+
357
+ row_count_inserted = delete_statement('accounts', 'id', new_account_id['accounts_id'])
353
358
  expect(row_count_inserted).to eq('1')
354
- row_count_inserted = delete_statement('account_history','external_key',new_account_id['accounts_id'])
359
+ row_count_inserted = delete_statement('account_history', 'external_key', new_account_id['accounts_id'])
355
360
  expect(row_count_inserted).to eq('1')
356
361
  end
357
-
362
+
358
363
  it 'when droping test schema' do
359
364
  response = drop_test_schema
360
365
  expect(response).to match('')
361
366
  end
362
-
363
367
  end
364
-
365
368
  end
366
-
367
- private
368
- def creating_account_with_client
369
- if $account_id.nil?
370
- KillBillClient.url = url
371
-
372
- options = {
373
- :username => killbill_user,
374
- :password => killbill_password,
375
- :api_key => killbill_api_key,
376
- :api_secret => killbill_api_secrets
377
- }
378
-
379
- account = KillBillClient::Model::Account.new
380
- account.name = 'KPM Account Test'
381
- account.first_name_length = 3
382
- account.external_key = SecureRandom.uuid
383
- account.currency = 'USD'
384
- account = account.create('kpm_account_test', 'kpm_account_test', 'kpm_account_test', options)
385
-
386
- $account_id = account.account_id
387
369
 
388
- end
389
-
390
- $account_id
391
- end
392
-
393
- def delete_statement(table_name,column_name,account_id)
394
- response = `#{mysql_cli} #{db_name} -e "DELETE FROM #{table_name} WHERE #{column_name} = '#{account_id}'; SELECT ROW_COUNT();" 2>&1`
395
- response_msg = response.split("\n")
396
- row_count_inserted = response_msg[response_msg.size - 1]
397
-
398
- row_count_inserted
399
- end
400
-
401
- def create_test_schema
402
- response = `#{mysql_cli} -e "CREATE DATABASE IF NOT EXISTS #{db_name};"`
403
- response = `#{mysql_cli} #{db_name} < "#{test_ddl}" 2>&1`
404
- response_msg = response.split("\n")
405
- used_database = response_msg[response_msg.size - 1]
406
-
407
- used_database
408
- end
409
-
410
- def drop_test_schema
411
- response = `#{mysql_cli} -e "DROP DATABASE #{db_name};"`;
412
- response
413
- end
370
+ private
371
+
372
+ def creating_account_with_client
373
+ KillBillClient.url = url
374
+
375
+ options = {
376
+ username: killbill_user,
377
+ password: killbill_password,
378
+ api_key: killbill_api_key,
379
+ api_secret: killbill_api_secret
380
+ }
381
+
382
+ account = KillBillClient::Model::Account.new
383
+ account.name = 'KPM Account Test'
384
+ account.first_name_length = 3
385
+ account.external_key = SecureRandom.uuid
386
+ account.currency = 'USD'
387
+ account = account.create('kpm_account_test', 'kpm_account_test', 'kpm_account_test', options)
388
+
389
+ account.account_id
390
+ end
414
391
 
415
- end
392
+ def verify_data(account_id)
393
+ response = `#{mysql_cli} #{db_name} -e "select company_name FROM accounts WHERE id = '#{account_id}';" 2>&1`
394
+ response_msg = response.split("\n")
395
+ company_name = response_msg[response_msg.size - 1]
396
+
397
+ expect(company_name).to eq('Company|\\nName')
398
+ end
399
+
400
+ def delete_statement(table_name, column_name, account_id)
401
+ response = `#{mysql_cli} #{db_name} -e "DELETE FROM #{table_name} WHERE #{column_name} = '#{account_id}'; SELECT ROW_COUNT();" 2>&1`
402
+ response_msg = response.split("\n")
403
+ response_msg[response_msg.size - 1]
404
+ end
405
+
406
+ def create_test_schema
407
+ `#{mysql_cli} -e "CREATE DATABASE IF NOT EXISTS #{db_name};"`
408
+ response = `#{mysql_cli} #{db_name} < "#{test_ddl}" 2>&1`
409
+ response_msg = response.split("\n")
410
+ response_msg[response_msg.size - 1]
411
+ end
412
+
413
+ def drop_test_schema
414
+ `#{mysql_cli} -e "DROP DATABASE #{db_name};"`
415
+ end
416
+ end