]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/services/test/service_menu_installation_test.rb
7c05a40e37c02f116cbb4cfc7bb1e543e54a8e6b
[dolphin.git] / src / settings / services / test / service_menu_installation_test.rb
1 #!/usr/bin/env ruby
2
3 # SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>
4 #
5 # SPDX-License-Identifier: GPL-2.0-or-later
6
7 require_relative 'test_helper'
8
9 require 'tmpdir'
10
11 class ServiceMenuInstallationTest < Test::Unit::TestCase
12 def setup
13 @tmpdir = Dir.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}")
14 @pwdir = Dir.pwd
15 Dir.chdir(@tmpdir)
16
17 ENV['XDG_DATA_HOME'] = File.join(@tmpdir, 'data')
18 end
19
20 def teardown
21 Dir.chdir(@pwdir)
22 FileUtils.rm_rf(@tmpdir)
23
24 ENV.delete('XDG_DATA_HOME')
25 end
26
27 def test_run_install
28 service_dir = File.join(Dir.pwd, 'share/servicemenu-download')
29 FileUtils.mkpath(service_dir)
30 archive = "#{service_dir}/foo.tar"
31
32 archive_dir = 'foo' # relative so tar cf is relative without fuzz
33 FileUtils.mkpath(archive_dir)
34 File.write("#{archive_dir}/install-it.sh", <<-INSTALL_IT_SH)
35 #!/bin/sh
36 touch #{@tmpdir}/install-it.sh-run
37 INSTALL_IT_SH
38 File.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
39 #!/bin/sh
40 touch #{@tmpdir}/install.sh-run
41 INSTALL_SH
42 assert(system('tar', '-cf', archive, archive_dir))
43
44 assert(system('servicemenuinstaller', 'install', archive))
45
46 tar_dir = "#{service_dir}/foo.tar-dir"
47 tar_extract_dir = "#{service_dir}/foo.tar-dir/foo"
48 assert_path_exist(tar_dir)
49 assert_path_exist(tar_extract_dir)
50 assert_path_exist("#{tar_extract_dir}/install-it.sh")
51 assert_path_exist("#{tar_extract_dir}/install.sh")
52 end
53
54 def test_run_install_with_arg
55 service_dir = File.join(Dir.pwd, 'share/servicemenu-download')
56 FileUtils.mkpath(service_dir)
57 archive = "#{service_dir}/foo.tar"
58
59 archive_dir = 'foo' # relative so tar cf is relative without fuzz
60 FileUtils.mkpath(archive_dir)
61 File.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
62 #!/bin/sh
63 if [ "$@" = "--install" ]; then
64 touch #{@tmpdir}/install.sh-run
65 exit 0
66 fi
67 exit 1
68 INSTALL_SH
69 assert(system('tar', '-cf', archive, archive_dir))
70
71 assert(system('servicemenuinstaller', 'install', archive))
72
73 tar_dir = "#{service_dir}/foo.tar-dir"
74 tar_extract_dir = "#{service_dir}/foo.tar-dir/foo"
75 assert_path_exist(tar_dir)
76 assert_path_exist(tar_extract_dir)
77 assert_path_not_exist("#{tar_extract_dir}/install-it.sh")
78 assert_path_exist("#{tar_extract_dir}/install.sh")
79 end
80
81 def test_run_fail
82 service_dir = File.join(Dir.pwd, 'share/servicemenu-download')
83 FileUtils.mkpath(service_dir)
84 archive = "#{service_dir}/foo.tar"
85
86 archive_dir = 'foo' # relative so tar cf is relative without fuzz
87 FileUtils.mkpath(archive_dir)
88 assert(system('tar', '-cf', archive, archive_dir))
89
90 refute(system('servicemenuinstaller', 'install', archive))
91 end
92
93 def test_run_desktop
94 service_dir = File.join(Dir.pwd, 'share/servicemenu-download')
95 downloaded_file = "#{service_dir}/foo.desktop"
96 FileUtils.mkpath(service_dir)
97 FileUtils.touch(downloaded_file)
98
99 installed_file = "#{ENV['XDG_DATA_HOME']}/kservices5/ServiceMenus/foo.desktop"
100
101 assert(system('servicemenuinstaller', 'install', downloaded_file))
102
103 assert_path_exist(downloaded_file)
104 assert_path_exist(installed_file)
105 end
106 end