File indexing completed on 2022-11-29 19:42:56

0001 #!/usr/bin/env ruby
0002 
0003 # Copyright 2017 Jonathan Riddell <jr@jriddell.org>
0004 # Copyright 2015-2019 Harald Sitter <sitter@kde.org>
0005 #
0006 # This program is free software; you can redistribute it and/or
0007 # modify it under the terms of the GNU General Public License as
0008 # published by the Free Software Foundation; either version 2 of
0009 # the License or (at your option) version 3 or any later version
0010 # accepted by the membership of KDE e.V. (or its successor approved
0011 # by the membership of KDE e.V.), which shall act as a proxy
0012 # defined in Section 14 of version 3 of the license.
0013 #
0014 # This program is distributed in the hope that it will be useful,
0015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 # GNU General Public License for more details.
0018 #
0019 # You should have received a copy of the GNU General Public License
0020 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 require 'test/unit'
0023 require_relative 'neondocker'
0024 require 'timeout'
0025 
0026 class ExecutableTest < Test::Unit::TestCase
0027   def setup
0028     ENV['PATH'] = Dir.pwd
0029   end
0030 
0031   def make_exe(name)
0032     File.write(name, '')
0033     File.chmod(0o700, name)
0034   end
0035 
0036   def test_exec_not_windows
0037     # If env looks windowsy, skip this test. It won't pass because we look
0038     # for gpg2.exe which obviously won't exist.
0039     return if ENV['PATHEXT']
0040     make_exe('gpg2')
0041     assert_equal "#{Dir.pwd}/gpg2", Executable.new('gpg2').find
0042     assert_nil Executable.new('foobar').find
0043   end
0044 
0045   def test_windows
0046     # windows
0047     ENV['RELEASEME_FORCE_WINDOWS']
0048     make_exe('gpg2.exe')
0049     make_exe('svn.com')
0050 
0051     ENV['PATHEXT'] = '.COM;.EXE'.downcase # downcase so this passes on Linux
0052     ENV['PATH'] = Dir.pwd
0053 
0054     assert_equal "#{Dir.pwd}/gpg2.exe", Executable.new('gpg2').find
0055     assert_equal "#{Dir.pwd}/svn.com", Executable.new('svn').find
0056     assert_nil Executable.new('foobar').find
0057   end
0058 end
0059 
0060 class NeonDockerTest < Test::Unit::TestCase
0061   def setup
0062     @neon_docker = NeonDocker.new
0063   end
0064 
0065   def test_full_session
0066     Timeout.timeout(2) do
0067       system('./neondocker.rb')
0068     end
0069     system('killall Xephyr')
0070   rescue Timeout::Error
0071     omit('timeout')
0072   end
0073 
0074   def test_standalone_session
0075     Timeout.timeout(2) do
0076       system('./neondocker.rb okular')
0077     end
0078   rescue Timeout::Error
0079     omit('timeout')
0080   end
0081 
0082   def test_unknown_edition
0083     exit_status = system('./neondocker.rb', '--edition', 'foo')
0084     refute(exit_status)
0085   end
0086 
0087   def test_tag_name
0088     @neon_docker.options = {pull: false, all: false, edition: 'user', kill: false }
0089     assert_equal('kdeneon/plasma:user', @neon_docker.docker_image_tag)
0090   end
0091 
0092   def test_run_xephyr
0093     @neon_docker.running_xephyr do
0094       puts 'running'
0095     end
0096   end
0097 
0098   def test_docker_has_image
0099     @neon_docker.tag = 'kdeneon/plasma:user'
0100     assert(@neon_docker.docker_has_image?)
0101     @neon_docker.tag = 'foo'
0102     refute(@neon_docker.docker_has_image?)
0103   end
0104 
0105   def test_container
0106     @neon_docker.options = {pull: false, all: false, edition: 'user', kill: false }
0107     @neon_docker.tag = 'kdeneon/plasma:user'
0108     assert(@neon_docker.container.is_a?(Docker::Container))
0109     @neon_docker.container = nil
0110     @neon_docker.tag = 'moo'
0111     assert_nil(@neon_docker.container)
0112   end
0113 
0114   def test_xdisplay
0115     assert_equal(1, @neon_docker.xdisplay)
0116   end
0117 end