File indexing completed on 2024-05-19 16:49:24
0001 #!/usr/bin/env ruby 0002 0003 # SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org> 0004 # 0005 # SPDX-License-Identifier: GPL-2.0-or-later 0006 0007 require_relative 'test_helper' 0008 0009 require 'tmpdir' 0010 0011 class ServiceMenuDeinstallationTest < Test::Unit::TestCase 0012 def setup 0013 @tmpdir = Dir.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}") 0014 @pwdir = Dir.pwd 0015 Dir.chdir(@tmpdir) 0016 0017 ENV['XDG_DATA_HOME'] = File.join(@tmpdir, 'data') 0018 end 0019 0020 def teardown 0021 Dir.chdir(@pwdir) 0022 FileUtils.rm_rf(@tmpdir) 0023 0024 ENV.delete('XDG_DATA_HOME') 0025 end 0026 0027 def test_run_deinstall 0028 service_dir = File.join(Dir.pwd, 'share/servicemenu-download') 0029 archive_base = "#{service_dir}/foo.zip" 0030 archive_dir = "#{archive_base}-dir/foo-1.1/" 0031 FileUtils.mkpath(archive_dir) 0032 File.write("#{archive_dir}/deinstall.sh", <<-DEINSTALL_SH) 0033 #!/bin/sh 0034 set -e 0035 cat deinstall.sh 0036 touch #{@tmpdir}/deinstall.sh-run 0037 DEINSTALL_SH 0038 File.write("#{archive_dir}/install.sh", <<-INSTALL_SH) 0039 #!/bin/sh 0040 set -e 0041 cat install.sh 0042 touch #{@tmpdir}/install.sh-run 0043 INSTALL_SH 0044 0045 assert(system('servicemenuinstaller', 'uninstall', archive_base)) 0046 0047 # deinstaller should be run 0048 # installer should not be run 0049 # archive_dir should have been correctly removed 0050 0051 assert_path_exist('deinstall.sh-run') 0052 assert_path_not_exist('install.sh-run') 0053 assert_path_not_exist(archive_dir) 0054 end 0055 0056 def test_run_install_with_arg 0057 service_dir = File.join(Dir.pwd, 'share/servicemenu-download') 0058 archive_base = "#{service_dir}/foo.zip" 0059 archive_dir = "#{archive_base}-dir/foo-1.1/" 0060 FileUtils.mkpath(archive_dir) 0061 0062 File.write("#{archive_dir}/install.sh", <<-INSTALL_SH) 0063 #!/bin/sh 0064 if [ "$@" = "--uninstall" ]; then 0065 touch #{@tmpdir}/install.sh-run 0066 exit 0 0067 fi 0068 exit 1 0069 INSTALL_SH 0070 0071 assert(system('servicemenuinstaller', 'uninstall', archive_base)) 0072 0073 assert_path_not_exist('deinstall.sh-run') 0074 assert_path_exist('install.sh-run') 0075 assert_path_not_exist(archive_dir) 0076 end 0077 0078 # no scripts in sight 0079 def test_run_fail 0080 service_dir = File.join(Dir.pwd, 'share/servicemenu-download') 0081 archive_base = "#{service_dir}/foo.zip" 0082 archive_dir = "#{archive_base}-dir/foo-1.1/" 0083 FileUtils.mkpath(archive_dir) 0084 0085 refute(system('servicemenuinstaller', 'uninstall', archive_base)) 0086 0087 # I am unsure if deinstallation really should keep the files around. But 0088 # that's how it behaved originally so it's supposedly intentional 0089 # - sitter, 2019 0090 assert_path_exist(archive_dir) 0091 end 0092 0093 # For desktop files things are a bit special. There is one in .local/share/servicemenu-download 0094 # and another in the actual ServiceMenus dir. The latter gets removed by the 0095 # script, the former by KNS. 0096 def test_run_desktop 0097 service_dir = File.join(Dir.pwd, 'share/servicemenu-download') 0098 downloaded_file = "#{service_dir}/foo.desktop" 0099 FileUtils.mkpath(service_dir) 0100 FileUtils.touch(downloaded_file) 0101 0102 menu_dir = "#{ENV['XDG_DATA_HOME']}/kservices5/ServiceMenus/" 0103 installed_file = "#{menu_dir}/foo.desktop" 0104 FileUtils.mkpath(menu_dir) 0105 FileUtils.touch(installed_file) 0106 0107 assert(system('servicemenuinstaller', 'uninstall', downloaded_file)) 0108 0109 assert_path_exist(downloaded_file) 0110 assert_path_not_exist(installed_file) 0111 end 0112 end