]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/services/test/service_menu_installation_test.rb
Merge branch 'Applications/19.04'
[dolphin.git] / src / settings / services / test / service_menu_installation_test.rb
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 ServiceMenuInstallationTest < 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_install
41 service_dir = File.join(Dir.pwd, 'share/servicemenu-download')
42 FileUtils.mkpath(service_dir)
43 archive = "#{service_dir}/foo.tar"
44
45 archive_dir = 'foo' # relative so tar cf is relative without fuzz
46 FileUtils.mkpath(archive_dir)
47 File.write("#{archive_dir}/install-it.sh", <<-INSTALL_IT_SH)
48 #!/bin/sh
49 touch #{@tmpdir}/install-it.sh-run
50 INSTALL_IT_SH
51 File.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
52 #!/bin/sh
53 touch #{@tmpdir}/install.sh-run
54 INSTALL_SH
55 assert(system('tar', '-cf', archive, archive_dir))
56
57 assert(covered_system('servicemenuinstallation', archive))
58
59 tar_dir = "#{service_dir}/foo.tar-dir"
60 tar_extract_dir = "#{service_dir}/foo.tar-dir/foo"
61 assert_path_exist(tar_dir)
62 assert_path_exist(tar_extract_dir)
63 assert_path_exist("#{tar_extract_dir}/install-it.sh")
64 assert_path_exist("#{tar_extract_dir}/install.sh")
65 end
66
67 def test_run_install_with_arg
68 service_dir = File.join(Dir.pwd, 'share/servicemenu-download')
69 FileUtils.mkpath(service_dir)
70 archive = "#{service_dir}/foo.tar"
71
72 archive_dir = 'foo' # relative so tar cf is relative without fuzz
73 FileUtils.mkpath(archive_dir)
74 File.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
75 #!/bin/sh
76 if [ "$@" = "--install" ]; then
77 touch #{@tmpdir}/install.sh-run
78 exit 0
79 fi
80 exit 1
81 INSTALL_SH
82 assert(system('tar', '-cf', archive, archive_dir))
83
84 assert(covered_system('servicemenuinstallation', archive))
85
86 tar_dir = "#{service_dir}/foo.tar-dir"
87 tar_extract_dir = "#{service_dir}/foo.tar-dir/foo"
88 assert_path_exist(tar_dir)
89 assert_path_exist(tar_extract_dir)
90 assert_path_not_exist("#{tar_extract_dir}/install-it.sh")
91 assert_path_exist("#{tar_extract_dir}/install.sh")
92 end
93
94 def test_run_fail
95 service_dir = File.join(Dir.pwd, 'share/servicemenu-download')
96 FileUtils.mkpath(service_dir)
97 archive = "#{service_dir}/foo.tar"
98
99 archive_dir = 'foo' # relative so tar cf is relative without fuzz
100 FileUtils.mkpath(archive_dir)
101 assert(system('tar', '-cf', archive, archive_dir))
102
103 refute(covered_system('servicemenuinstallation', archive))
104 end
105
106 def test_run_desktop
107 service_dir = File.join(Dir.pwd, 'share/servicemenu-download')
108 downloaded_file = "#{service_dir}/foo.desktop"
109 FileUtils.mkpath(service_dir)
110 FileUtils.touch(downloaded_file)
111
112 installed_file = "#{ENV['XDG_DATA_HOME']}/kservices5/ServiceMenus/foo.desktop"
113
114 assert(covered_system('servicemenuinstallation', downloaded_file))
115
116 assert_path_exist(downloaded_file)
117 assert_path_exist(installed_file)
118 end
119 end