Changeset View
Changeset View
Standalone View
Standalone View
src/settings/services/test/service_menu_deinstallation_test.rb
Show All 14 Lines | |||||
15 | # You should have received a copy of the GNU General Public License | 15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with this program; if not, write to the | 16 | # along with this program; if not, write to the | ||
17 | # Free Software Foundation, Inc., | 17 | # Free Software Foundation, Inc., | ||
18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | 19 | | |||
20 | require_relative 'test_helper' | 20 | require_relative 'test_helper' | ||
21 | 21 | | |||
22 | require 'tmpdir' | 22 | require 'tmpdir' | ||
23 | require 'securerandom' | ||||
sitter: sort alphabetically please | |||||
23 | 24 | | |||
24 | class ServiceMenuDeinstallationTest < Test::Unit::TestCase | 25 | class ServiceMenuDeinstallationTest < Test::Unit::TestCase | ||
25 | def setup | 26 | def setup | ||
26 | @tmpdir = Dir.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}") | 27 | @tmpdir = Dir.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}") | ||
27 | @pwdir = Dir.pwd | 28 | @pwdir = Dir.pwd | ||
28 | Dir.chdir(@tmpdir) | 29 | Dir.chdir(@tmpdir) | ||
29 | 30 | | |||
30 | ENV['XDG_DATA_HOME'] = File.join(@tmpdir, 'data') | 31 | ENV['XDG_DATA_HOME'] = File.join(@tmpdir, 'data') | ||
31 | end | 32 | end | ||
32 | 33 | | |||
33 | def teardown | 34 | def teardown | ||
34 | Dir.chdir(@pwdir) | 35 | Dir.chdir(@pwdir) | ||
35 | FileUtils.rm_rf(@tmpdir) | 36 | FileUtils.rm_rf(@tmpdir) | ||
36 | 37 | | |||
37 | ENV.delete('XDG_DATA_HOME') | 38 | ENV.delete('XDG_DATA_HOME') | ||
38 | end | 39 | end | ||
39 | 40 | | |||
40 | def test_run_deinstall | 41 | def run_deinstall_success(relative_path) | ||
41 | service_dir = File.join(Dir.pwd, 'share/servicemenu-download') | 42 | service_dir = File.join(Dir.pwd, 'share/servicemenu-download') | ||
42 | archive_base = "#{service_dir}/foo.zip" | 43 | archive_base = "#{service_dir}/foo.zip" | ||
43 | archive_dir = "#{archive_base}-dir/foo-1.1/" | 44 | archive_dir = "#{archive_base}-dir/foo-1.1/" | ||
44 | FileUtils.mkpath(archive_dir) | 45 | scripts_dir = "#{archive_dir}/#{relative_path}" | ||
45 | File.write("#{archive_dir}/deinstall.sh", <<-DEINSTALL_SH) | 46 | FileUtils.mkpath(scripts_dir) | ||
47 | deinstall_tmp = "#{@tmpdir}/#{SecureRandom.hex(5)}_deinstall.sh-run" | ||||
48 | install_tmp = "#{@tmpdir}/#{SecureRandom.hex(5)}_install.sh-run" | ||||
49 | File.write("#{scripts_dir}/deinstall.sh", <<-DEINSTALL_SH) | ||||
46 | #!/bin/sh | 50 | #!/bin/sh | ||
47 | touch #{@tmpdir}/deinstall.sh-run | 51 | set -e | ||
52 | cat deinstall.sh | ||||
53 | touch #{deinstall_tmp} | ||||
48 | DEINSTALL_SH | 54 | DEINSTALL_SH | ||
49 | File.write("#{archive_dir}/install.sh", <<-INSTALL_SH) | 55 | File.write("#{scripts_dir}/install.sh", <<-INSTALL_SH) | ||
50 | #!/bin/sh | 56 | #!/bin/sh | ||
51 | touch #{@tmpdir}/install.sh-run | 57 | set -e | ||
58 | cat install.sh | ||||
59 | touch #{install_tmp} | ||||
52 | INSTALL_SH | 60 | INSTALL_SH | ||
53 | 61 | | |||
54 | assert(system('servicemenuinstaller', 'uninstall', archive_base)) | 62 | assert(system('servicemenuinstaller', 'uninstall', archive_base)) | ||
55 | 63 | | |||
56 | # deinstaller should be run | 64 | # deinstaller should be run | ||
57 | # installer should not be run | 65 | # installer should not be run | ||
58 | # archive_dir should have been correctly removed | 66 | # archive_dir should have been correctly removed | ||
59 | 67 | | |||
60 | assert_path_exist('deinstall.sh-run') | 68 | assert_path_exist(deinstall_tmp) | ||
61 | assert_path_not_exist('install.sh-run') | 69 | assert_path_not_exist(install_tmp) | ||
62 | assert_path_not_exist(archive_dir) | 70 | assert_path_not_exist(archive_dir) | ||
63 | end | 71 | end | ||
64 | 72 | | |||
73 | def test_run_deinstall | ||||
74 | run_deinstall_success('') | ||||
75 | end | ||||
76 | | ||||
77 | def test_run_deinstall_subdirs | ||||
78 | run_deinstall_success('abc/def') | ||||
79 | end | ||||
80 | | ||||
65 | def test_run_install_with_arg | 81 | def test_run_install_with_arg | ||
66 | service_dir = File.join(Dir.pwd, 'share/servicemenu-download') | 82 | service_dir = File.join(Dir.pwd, 'share/servicemenu-download') | ||
67 | archive_base = "#{service_dir}/foo.zip" | 83 | archive_base = "#{service_dir}/foo.zip" | ||
68 | archive_dir = "#{archive_base}-dir/foo-1.1/" | 84 | archive_dir = "#{archive_base}-dir/foo-1.1/" | ||
69 | FileUtils.mkpath(archive_dir) | 85 | FileUtils.mkpath(archive_dir) | ||
70 | 86 | | |||
71 | File.write("#{archive_dir}/install.sh", <<-INSTALL_SH) | 87 | File.write("#{archive_dir}/install.sh", <<-INSTALL_SH) | ||
72 | #!/bin/sh | 88 | #!/bin/sh | ||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
sort alphabetically please