Changeset View
Changeset View
Standalone View
Standalone View
src/settings/services/test/service_menu_deinstallation_test.rb
- This file was added.
1 | #!/usr/bin/env ruby | ||||
---|---|---|---|---|---|
2 | | ||||
3 | # Copyright (C) 2019 Harald Sitter <sitter@kde.org> | ||||
4 | # | ||||
5 | # This program is free software; you can redistribute it and/or modify | ||||
6 | # it under the terms of the GNU General Public License as published by | ||||
7 | # the Free Software Foundation; either version 2 of the License, or | ||||
8 | # (at your option) any later version. | ||||
9 | # | ||||
10 | # This program is distributed in the hope that it will be useful, | ||||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
13 | # GNU General Public License for more details. | ||||
14 | # | ||||
15 | # You should have received a copy of the GNU General Public License | ||||
16 | # along with this program; if not, write to the | ||||
17 | # Free Software Foundation, Inc., | ||||
18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
19 | | ||||
20 | require_relative 'test_helper' | ||||
21 | | ||||
22 | require 'tmpdir' | ||||
23 | | ||||
24 | class ServiceMenuDeinstallationTest < Test::Unit::TestCase | ||||
25 | def setup | ||||
26 | @tmpdir = Dir.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}") | ||||
27 | @pwdir = Dir.pwd | ||||
28 | Dir.chdir(@tmpdir) | ||||
29 | | ||||
30 | ENV['XDG_DATA_HOME'] = File.join(@tmpdir, 'data') | ||||
31 | end | ||||
32 | | ||||
33 | def teardown | ||||
34 | Dir.chdir(@pwdir) | ||||
35 | FileUtils.rm_rf(@tmpdir) | ||||
36 | | ||||
37 | ENV.delete('XDG_DATA_HOME') | ||||
38 | end | ||||
39 | | ||||
40 | def test_run_deinstall | ||||
41 | service_dir = File.join(Dir.pwd, 'share/servicemenu-download') | ||||
42 | archive_base = "#{service_dir}/foo.zip" | ||||
43 | archive_dir = "#{archive_base}-dir/foo-1.1/" | ||||
44 | FileUtils.mkpath(archive_dir) | ||||
45 | File.write("#{archive_dir}/deinstall.sh", <<-DEINSTALL_SH) | ||||
46 | #!/bin/sh | ||||
47 | touch #{@tmpdir}/deinstall.sh-run | ||||
48 | DEINSTALL_SH | ||||
49 | File.write("#{archive_dir}/install.sh", <<-INSTALL_SH) | ||||
50 | #!/bin/sh | ||||
51 | touch #{@tmpdir}/install.sh-run | ||||
52 | INSTALL_SH | ||||
53 | | ||||
54 | assert(covered_system('servicemenudeinstallation', archive_base)) | ||||
55 | | ||||
56 | # deinstaller should be run | ||||
57 | # installer should not be run | ||||
58 | # archive_dir should have been correctly removed | ||||
59 | | ||||
60 | assert_path_exist('deinstall.sh-run') | ||||
61 | assert_path_not_exist('install.sh-run') | ||||
62 | assert_path_not_exist(archive_dir) | ||||
63 | end | ||||
64 | | ||||
65 | def test_run_install_with_arg | ||||
66 | service_dir = File.join(Dir.pwd, 'share/servicemenu-download') | ||||
67 | archive_base = "#{service_dir}/foo.zip" | ||||
68 | archive_dir = "#{archive_base}-dir/foo-1.1/" | ||||
69 | FileUtils.mkpath(archive_dir) | ||||
70 | | ||||
71 | File.write("#{archive_dir}/install.sh", <<-INSTALL_SH) | ||||
72 | #!/bin/sh | ||||
73 | if [ "$@" = "--uninstall" ]; then | ||||
74 | touch #{@tmpdir}/install.sh-run | ||||
75 | exit 0 | ||||
76 | fi | ||||
77 | exit 1 | ||||
78 | INSTALL_SH | ||||
79 | | ||||
80 | assert(covered_system('servicemenudeinstallation', archive_base)) | ||||
81 | | ||||
82 | assert_path_not_exist('deinstall.sh-run') | ||||
83 | assert_path_exist('install.sh-run') | ||||
84 | assert_path_not_exist(archive_dir) | ||||
85 | end | ||||
86 | | ||||
87 | # no scripts in sight | ||||
88 | def test_run_fail | ||||
89 | service_dir = File.join(Dir.pwd, 'share/servicemenu-download') | ||||
90 | archive_base = "#{service_dir}/foo.zip" | ||||
91 | archive_dir = "#{archive_base}-dir/foo-1.1/" | ||||
92 | FileUtils.mkpath(archive_dir) | ||||
93 | | ||||
94 | refute(covered_system('servicemenudeinstallation', archive_base)) | ||||
95 | | ||||
96 | # I am unsure if deinstallation really should keep the files around. But | ||||
97 | # that's how it behaved originally so it's supposedly intentional | ||||
98 | # - sitter, 2019 | ||||
99 | assert_path_exist(archive_dir) | ||||
100 | end | ||||
101 | | ||||
102 | # For desktop files things are a bit special. There is one in .local/share/servicemenu-download | ||||
103 | # and another in the actual ServiceMenus dir. The latter gets removed by the | ||||
104 | # script, the former by KNS. | ||||
105 | def test_run_desktop | ||||
106 | service_dir = File.join(Dir.pwd, 'share/servicemenu-download') | ||||
107 | downloaded_file = "#{service_dir}/foo.desktop" | ||||
108 | FileUtils.mkpath(service_dir) | ||||
109 | FileUtils.touch(downloaded_file) | ||||
110 | | ||||
111 | menu_dir = "#{ENV['XDG_DATA_HOME']}/kservices5/ServiceMenus/" | ||||
112 | installed_file = "#{menu_dir}/foo.desktop" | ||||
113 | FileUtils.mkpath(menu_dir) | ||||
114 | FileUtils.touch(installed_file) | ||||
115 | | ||||
116 | assert(covered_system('servicemenudeinstallation', downloaded_file)) | ||||
117 | | ||||
118 | assert_path_exist(downloaded_file) | ||||
119 | assert_path_not_exist(installed_file) | ||||
120 | end | ||||
121 | end |