tpkg 2.3.3 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/Portfile +39 -0
- data/Portfile.template +39 -0
- data/README.md +43 -0
- data/Rakefile +468 -18
- data/bin/gem2tpkg +2 -2
- data/bin/tpkg +18 -13
- data/bin/tpkg_uploader +132 -0
- data/ca.pem +1 -0
- data/control +7 -0
- data/depend +3 -0
- data/externals-etch/authorized_keys +40 -0
- data/externals-etch/group +9 -0
- data/externals-etch/iptables +38 -0
- data/externals-etch/limits +30 -0
- data/externals-etch/nfs +30 -0
- data/externals-etch/sudo +30 -0
- data/externals-etch/supplemental_groups +8 -0
- data/externals-etch/sysctl +30 -0
- data/externals-etch/user +41 -0
- data/externals/group +39 -0
- data/externals/supplemental_groups +48 -0
- data/externals/user +39 -0
- data/lib/tpkg.rb +260 -991
- data/lib/tpkg/os.rb +164 -0
- data/lib/tpkg/os/debian.rb +159 -0
- data/lib/tpkg/os/freebsd.rb +113 -0
- data/lib/tpkg/os/macosx.rb +113 -0
- data/lib/tpkg/os/redhat.rb +173 -0
- data/lib/tpkg/os/solaris.rb +101 -0
- data/lib/tpkg/os/windows.rb +26 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
- data/lib/tpkg/version.rb +3 -0
- data/man/man1/cpan2tpkg.1 +82 -0
- data/man/man1/gem2tpkg.1 +120 -0
- data/man/man1/tpkg.1 +411 -0
- data/pkginfo +8 -0
- data/postinstall.solaris +11 -0
- data/postremove.solaris +16 -0
- data/schema/schema-1.0.5.yml +0 -0
- data/schema/schema-1.0.6.yml +0 -0
- data/schema/schema-1.0.7.yml +0 -0
- data/schema/schema-1.0.8.yml +0 -0
- data/schema/schema-1.0.9.yml +0 -0
- data/schema/schema.yml +0 -0
- data/schema/tpkg-1.0.0.dtd +0 -0
- data/schema/tpkg-1.0.1.dtd +0 -0
- data/schema/tpkg-1.0.2.dtd +0 -0
- data/schema/tpkg-1.0.3.dtd +0 -0
- data/schema/tpkg-1.0.4.dtd +0 -0
- data/schema/tpkg-1.0.5.dtd +0 -0
- data/schema/tpkg-1.0.6.dtd +0 -0
- data/schema/tpkg-1.0.7.dtd +0 -0
- data/schema/tpkg-1.0.8.dtd +0 -0
- data/schema/tpkg-1.0.9.dtd +0 -0
- data/schema/tpkg.dtd +0 -0
- data/test/TODO +30 -0
- data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
- data/test/test_checksum.rb +53 -0
- data/test/test_compress.rb +55 -0
- data/test/test_conflict.rb +41 -0
- data/test/test_crontabs.rb +398 -0
- data/test/test_dependency.rb +1113 -0
- data/test/test_downgrade.rb +80 -0
- data/test/test_download.rb +95 -0
- data/test/test_encrypt.rb +136 -0
- data/test/test_filemetadata.rb +131 -0
- data/test/test_initscript.rb +93 -0
- data/test/test_install.rb +186 -0
- data/test/test_lock.rb +82 -0
- data/test/test_make.rb +410 -0
- data/test/test_metadata.rb +805 -0
- data/test/test_misc.rb +379 -0
- data/test/test_options.rb +1711 -0
- data/test/test_os.rb +193 -0
- data/test/test_os_debian.rb +99 -0
- data/test/test_os_freebsd.rb +89 -0
- data/test/test_os_macosx.rb +79 -0
- data/test/test_os_redhat.rb +124 -0
- data/test/test_os_solaris.rb +85 -0
- data/test/test_os_windows.rb +26 -0
- data/test/test_query.rb +134 -0
- data/test/test_remove.rb +539 -0
- data/test/test_tar.rb +99 -0
- data/test/test_unpack.rb +977 -0
- data/test/test_upgrade.rb +398 -0
- data/test/test_version.rb +54 -0
- data/test/testcmds/crontab +14 -0
- data/test/testcmds/debian/apt-cache +145 -0
- data/test/testcmds/debian/dpkg-query +16 -0
- data/test/testcmds/freebsd/pkg_info +13 -0
- data/test/testcmds/macosx/port +35 -0
- data/test/testcmds/redhat/rpmbuild +6 -0
- data/test/testcmds/redhat/yum +90 -0
- data/test/testcmds/solaris/pkginfo +25 -0
- data/test/testcmds/solaris/pkgutil +36 -0
- data/test/testpkg/reloc/encfile +2 -0
- data/test/testpkg/reloc/file +2 -0
- data/test/testpkg/reloc/precryptfile +1 -0
- data/test/testpkg/reloc/precryptfile.plaintext +3 -0
- data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-default-perms.xml +28 -0
- data/test/testpkg/tpkg-default-perms.yml +20 -0
- data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-nativedeps.yml +13 -0
- data/test/testpkg/tpkg-nofiles.xml +14 -0
- data/test/testpkg/tpkg-nofiles.yml +9 -0
- data/test/testpkg/tpkg.xml +35 -0
- data/test/testpkg/tpkg.yml +25 -0
- data/test/tpkgtest.rb +300 -0
- data/tpkg.conf +16 -0
- data/tpkg.gemspec +24 -0
- data/tpkg.spec +28 -0
- data/tpkg.xml +17 -0
- data/tpkg_profile.sh +32 -0
- metadata +306 -31
data/test/test_misc.rb
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Tests for various methods that don't fit in anywhere else
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
|
6
|
+
require 'etc'
|
|
7
|
+
require 'webrick'
|
|
8
|
+
require 'webrick/https'
|
|
9
|
+
|
|
10
|
+
class TpkgMiscTests < Test::Unit::TestCase
|
|
11
|
+
include TpkgTests
|
|
12
|
+
|
|
13
|
+
def setup
|
|
14
|
+
Tpkg::set_prompt(false)
|
|
15
|
+
|
|
16
|
+
# Make up our regular test package
|
|
17
|
+
@pkgfile = make_package()
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_package_toplevel_directory
|
|
21
|
+
# Verify normal operation
|
|
22
|
+
assert_equal('testpkg-1.0-1-os-architecture', Tpkg::package_toplevel_directory(@pkgfile))
|
|
23
|
+
|
|
24
|
+
# Verify that it works on a package with top level directory with an
|
|
25
|
+
# unusually long name
|
|
26
|
+
longpkg = nil
|
|
27
|
+
longpkgname = ''
|
|
28
|
+
1.upto(240) do
|
|
29
|
+
longpkgname << 'a'
|
|
30
|
+
end
|
|
31
|
+
Dir.mktmpdir('workdir') do |workdir|
|
|
32
|
+
Dir.mktmpdir('longtoplevel') do |longtoplevel|
|
|
33
|
+
# It seems like most common filesystems limit filenames to 255
|
|
34
|
+
# characters. Anything over 100 characters should force tar to use one
|
|
35
|
+
# of the extended formats that needs more than 1 block.
|
|
36
|
+
# The top level directory will end up being pkgname-version so stop a
|
|
37
|
+
# few characters short of 255 to leave room for the version
|
|
38
|
+
File.open(File.join(longtoplevel, 'tpkg.yml'), 'w') do |tpkgyml|
|
|
39
|
+
yaml = <<YAML
|
|
40
|
+
name: #{longpkgname}
|
|
41
|
+
version: 1
|
|
42
|
+
maintainer: me
|
|
43
|
+
description: me@example.com
|
|
44
|
+
YAML
|
|
45
|
+
tpkgyml.write(yaml)
|
|
46
|
+
end
|
|
47
|
+
longpkg = Tpkg.make_package(longtoplevel, nil, :out => workdir)
|
|
48
|
+
end
|
|
49
|
+
assert_equal("#{longpkgname}-1", Tpkg::package_toplevel_directory(longpkg))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Verify that it fails in the expected way on something that isn't a tarball
|
|
53
|
+
boguspkg = Tempfile.new('boguspkg')
|
|
54
|
+
boguspkg.puts('xxxxxx')
|
|
55
|
+
boguspkg.close
|
|
56
|
+
assert_raise(RuntimeError) { Tpkg::verify_package_checksum(boguspkg.path) }
|
|
57
|
+
begin
|
|
58
|
+
Tpkg::verify_package_checksum(boguspkg.path)
|
|
59
|
+
rescue RuntimeError => e
|
|
60
|
+
assert_match(/Error reading top level directory/, e.message)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Verify that it fails on a bogus package due to the unexpected
|
|
64
|
+
# directory structure
|
|
65
|
+
boguspkg = Tempfile.new('tpkgtest')
|
|
66
|
+
Dir.mktmpdir('bogusdir') do |bogusdir|
|
|
67
|
+
Dir.mkdir(File.join(bogusdir, 'bogus'))
|
|
68
|
+
system("#{Tpkg::find_tar} -cf #{boguspkg.path} #{File.join(bogusdir, 'bogus')}")
|
|
69
|
+
end
|
|
70
|
+
assert_raise(RuntimeError) { Tpkg::package_toplevel_directory(boguspkg.path) }
|
|
71
|
+
begin
|
|
72
|
+
Tpkg::verify_package_checksum(boguspkg.path)
|
|
73
|
+
rescue RuntimeError => e
|
|
74
|
+
assert_match(/top level is more than one directory deep/, e.message)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_source_to_local_directory
|
|
79
|
+
Dir.mktmpdir('testbase') do |testbase|
|
|
80
|
+
tpkg = Tpkg.new(:base => testbase)
|
|
81
|
+
|
|
82
|
+
srca = 'http://example.com/pkgs'
|
|
83
|
+
srca_as_ld = tpkg.source_to_local_directory(srca)
|
|
84
|
+
|
|
85
|
+
srcb = 'http://www.example.com/pkgs'
|
|
86
|
+
srcb_as_ld = tpkg.source_to_local_directory(srcb)
|
|
87
|
+
|
|
88
|
+
assert_match(/^http/, File.basename(srca_as_ld))
|
|
89
|
+
assert_match(/^http/, File.basename(srcb_as_ld))
|
|
90
|
+
assert_no_match(/[^a-zA-Z0-9]/, File.basename(srca_as_ld))
|
|
91
|
+
assert_no_match(/[^a-zA-Z0-9]/, File.basename(srcb_as_ld))
|
|
92
|
+
assert_not_equal(srca_as_ld, srcb_as_ld)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_gethttp
|
|
97
|
+
Dir.mktmpdir('serverdir') do |serverdir|
|
|
98
|
+
http_server = WEBrick::HTTPServer.new(:Port => 3500, :DocumentRoot => serverdir)
|
|
99
|
+
https_server = WEBrick::HTTPServer.new(
|
|
100
|
+
:Port => 3501,
|
|
101
|
+
:DocumentRoot => serverdir,
|
|
102
|
+
:SSLEnable => true,
|
|
103
|
+
:SSLVerifyClient => ::OpenSSL::SSL::VERIFY_NONE,
|
|
104
|
+
:SSLCertName => [ ["CN", "localhost"] ]
|
|
105
|
+
)
|
|
106
|
+
# There may be an easier way to push WEBrick into the background, but
|
|
107
|
+
# the WEBrick docs are mostly non-existent so I'm taking the quick and
|
|
108
|
+
# dirty route.
|
|
109
|
+
t1 = Thread.new { http_server.start }
|
|
110
|
+
t2 = Thread.new { https_server.start }
|
|
111
|
+
|
|
112
|
+
# This is necessary to ensure that any SSL configuration in /etc/tpkg
|
|
113
|
+
# doesn't throw us off
|
|
114
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
115
|
+
tpkg = Tpkg.new(:file_system_root => testroot)
|
|
116
|
+
assert_kind_of(Net::HTTP, tpkg.gethttp(URI.parse('http://localhost:3500/pkgs')))
|
|
117
|
+
assert_kind_of(Net::HTTP, tpkg.gethttp(URI.parse('https://localhost:3501/pkgs')))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
http_server.shutdown
|
|
121
|
+
t1.kill
|
|
122
|
+
https_server.shutdown
|
|
123
|
+
t2.kill
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_lookup_uid
|
|
128
|
+
assert_equal(0, Tpkg::lookup_uid('0'))
|
|
129
|
+
assert_equal(Process.uid, Tpkg::lookup_uid(Etc.getlogin))
|
|
130
|
+
# Should return 0 if it can't find the specified user
|
|
131
|
+
assert_equal(0, Tpkg::lookup_uid('bogususer'))
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_lookup_gid
|
|
135
|
+
assert_equal(0, Tpkg::lookup_gid('0'))
|
|
136
|
+
assert_equal(Process.gid, Tpkg::lookup_gid(Etc.getgrgid(Process.gid).name))
|
|
137
|
+
# Should return 0 if it can't find the specified group
|
|
138
|
+
assert_equal(0, Tpkg::lookup_gid('bogusgroup'))
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_clean_for_filename
|
|
142
|
+
assert_equal('redhat5', Metadata.clean_for_filename('RedHat-5'))
|
|
143
|
+
assert_equal('i386', Metadata.clean_for_filename('i386'))
|
|
144
|
+
assert_equal('x86_64', Metadata.clean_for_filename('x86_64'))
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def test_normalize_paths
|
|
148
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
149
|
+
FileUtils.mkdir_p(File.join(testroot, 'home', 'tpkg'))
|
|
150
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'))
|
|
151
|
+
files = Tpkg::files_in_package(@pkgfile)
|
|
152
|
+
tpkg.normalize_paths(files)
|
|
153
|
+
assert_equal(files[:root].length + files[:reloc].length, files[:normalized].length)
|
|
154
|
+
assert(files[:normalized].include?(File.join(testroot, 'home', 'tpkg', 'file')))
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_conflicting_files
|
|
159
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
160
|
+
tpkg = Tpkg.new(:file_system_root => testroot)
|
|
161
|
+
|
|
162
|
+
pkg1 = make_package(:change => { 'version' => '2.0' }, :remove => ['operatingsystem', 'architecture'], :output_directory => File.join(testroot, 'tmp'))
|
|
163
|
+
pkg2 = make_package(:change => { 'version' => '3.0' }, :remove => ['operatingsystem', 'architecture'], :output_directory => File.join(testroot, 'tmp'))
|
|
164
|
+
# The check for conflicting files shouldn't complain when nothing
|
|
165
|
+
# else is installed
|
|
166
|
+
conflicts = tpkg.conflicting_files(pkg1)
|
|
167
|
+
assert(conflicts.empty?)
|
|
168
|
+
tpkg.install([pkg1])
|
|
169
|
+
# The test package has a few files in it. Since we made two copies of
|
|
170
|
+
# that package the second one should fail the conflict test
|
|
171
|
+
conflicts = tpkg.conflicting_files(pkg2)
|
|
172
|
+
assert(!conflicts.empty?)
|
|
173
|
+
FileUtils.rm_f(pkg1)
|
|
174
|
+
FileUtils.rm_f(pkg2)
|
|
175
|
+
|
|
176
|
+
# Make a package with non-relocatable files that end up in the same
|
|
177
|
+
# place as relocatable files in an installed package. That should
|
|
178
|
+
# also raise an error.
|
|
179
|
+
rootpkg = nil
|
|
180
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
|
181
|
+
FileUtils.mkdir_p(File.join(srcdir, 'root', Tpkg::DEFAULT_BASE))
|
|
182
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
|
183
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'reloc', 'file'), File.join(srcdir, 'root', Tpkg::DEFAULT_BASE))
|
|
184
|
+
rootpkg = make_package(:change => { 'version' => '4.0' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'], :output_directory => File.join(testroot, 'tmp'))
|
|
185
|
+
end
|
|
186
|
+
conflicts = tpkg.conflicting_files(rootpkg)
|
|
187
|
+
assert(!conflicts.empty?)
|
|
188
|
+
FileUtils.rm_f(rootpkg)
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_predict_file_permissions_and_ownership
|
|
193
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
194
|
+
tpkg = Tpkg.new(:file_system_root => testroot)
|
|
195
|
+
|
|
196
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
|
197
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
|
198
|
+
testfile = "#{srcdir}/reloc/myfile"
|
|
199
|
+
FileUtils.mkdir_p(File.dirname(testfile))
|
|
200
|
+
File.open(testfile, 'w') {|f| }
|
|
201
|
+
File.chmod(0623, testfile)
|
|
202
|
+
|
|
203
|
+
# No file_defaults settings, no file posix defined, then the current
|
|
204
|
+
# perms of the file and default ownership settings are used
|
|
205
|
+
data = {:actual_file => testfile}
|
|
206
|
+
predicted_perms, predicted_uid, predicted_gid = Tpkg::predict_file_perms_and_ownership(data)
|
|
207
|
+
assert_equal(File.stat(testfile).mode, predicted_perms)
|
|
208
|
+
assert_equal(Tpkg::DEFAULT_OWNERSHIP_UID, predicted_uid)
|
|
209
|
+
assert_equal(Tpkg::DEFAULT_OWNERSHIP_GID, predicted_gid)
|
|
210
|
+
|
|
211
|
+
# If metadata has file_defaults settings but not specific permissions
|
|
212
|
+
# for the individual file then that is used
|
|
213
|
+
pkgfile = make_package(
|
|
214
|
+
:source_directory => srcdir,
|
|
215
|
+
:file_defaults => {
|
|
216
|
+
'perms' => '0654',
|
|
217
|
+
'owner' => 'nobody',
|
|
218
|
+
'group' => 'nogroup',
|
|
219
|
+
},
|
|
220
|
+
:output_directory => "#{testroot}/tmp")
|
|
221
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
|
222
|
+
data = {:actual_file => testfile, :metadata => metadata}
|
|
223
|
+
predicted_perms, predicted_uid, predicted_gid = Tpkg::predict_file_perms_and_ownership(data)
|
|
224
|
+
assert_equal(0654, predicted_perms)
|
|
225
|
+
assert_equal(Tpkg::lookup_uid('nobody'), predicted_uid)
|
|
226
|
+
assert_equal(Tpkg::lookup_gid('nogroup'), predicted_gid)
|
|
227
|
+
FileUtils.rm_f(pkgfile)
|
|
228
|
+
|
|
229
|
+
# If metadata has the file perms & ownership explicitly defined, then
|
|
230
|
+
# that overrides everything
|
|
231
|
+
pkgfile = make_package(
|
|
232
|
+
:source_directory => srcdir,
|
|
233
|
+
:file_defaults => {
|
|
234
|
+
'perms' => '0654',
|
|
235
|
+
'owner' => 'nobody',
|
|
236
|
+
'group' => 'nogroup',
|
|
237
|
+
},
|
|
238
|
+
:files => {
|
|
239
|
+
'myfile' => {
|
|
240
|
+
'perms' => '0733',
|
|
241
|
+
'owner' => 'root',
|
|
242
|
+
'group' => 'wheel',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
246
|
+
metadata = Tpkg::metadata_from_package(pkgfile)
|
|
247
|
+
file_metadata = {
|
|
248
|
+
:posix => {
|
|
249
|
+
:perms => 0733,
|
|
250
|
+
:owner => 'root',
|
|
251
|
+
:group => 'wheel',
|
|
252
|
+
},
|
|
253
|
+
}
|
|
254
|
+
data = {:actual_file => testfile, :metadata => metadata, :file_metadata => file_metadata}
|
|
255
|
+
predicted_perms, predicted_uid, predicted_gid = Tpkg::predict_file_perms_and_ownership(data)
|
|
256
|
+
assert_equal(0733, predicted_perms)
|
|
257
|
+
assert_equal(Tpkg::lookup_uid('root'), predicted_uid)
|
|
258
|
+
assert_equal(Tpkg::lookup_gid('wheel'), predicted_gid)
|
|
259
|
+
FileUtils.rm_f(pkgfile)
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def test_prompt_for_conflicting_files
|
|
265
|
+
# FIXME: Not quite sure how to test this method
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def test_prompt_for_install
|
|
269
|
+
# FIXME: Not quite sure how to test this method
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def test_valid_pkg_filename
|
|
273
|
+
# we currently accepts all string for filename as long as it
|
|
274
|
+
# doesn't begin with a dot
|
|
275
|
+
valid_filenames = ['a.tpkg', 'pkg_with_no_extension', '_valid_pkg', './path/to/package.tpkg']
|
|
276
|
+
invalid_filenames = ['.invalid_pkg', '..invalid_pkg']
|
|
277
|
+
|
|
278
|
+
valid_filenames.each do |filename|
|
|
279
|
+
assert(Tpkg::valid_pkg_filename?(filename))
|
|
280
|
+
end
|
|
281
|
+
invalid_filenames.each do |filename|
|
|
282
|
+
assert(!Tpkg::valid_pkg_filename?(filename))
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def test_run_external
|
|
287
|
+
extname = 'testext'
|
|
288
|
+
extdata = "This is a test of an external hook\nwith multiple lines\nof data"
|
|
289
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
290
|
+
relative_base = File.join('home', 'tpkg')
|
|
291
|
+
testbase = File.join(testroot, relative_base)
|
|
292
|
+
FileUtils.mkdir_p(testbase)
|
|
293
|
+
# Make an external script which writes the arguments and data it receives
|
|
294
|
+
# to a temporary file, so that we can verify the external script received
|
|
295
|
+
# them properly.
|
|
296
|
+
exttmpfile = Tempfile.new('tpkgtest_external')
|
|
297
|
+
externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
|
|
298
|
+
FileUtils.mkdir_p(externalsdir)
|
|
299
|
+
extscript = File.join(externalsdir, extname)
|
|
300
|
+
File.open(extscript, 'w') do |file|
|
|
301
|
+
file.puts('#!/bin/sh')
|
|
302
|
+
# Package filename
|
|
303
|
+
file.puts("echo $1 > #{exttmpfile.path}")
|
|
304
|
+
# Operation (install/remove)
|
|
305
|
+
file.puts("echo $2 >> #{exttmpfile.path}")
|
|
306
|
+
# TPKG_HOME environment variable
|
|
307
|
+
file.puts("echo $TPKG_HOME >> #{exttmpfile.path}")
|
|
308
|
+
# Data
|
|
309
|
+
file.puts("cat >> #{exttmpfile.path}")
|
|
310
|
+
end
|
|
311
|
+
File.chmod(0755, extscript)
|
|
312
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => relative_base)
|
|
313
|
+
tpkg_force = Tpkg.new(:file_system_root => testroot, :base => relative_base, :force => true)
|
|
314
|
+
|
|
315
|
+
# Test install
|
|
316
|
+
assert_nothing_raised { tpkg.run_external('pkgfile', :install, extname, extdata) }
|
|
317
|
+
assert_equal("pkgfile\ninstall\n#{testbase}\n#{extdata}", IO.read(exttmpfile.path))
|
|
318
|
+
# Test remove
|
|
319
|
+
assert_nothing_raised { tpkg.run_external('pkgfile', :remove, extname, extdata) }
|
|
320
|
+
assert_equal("pkgfile\nremove\n#{testbase}\n#{extdata}", IO.read(exttmpfile.path))
|
|
321
|
+
|
|
322
|
+
# A non-existent external raises an exception
|
|
323
|
+
File.delete(extscript)
|
|
324
|
+
assert_raise(RuntimeError) { tpkg.run_external('pkgfile', :install, extname, extdata) }
|
|
325
|
+
# Unless forced
|
|
326
|
+
assert_nothing_raised { tpkg_force.run_external('pkgfile', :install, extname, extdata) }
|
|
327
|
+
|
|
328
|
+
# A non-executable external raises an exception
|
|
329
|
+
File.open(extscript, 'w') do |file|
|
|
330
|
+
file.puts('#!/bin/sh')
|
|
331
|
+
file.puts("exit 0")
|
|
332
|
+
end
|
|
333
|
+
File.chmod(0644, extscript)
|
|
334
|
+
assert_raise(RuntimeError) { tpkg.run_external('pkgfile', :install, extname, extdata) }
|
|
335
|
+
# Unless forced
|
|
336
|
+
assert_nothing_raised { tpkg_force.run_external('pkgfile', :install, extname, extdata) }
|
|
337
|
+
|
|
338
|
+
# An external that exits non-zero should raise an exception
|
|
339
|
+
File.open(extscript, 'w') do |file|
|
|
340
|
+
file.puts('#!/bin/sh')
|
|
341
|
+
# Avoid generating SIGPIPE in tpkg
|
|
342
|
+
file.puts('cat > /dev/null')
|
|
343
|
+
file.puts("exit 1")
|
|
344
|
+
end
|
|
345
|
+
File.chmod(0755, extscript)
|
|
346
|
+
assert_raise(RuntimeError) { tpkg.run_external('pkgfile', :install, extname, extdata) }
|
|
347
|
+
# Unless forced
|
|
348
|
+
assert_nothing_raised { tpkg_force.run_external('pkgfile', :install, extname, extdata) }
|
|
349
|
+
|
|
350
|
+
# An invalid operation should raise an exception
|
|
351
|
+
assert_raise(RuntimeError) { tpkg.run_external('pkgfile', :bogus, extname, extdata) }
|
|
352
|
+
# The externals operation to perform is determined within tpkg. If an
|
|
353
|
+
# invalid operation is specified that's a significant tpkg bug, not
|
|
354
|
+
# something we have any reason to expect a user to see and thus no
|
|
355
|
+
# reason to allow a force to override raising that exception.
|
|
356
|
+
|
|
357
|
+
# An invalid external name should raise an exception
|
|
358
|
+
assert_raise(RuntimeError) { tpkg.run_external('pkgfile', :install, 'bogus', extdata) }
|
|
359
|
+
# Unless forced
|
|
360
|
+
assert_nothing_raised { tpkg_force.run_external('pkgfile', :install, 'bogus', extdata) }
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
def test_wrap_exception
|
|
365
|
+
original_message = 'original message'
|
|
366
|
+
original_backtrace = ['a', 'b']
|
|
367
|
+
e = StandardError.new(original_message)
|
|
368
|
+
e.set_backtrace(original_backtrace)
|
|
369
|
+
new_message = 'new message'
|
|
370
|
+
eprime = Tpkg.wrap_exception(e, new_message)
|
|
371
|
+
assert_equal(StandardError, eprime.class)
|
|
372
|
+
assert_equal(new_message, eprime.message)
|
|
373
|
+
assert_equal(original_backtrace, eprime.backtrace)
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
def teardown
|
|
377
|
+
FileUtils.rm_f(@pkgfile)
|
|
378
|
+
end
|
|
379
|
+
end
|
|
@@ -0,0 +1,1711 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Test tpkg command line options
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'open4'
|
|
8
|
+
require 'rbconfig'
|
|
9
|
+
|
|
10
|
+
RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) +
|
|
11
|
+
RbConfig::CONFIG["EXEEXT"]
|
|
12
|
+
TPKG_EXECUTABLE = File.expand_path('../bin/tpkg', File.dirname(__FILE__))
|
|
13
|
+
|
|
14
|
+
class TpkgOptionTests < Test::Unit::TestCase
|
|
15
|
+
include TpkgTests
|
|
16
|
+
|
|
17
|
+
def setup
|
|
18
|
+
Tpkg::set_prompt(false)
|
|
19
|
+
@testroot = Dir.mktmpdir('testroot')
|
|
20
|
+
@tpkg = Tpkg.new(:file_system_root => @testroot)
|
|
21
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
22
|
+
ENV.delete('TPKG_HOME')
|
|
23
|
+
# Make up our regular test package
|
|
24
|
+
@pkgfile = make_package(:remove => ['operatingsystem', 'architecture'])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_help
|
|
28
|
+
output = nil
|
|
29
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
30
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
31
|
+
IO.popen("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --help") do |pipe|
|
|
32
|
+
output = pipe.readlines
|
|
33
|
+
end
|
|
34
|
+
# Make sure at least something resembling help output is there
|
|
35
|
+
assert(output.any? {|line| line.include?('Usage: tpkg')}, 'help output content')
|
|
36
|
+
# Make sure it fits on the screen
|
|
37
|
+
assert(output.all? {|line| line.length <= 80}, 'help output columns')
|
|
38
|
+
# Too many options for 23 lines
|
|
39
|
+
#assert(output.size <= 23, 'help output lines')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# --query/-q
|
|
43
|
+
def test_query
|
|
44
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
45
|
+
|
|
46
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
47
|
+
# Query with no package installed
|
|
48
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
49
|
+
['-q', '--query'].each do |switch|
|
|
50
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} #{switch} #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
51
|
+
stdin.close
|
|
52
|
+
assert_equal(
|
|
53
|
+
"", stdout.read, "#{switch} #{query}, not installed, stdout")
|
|
54
|
+
assert_equal(
|
|
55
|
+
"No packages matching '#{query}' installed\n", stderr.read,
|
|
56
|
+
"#{switch} #{query}, not installed, stderr")
|
|
57
|
+
end
|
|
58
|
+
assert_equal(1, status.exitstatus, "#{switch} #{query}, not installed, exitstatus")
|
|
59
|
+
# Same query with --quiet should be quiet
|
|
60
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} #{switch} #{query} --quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
61
|
+
stdin.close
|
|
62
|
+
assert_equal("", stdout.read, "#{switch} #{query} --quiet, not installed, stdout")
|
|
63
|
+
assert_equal("", stderr.read, "#{switch} #{query} --quiet, not installed, stderr")
|
|
64
|
+
end
|
|
65
|
+
assert_equal(1, status.exitstatus, "#{switch} #{query} --quiet, not installed, exitstatus")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
pkgfile2 = make_package(:change => {'name' => 'querypkg'},
|
|
70
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
71
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
72
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
73
|
+
|
|
74
|
+
# Install packages and try again
|
|
75
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :sources => [@pkgfile, pkgfile2])
|
|
76
|
+
tpkg.install([@pkgfile, pkgfile2], PASSPHRASE)
|
|
77
|
+
|
|
78
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
79
|
+
ENV.delete('TPKG_HOME')
|
|
80
|
+
|
|
81
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
82
|
+
['-q', '--query'].each do |switch|
|
|
83
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} #{switch} #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
84
|
+
stdin.close
|
|
85
|
+
assert_equal("#{File.basename(@pkgfile)}\n", stdout.read, "#{switch} #{query}, installed, stdout")
|
|
86
|
+
assert_equal("", stderr.read, "#{switch} #{query}, installed, stderr")
|
|
87
|
+
end
|
|
88
|
+
assert_equal(0, status.exitstatus, "#{switch} #{query}, installed, exitstatus")
|
|
89
|
+
# Same query with --quiet should be quiet
|
|
90
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} #{switch} #{query} --quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
91
|
+
stdin.close
|
|
92
|
+
assert_equal('', stdout.read, "#{switch} #{query} --quiet, installed, stdout")
|
|
93
|
+
assert_equal('', stderr.read, "#{switch} #{query} --quiet, installed, stderr")
|
|
94
|
+
end
|
|
95
|
+
assert_equal(0, status.exitstatus, "#{switch} #{query} --quiet, installed, exitstatus")
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
# --query allows multiple arguments, test that functionality
|
|
99
|
+
["#{File.basename(@pkgfile)},#{File.basename(pkgfile2)}", "#{metadata2[:name]},#{metadata[:name]}"].each do |query|
|
|
100
|
+
['-q', '--query'].each do |switch|
|
|
101
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} #{switch} #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
102
|
+
stdin.close
|
|
103
|
+
assert_equal(
|
|
104
|
+
# Output will be sorted
|
|
105
|
+
"#{File.basename(pkgfile2)}\n#{File.basename(@pkgfile)}\n",
|
|
106
|
+
stdout.read, "#{switch} #{query}, installed, stdout")
|
|
107
|
+
assert_equal(
|
|
108
|
+
"", stderr.read, "#{switch} #{query}, installed, stderr")
|
|
109
|
+
end
|
|
110
|
+
assert_equal(0, status.exitstatus, "#{switch} #{query}, installed, exitstatus")
|
|
111
|
+
# Same query with --quiet should be quiet
|
|
112
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} #{switch} #{query} --quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
113
|
+
stdin.close
|
|
114
|
+
assert_equal('', stdout.read, "#{switch} #{query} --quiet, installed, stdout")
|
|
115
|
+
assert_equal('', stderr.read, "#{switch} #{query} --quiet, installed, stderr")
|
|
116
|
+
end
|
|
117
|
+
assert_equal(0, status.exitstatus, "#{switch} #{query} --quiet, installed, exitstatus")
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
def test_qa
|
|
123
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
124
|
+
# Query with no package installed
|
|
125
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qa --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
126
|
+
stdin.close
|
|
127
|
+
assert_equal("", stdout.read, "--qa, not installed, stdout")
|
|
128
|
+
assert_equal("No packages installed\n", stderr.read, "--qa, not installed, stderr")
|
|
129
|
+
end
|
|
130
|
+
assert_equal(1, status.exitstatus)
|
|
131
|
+
|
|
132
|
+
# Make up a few more packages to install so we give --qa a fair test.
|
|
133
|
+
# Use names that will allow us to make sure the package names are output
|
|
134
|
+
# in sorted order.
|
|
135
|
+
pkgfile2 = make_package(:change => {'name' => 'aqapkg'},
|
|
136
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
137
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
138
|
+
pkgfile3 = make_package(:change => {'name' => 'zqapkg'},
|
|
139
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
140
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
141
|
+
|
|
142
|
+
# Install packages and try again
|
|
143
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :sources => [@pkgfile, pkgfile2, pkgfile3])
|
|
144
|
+
tpkg.install([@pkgfile, pkgfile2, pkgfile3], PASSPHRASE)
|
|
145
|
+
|
|
146
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
147
|
+
ENV.delete('TPKG_HOME')
|
|
148
|
+
|
|
149
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qa --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
150
|
+
stdin.close
|
|
151
|
+
pkgshortnames = [pkgfile2, @pkgfile, pkgfile3].collect {|pkg| File.basename(pkg)}
|
|
152
|
+
assert_equal(pkgshortnames.join("\n")+"\n", stdout.read, "--qa, installed, stdout")
|
|
153
|
+
assert_equal('', stderr.read, "--qa, installed, stderr")
|
|
154
|
+
end
|
|
155
|
+
assert_equal(0, status.exitstatus)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
def test_qi
|
|
159
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
160
|
+
|
|
161
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
162
|
+
# Query with no package installed
|
|
163
|
+
# Queries for installed packages should return nothing
|
|
164
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
165
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qi #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
166
|
+
stdin.close
|
|
167
|
+
assert_equal(
|
|
168
|
+
"", stdout.read, "--qi #{query}, not installed, stdout")
|
|
169
|
+
assert_equal("No packages matching '#{query}' installed\n",
|
|
170
|
+
stderr.read, "--qi #{query}, not installed, stderr")
|
|
171
|
+
end
|
|
172
|
+
assert_equal(1, status.exitstatus, "--qi #{query}, not installed, exitstatus")
|
|
173
|
+
end
|
|
174
|
+
# But querying a package file should work
|
|
175
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qi #{@pkgfile} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
176
|
+
stdin.close
|
|
177
|
+
output = stdout.read
|
|
178
|
+
[:name, :version, :package_version, :maintainer, :description, :bugreporting].each do |field|
|
|
179
|
+
assert_match(
|
|
180
|
+
/^#{field}: #{metadata[field]}$/,
|
|
181
|
+
output, "--qi #{@pkgfile}, #{field}, not installed, stdout")
|
|
182
|
+
end
|
|
183
|
+
[:operatingsystem, :architecture].each do |field|
|
|
184
|
+
assert_match(
|
|
185
|
+
/^#{field}: any$/,
|
|
186
|
+
output, "--qi #{@pkgfile}, #{field}, not installed, stdout")
|
|
187
|
+
end
|
|
188
|
+
assert_equal("", stderr.read, "--qi #{@pkgfile}, not installed, stderr")
|
|
189
|
+
end
|
|
190
|
+
assert_equal(0, status.exitstatus, "--qi #{@pkgfile}, not installed, exitstatus")
|
|
191
|
+
|
|
192
|
+
# Make up more packages to install so we give --qi a fair test.
|
|
193
|
+
pkgfile2 = make_package(
|
|
194
|
+
:change => {
|
|
195
|
+
'name' => 'qipkg',
|
|
196
|
+
# Note spaces between commas here for just a bit of extra testing.
|
|
197
|
+
# See below when we match this out of the --qi output for further
|
|
198
|
+
# explanation
|
|
199
|
+
'operatingsystem' => "RedHat, CentOS, #{@tpkg.os.os}, FreeBSD, Solaris",
|
|
200
|
+
'architecture' => Facter['hardwaremodel'].value},
|
|
201
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
202
|
+
pkgfile3 = make_package(
|
|
203
|
+
:change => {'name' => 'qidepspkg'},
|
|
204
|
+
:dependencies => {'qipkg' => {}},
|
|
205
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
206
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
207
|
+
|
|
208
|
+
# FIXME: test when multiple versions of same package are installed
|
|
209
|
+
|
|
210
|
+
# Install packages and try again
|
|
211
|
+
tpkg = Tpkg.new(
|
|
212
|
+
:file_system_root => testroot,
|
|
213
|
+
:sources => [@pkgfile, pkgfile2, pkgfile3])
|
|
214
|
+
tpkg.install([@pkgfile, pkgfile2, pkgfile3], PASSPHRASE)
|
|
215
|
+
|
|
216
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
217
|
+
ENV.delete('TPKG_HOME')
|
|
218
|
+
|
|
219
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
220
|
+
|
|
221
|
+
{@pkgfile => metadata, pkgfile2 => metadata2}.each do |pfile, mdata|
|
|
222
|
+
[File.basename(pfile), mdata[:name]].each do |query|
|
|
223
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qi #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
224
|
+
stdin.close
|
|
225
|
+
output = stdout.read
|
|
226
|
+
[:name, :version, :package_version, :maintainer, :description, :bugreporting].each do |field|
|
|
227
|
+
assert_match(/^#{field}: #{mdata[field]}$/, output, "--qi #{query}, #{field}, installed")
|
|
228
|
+
end
|
|
229
|
+
if mdata[:name] == metadata[:name]
|
|
230
|
+
assert_match(/^operatingsystem: any$/, output,
|
|
231
|
+
"--qi #{query}, operatingsystem, installed")
|
|
232
|
+
assert_match(/^architecture: any$/, output,
|
|
233
|
+
"--qi #{query}, architecture, installed")
|
|
234
|
+
else # qipkg
|
|
235
|
+
# Note that there are no spaces between the commas here, even
|
|
236
|
+
# though we used spaces between the commas when creating the
|
|
237
|
+
# package. tpkg splits on commas into an array when parsing the
|
|
238
|
+
# metadata, and the tpkg executable joins the array members back
|
|
239
|
+
# together with a comma but no spaces when displaying --qi
|
|
240
|
+
assert_match(/^operatingsystem: RedHat,CentOS,#{@tpkg.os.os},FreeBSD,Solaris$/,
|
|
241
|
+
output, "--qi #{query}, operatingsystem, installed")
|
|
242
|
+
assert_match(/^architecture: #{Facter['hardwaremodel'].value}$/,
|
|
243
|
+
output, "--qi #{query}, architecture, installed")
|
|
244
|
+
end
|
|
245
|
+
assert_no_match(/This package depends on other packages/,
|
|
246
|
+
output, '--qi package without dependencies')
|
|
247
|
+
assert_equal("", stderr.read, "--qi package without dependencies, stderr")
|
|
248
|
+
end
|
|
249
|
+
assert_equal(0, status.exitstatus, "--qi #{query}, installed, exitstatus")
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qi #{File.basename(pkgfile3)} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
253
|
+
stdin.close
|
|
254
|
+
assert_match(/This package depends on other packages/,
|
|
255
|
+
stdout.read, '--qi package with dependencies')
|
|
256
|
+
assert_equal("", stderr.read, "--qi package with dependencies, stderr")
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
def test_qis
|
|
261
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
262
|
+
|
|
263
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
264
|
+
# Make up more packages to install so we give --qis a fair test.
|
|
265
|
+
pkgfile2 = make_package(
|
|
266
|
+
:change => {
|
|
267
|
+
'name' => 'qispkg',
|
|
268
|
+
# Note spaces between commas here for just a bit of extra testing.
|
|
269
|
+
# See below when we match this out of the --qis output for further
|
|
270
|
+
# explanation
|
|
271
|
+
'operatingsystem' => "RedHat, CentOS, #{@tpkg.os.os}, FreeBSD, Solaris",
|
|
272
|
+
'architecture' => Facter['hardwaremodel'].value},
|
|
273
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
274
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
275
|
+
pkgfile3 = make_package(
|
|
276
|
+
:change => {'name' => 'qisdepspkg'},
|
|
277
|
+
:dependencies => {'qispkg' => {}},
|
|
278
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
279
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
280
|
+
metadata3 = Tpkg::metadata_from_package(pkgfile3)
|
|
281
|
+
|
|
282
|
+
# Query a package that is not available, should get nothing
|
|
283
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
284
|
+
status = Open4.popen4(
|
|
285
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qis #{query} " +
|
|
286
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
287
|
+
stdin.close
|
|
288
|
+
assert_equal(
|
|
289
|
+
"", stdout.read,
|
|
290
|
+
"--qis #{query}, not available or installed, stdout")
|
|
291
|
+
assert_equal(
|
|
292
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
293
|
+
"--qis #{query}, not available or installed, stderr")
|
|
294
|
+
end
|
|
295
|
+
assert_equal(
|
|
296
|
+
1, status.exitstatus,
|
|
297
|
+
"--qis #{query}, not available or installed, exitstatus")
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
# Query packages that are available but not installed, should get data
|
|
301
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
302
|
+
status = Open4.popen4(
|
|
303
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qis #{query} " +
|
|
304
|
+
"--source #{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
305
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
306
|
+
stdin.close
|
|
307
|
+
output = stdout.read
|
|
308
|
+
[:name, :version, :package_version,
|
|
309
|
+
:maintainer, :description, :bugreporting].each do |field|
|
|
310
|
+
assert_match(
|
|
311
|
+
/^#{field}: #{metadata[field]}$/, output,
|
|
312
|
+
"--qis #{query}, #{field}, available, not installed, stdout")
|
|
313
|
+
end
|
|
314
|
+
[:operatingsystem, :architecture].each do |field|
|
|
315
|
+
assert_match(
|
|
316
|
+
/^#{field}: any$/, output,
|
|
317
|
+
"--qis #{query}, #{field}, available, not installed, stdout")
|
|
318
|
+
end
|
|
319
|
+
assert_equal(
|
|
320
|
+
"", stderr.read,
|
|
321
|
+
"--qis #{query}, available, not installed, stderr")
|
|
322
|
+
end
|
|
323
|
+
assert_equal(
|
|
324
|
+
0, status.exitstatus,
|
|
325
|
+
"--qis #{query}, available, not installed, exitstatus")
|
|
326
|
+
end
|
|
327
|
+
{@pkgfile => metadata, pkgfile2 => metadata2}.each do |pfile, mdata|
|
|
328
|
+
[File.basename(pfile), mdata[:name]].each do |query|
|
|
329
|
+
status = Open4.popen4(
|
|
330
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qis #{query} " +
|
|
331
|
+
"--source #{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
332
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
333
|
+
stdin.close
|
|
334
|
+
output = stdout.read
|
|
335
|
+
[:name, :version, :package_version,
|
|
336
|
+
:maintainer, :description, :bugreporting].each do |field|
|
|
337
|
+
assert_match(
|
|
338
|
+
/^#{field}: #{mdata[field]}$/, output,
|
|
339
|
+
"--qis #{query}, #{field}, available, not installed")
|
|
340
|
+
end
|
|
341
|
+
if mdata[:name] == metadata[:name]
|
|
342
|
+
assert_match(/^operatingsystem: any$/, output,
|
|
343
|
+
"--qis #{query}, operatingsystem, available, not installed")
|
|
344
|
+
assert_match(/^architecture: any$/, output,
|
|
345
|
+
"--qis #{query}, architecture, available, not installed")
|
|
346
|
+
else # qispkg
|
|
347
|
+
# Note that there are no spaces between the commas here, even
|
|
348
|
+
# though we used spaces between the commas when creating the
|
|
349
|
+
# package. tpkg splits on commas into an array when parsing the
|
|
350
|
+
# metadata, and the tpkg executable joins the array members back
|
|
351
|
+
# together with a comma but no spaces when displaying --qi
|
|
352
|
+
assert_match(
|
|
353
|
+
/^operatingsystem: RedHat,CentOS,#{@tpkg.os.os},FreeBSD,Solaris$/,
|
|
354
|
+
output, "--qis #{query}, operatingsystem, installed")
|
|
355
|
+
assert_match(
|
|
356
|
+
/^architecture: #{Facter['hardwaremodel'].value}$/,
|
|
357
|
+
output, "--qis #{query}, architecture, installed")
|
|
358
|
+
end
|
|
359
|
+
assert_no_match(
|
|
360
|
+
/This package depends on other packages/, output,
|
|
361
|
+
'--qis package without dependencies')
|
|
362
|
+
assert_equal(
|
|
363
|
+
"", stderr.read,
|
|
364
|
+
"--qis package without dependencies, stderr")
|
|
365
|
+
end
|
|
366
|
+
assert_equal(
|
|
367
|
+
0, status.exitstatus,
|
|
368
|
+
"--qis #{query}, available, not installed, exitstatus")
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
status = Open4.popen4(
|
|
372
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qis #{File.basename(pkgfile3)} " +
|
|
373
|
+
"--source #{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
374
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
375
|
+
stdin.close
|
|
376
|
+
assert_match(
|
|
377
|
+
/This package depends on other packages/, stdout.read,
|
|
378
|
+
'--qis package with dependencies')
|
|
379
|
+
assert_equal(
|
|
380
|
+
"", stderr.read,
|
|
381
|
+
"--qis package with dependencies, stderr")
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
# Install packages and try again
|
|
385
|
+
tpkg = Tpkg.new(
|
|
386
|
+
:file_system_root => testroot,
|
|
387
|
+
:sources => [@pkgfile, pkgfile2, pkgfile3])
|
|
388
|
+
tpkg.install([@pkgfile, pkgfile2, pkgfile3], PASSPHRASE)
|
|
389
|
+
|
|
390
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg
|
|
391
|
+
# library
|
|
392
|
+
ENV.delete('TPKG_HOME')
|
|
393
|
+
|
|
394
|
+
# Query a package that is installed but not available, should get
|
|
395
|
+
# nothing
|
|
396
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
397
|
+
status = Open4.popen4(
|
|
398
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qis #{query} " +
|
|
399
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
400
|
+
stdin.close
|
|
401
|
+
assert_equal(
|
|
402
|
+
"", stdout.read,
|
|
403
|
+
"--qis #{query}, installed, not available, stdout")
|
|
404
|
+
assert_equal(
|
|
405
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
406
|
+
"--qis #{query}, installed, not available, stderr")
|
|
407
|
+
end
|
|
408
|
+
assert_equal(
|
|
409
|
+
1, status.exitstatus,
|
|
410
|
+
"--qis #{query}, installed, not available, exitstatus")
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
# Query a package that is installed and available, should get the data
|
|
414
|
+
# for the available package
|
|
415
|
+
# pkgfile2 and pkgfile4 have the same name but other differences
|
|
416
|
+
pkgfile4 = make_package(
|
|
417
|
+
:change => {
|
|
418
|
+
'name' => 'qispkg',
|
|
419
|
+
'version' => '42',
|
|
420
|
+
# Note spaces between commas here for just a bit of extra testing.
|
|
421
|
+
# See below when we match this out of the --qis output for further
|
|
422
|
+
# explanation
|
|
423
|
+
'operatingsystem' => "RedHat, CentOS, #{@tpkg.os.os}",
|
|
424
|
+
'architecture' => "#{Facter['hardwaremodel'].value}, bogusarch"},
|
|
425
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
426
|
+
metadata4 = Tpkg::metadata_from_package(pkgfile4)
|
|
427
|
+
[metadata2[:name]].each do |query|
|
|
428
|
+
status = Open4.popen4(
|
|
429
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qis #{query} " +
|
|
430
|
+
"--source #{[@pkgfile,pkgfile3,pkgfile4].join(',')} " +
|
|
431
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
432
|
+
stdin.close
|
|
433
|
+
output = stdout.read
|
|
434
|
+
assert_match(
|
|
435
|
+
/^version: #{metadata4['version']}$/, output,
|
|
436
|
+
"--qis #{query}, version, available and installed, stdout")
|
|
437
|
+
assert_match(
|
|
438
|
+
/^operatingsystem: RedHat,CentOS,#{@tpkg.os.os}$/,
|
|
439
|
+
output,
|
|
440
|
+
"--qis #{query}, operatingsystem, available and installed, stdout")
|
|
441
|
+
assert_match(
|
|
442
|
+
/^architecture: #{Facter['hardwaremodel'].value},bogusarch$/,
|
|
443
|
+
output,
|
|
444
|
+
"--qis #{query}, architecture, available and installed, stdout")
|
|
445
|
+
assert_equal(
|
|
446
|
+
"", stderr.read,
|
|
447
|
+
"--qis #{query}, available and installed, stderr")
|
|
448
|
+
end
|
|
449
|
+
assert_equal(
|
|
450
|
+
0, status.exitstatus,
|
|
451
|
+
"--qis #{query}, available and installed, exitstatus")
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
end
|
|
455
|
+
def test_ql
|
|
456
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
457
|
+
|
|
458
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
459
|
+
# Query with no package installed
|
|
460
|
+
# Queries for installed packages should return nothing
|
|
461
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
462
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --ql #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
463
|
+
stdin.close
|
|
464
|
+
assert_equal(
|
|
465
|
+
"", stdout.read, "--ql #{query}, not installed, stdout")
|
|
466
|
+
assert_equal("No packages matching '#{query}' installed\n",
|
|
467
|
+
stderr.read, "--ql #{query}, not installed, stderr")
|
|
468
|
+
end
|
|
469
|
+
assert_equal(1, status.exitstatus, "--ql #{query}, not installed, exitstatus")
|
|
470
|
+
end
|
|
471
|
+
# But querying a package file should work
|
|
472
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --ql #{@pkgfile} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
473
|
+
stdin.close
|
|
474
|
+
output = stdout.read
|
|
475
|
+
# Output should start with the filename
|
|
476
|
+
assert_match(/\A#{@pkgfile}:$/, output, "--ql #{@pkgfile}, not installed, header")
|
|
477
|
+
# And then the files, one per file
|
|
478
|
+
oldpwd = Dir.pwd
|
|
479
|
+
Dir.chdir(File.join(TESTPKGDIR, 'reloc'))
|
|
480
|
+
Dir.glob('*').each do |testpkgfile|
|
|
481
|
+
assert_match(/^<relocatable>\/#{testpkgfile}$/,
|
|
482
|
+
output, "--ql #{@pkgfile}, #{testpkgfile}, not installed")
|
|
483
|
+
end
|
|
484
|
+
assert_equal("", stderr.read, "--ql #{@pkgfile}, not installed, stderr")
|
|
485
|
+
Dir.chdir(oldpwd)
|
|
486
|
+
end
|
|
487
|
+
assert_equal(0, status.exitstatus, "--ql #{@pkgfile}, not installed, exitstatus")
|
|
488
|
+
|
|
489
|
+
# FIXME: test when multiple versions of same package are installed
|
|
490
|
+
|
|
491
|
+
# Install a package and try again
|
|
492
|
+
tpkg = Tpkg.new(
|
|
493
|
+
:file_system_root => testroot,
|
|
494
|
+
:sources => [@pkgfile])
|
|
495
|
+
tpkg.install([@pkgfile], PASSPHRASE)
|
|
496
|
+
|
|
497
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
498
|
+
ENV.delete('TPKG_HOME')
|
|
499
|
+
|
|
500
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
501
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --ql #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
502
|
+
stdin.close
|
|
503
|
+
output = stdout.read
|
|
504
|
+
# Output should start with the package filename
|
|
505
|
+
assert_match(
|
|
506
|
+
/\A#{File.basename(@pkgfile)}:$/,
|
|
507
|
+
output, "--ql #{@pkgfile}, installed, header")
|
|
508
|
+
# And then the files, one per file
|
|
509
|
+
oldpwd = Dir.pwd
|
|
510
|
+
Dir.chdir(File.join(TESTPKGDIR, 'reloc'))
|
|
511
|
+
Dir.glob('*').each do |testpkgfile|
|
|
512
|
+
assert_match(
|
|
513
|
+
/^#{File.join(testroot, Tpkg::DEFAULT_BASE, testpkgfile)}$/,
|
|
514
|
+
output, "--ql #{@pkgfile}, #{testpkgfile}, installed")
|
|
515
|
+
end
|
|
516
|
+
assert_equal("", stderr.read, "--ql #{@pkgfile}, installed, stderr")
|
|
517
|
+
Dir.chdir(oldpwd)
|
|
518
|
+
end
|
|
519
|
+
assert_equal(0, status.exitstatus, "--ql #{query}, installed, exitstatus")
|
|
520
|
+
end
|
|
521
|
+
end
|
|
522
|
+
end
|
|
523
|
+
def test_qls
|
|
524
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
525
|
+
|
|
526
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
527
|
+
pkgfile2 = make_package(
|
|
528
|
+
:change => {'name' => 'qlspkg'},
|
|
529
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
530
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
531
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
532
|
+
|
|
533
|
+
# Query a package that is not available, should get nothing
|
|
534
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
535
|
+
status = Open4.popen4(
|
|
536
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qls #{query} " +
|
|
537
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
538
|
+
stdin.close
|
|
539
|
+
assert_equal(
|
|
540
|
+
"", stdout.read,
|
|
541
|
+
"--qls #{query}, not available or installed, stdout")
|
|
542
|
+
assert_equal(
|
|
543
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
544
|
+
"--qls #{query}, not available or installed, stderr")
|
|
545
|
+
end
|
|
546
|
+
assert_equal(
|
|
547
|
+
1, status.exitstatus,
|
|
548
|
+
"--qls #{query}, not available or installed, exitstatus")
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
# Query package that is available but not installed, should get data
|
|
552
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
553
|
+
status = Open4.popen4(
|
|
554
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qls #{query} " +
|
|
555
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
556
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
557
|
+
stdin.close
|
|
558
|
+
output = stdout.read
|
|
559
|
+
# Output should start with the filename
|
|
560
|
+
assert_match(/\A#{File.basename(@pkgfile)}:$/, output, "--qls #{@pkgfile}, available, not installed, header")
|
|
561
|
+
# And then the files, one per file
|
|
562
|
+
oldpwd = Dir.pwd
|
|
563
|
+
Dir.chdir(File.join(TESTPKGDIR, 'reloc'))
|
|
564
|
+
Dir.glob('*').each do |testpkgfile|
|
|
565
|
+
assert_match(/^<relocatable>\/#{testpkgfile}$/,
|
|
566
|
+
output, "--qls #{@pkgfile}, #{testpkgfile}, available, not installed")
|
|
567
|
+
end
|
|
568
|
+
Dir.chdir(oldpwd)
|
|
569
|
+
assert_equal(
|
|
570
|
+
"", stderr.read,
|
|
571
|
+
"--qls #{query}, available, not installed, stderr")
|
|
572
|
+
end
|
|
573
|
+
assert_equal(
|
|
574
|
+
0, status.exitstatus,
|
|
575
|
+
"--qls #{query}, available, not installed, exitstatus")
|
|
576
|
+
end
|
|
577
|
+
|
|
578
|
+
# Install packages and try again
|
|
579
|
+
tpkg = Tpkg.new(
|
|
580
|
+
:file_system_root => testroot,
|
|
581
|
+
:sources => [@pkgfile, pkgfile2])
|
|
582
|
+
tpkg.install([@pkgfile, pkgfile2], PASSPHRASE)
|
|
583
|
+
|
|
584
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg
|
|
585
|
+
# library
|
|
586
|
+
ENV.delete('TPKG_HOME')
|
|
587
|
+
|
|
588
|
+
# Query a package that is installed but not available, should get
|
|
589
|
+
# nothing
|
|
590
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
591
|
+
status = Open4.popen4(
|
|
592
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qls #{query} " +
|
|
593
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
594
|
+
stdin.close
|
|
595
|
+
assert_equal(
|
|
596
|
+
"", stdout.read,
|
|
597
|
+
"--qls #{query}, installed, not available, stdout")
|
|
598
|
+
assert_equal(
|
|
599
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
600
|
+
"--qls #{query}, installed, not available, stderr")
|
|
601
|
+
end
|
|
602
|
+
assert_equal(
|
|
603
|
+
1, status.exitstatus,
|
|
604
|
+
"--qls #{query}, installed, not available, exitstatus")
|
|
605
|
+
end
|
|
606
|
+
|
|
607
|
+
# Query a package that is installed and available, should get the data
|
|
608
|
+
# for the available package
|
|
609
|
+
# pkgfile2 and pkgfile4 have the same name but other differences
|
|
610
|
+
pkgfile4 = nil
|
|
611
|
+
Dir.mktmpdir('pkg4') do |pkg4src|
|
|
612
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(pkg4src, 'tpkg.xml'))
|
|
613
|
+
Dir.mkdir(File.join(pkg4src, 'reloc'))
|
|
614
|
+
File.open(File.join(pkg4src, 'reloc', 'pkg4file'), 'w') {}
|
|
615
|
+
pkgfile4 = make_package(
|
|
616
|
+
:change => {
|
|
617
|
+
'name' => 'qlspkg',
|
|
618
|
+
'version' => '42'},
|
|
619
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
620
|
+
:source_directory => pkg4src,
|
|
621
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
622
|
+
end
|
|
623
|
+
metadata4 = Tpkg::metadata_from_package(pkgfile4)
|
|
624
|
+
[metadata2[:name]].each do |query|
|
|
625
|
+
status = Open4.popen4(
|
|
626
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qls #{query} " +
|
|
627
|
+
"--source #{[@pkgfile,pkgfile4].join(',')} " +
|
|
628
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
629
|
+
stdin.close
|
|
630
|
+
output = stdout.read
|
|
631
|
+
assert_equal(
|
|
632
|
+
"#{File.basename(pkgfile4)}:\n<relocatable>/pkg4file\n", output,
|
|
633
|
+
"--qls #{query}, available and installed, stdout")
|
|
634
|
+
assert_equal(
|
|
635
|
+
"", stderr.read,
|
|
636
|
+
"--qls #{query}, available and installed, stderr")
|
|
637
|
+
end
|
|
638
|
+
assert_equal(
|
|
639
|
+
0, status.exitstatus,
|
|
640
|
+
"--qls #{query}, available and installed, exitstatus")
|
|
641
|
+
end
|
|
642
|
+
end
|
|
643
|
+
end
|
|
644
|
+
def test_qf
|
|
645
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
646
|
+
# Query with no package installed
|
|
647
|
+
queryfile = File.join(testroot, Tpkg::DEFAULT_BASE, 'file')
|
|
648
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qf #{queryfile} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
649
|
+
stdin.close
|
|
650
|
+
assert_equal("", stdout.read, "--qf, not installed, stdout")
|
|
651
|
+
assert_equal("No package owns file '#{queryfile}'\n",
|
|
652
|
+
stderr.read, "--qf, not installed, stderr")
|
|
653
|
+
end
|
|
654
|
+
assert_equal(1, status.exitstatus, "--qf, not installed, exitstatus")
|
|
655
|
+
|
|
656
|
+
# FIXME: test when multiple versions of same package are installed
|
|
657
|
+
|
|
658
|
+
# Install a package and try again
|
|
659
|
+
tpkg = Tpkg.new(
|
|
660
|
+
:file_system_root => testroot,
|
|
661
|
+
:sources => [@pkgfile])
|
|
662
|
+
tpkg.install([@pkgfile], PASSPHRASE)
|
|
663
|
+
|
|
664
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
665
|
+
ENV.delete('TPKG_HOME')
|
|
666
|
+
|
|
667
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qf #{queryfile} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
668
|
+
stdin.close
|
|
669
|
+
assert_equal("#{queryfile}: #{File.basename(@pkgfile)}\n", stdout.read, "--qf, installed, stdout")
|
|
670
|
+
assert_equal("", stderr.read, "--qf, installed, stderr")
|
|
671
|
+
end
|
|
672
|
+
assert_equal(0, status.exitstatus, "--qf, installed, exitstatus")
|
|
673
|
+
end
|
|
674
|
+
end
|
|
675
|
+
# I've shelved the --qfs option for now because we don't currently keep a
|
|
676
|
+
# record of the files in the packages on the server. I.e. metadata.yml
|
|
677
|
+
# doesn't have a complete list of files. So implementing --qfs today would
|
|
678
|
+
# require downloading all of the packages.
|
|
679
|
+
# def test_qfs
|
|
680
|
+
# # FIXME: ways to improve this:
|
|
681
|
+
# # - Multiple packages available with the queried file
|
|
682
|
+
# # - Some available packages don't contain the queried file (need to make a package with no files)
|
|
683
|
+
# # - For the "Installed and available" case make the installed and available packages different to make sure that we're getting the data for the available package instead of the installed package
|
|
684
|
+
#
|
|
685
|
+
# Dir.mktmpdir('testroot') do |testroot|
|
|
686
|
+
# # Neither available nor installed
|
|
687
|
+
# queryfile = File.join(testroot, Tpkg::DEFAULT_BASE, 'file')
|
|
688
|
+
# status = Open4.popen4(
|
|
689
|
+
# "#{RUBY} #{TPKG_EXECUTABLE} --qfs #{queryfile} " +
|
|
690
|
+
# "--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
691
|
+
# stdin.close
|
|
692
|
+
# assert_equal(
|
|
693
|
+
# "", stdout.read, "--qfs, not available, not installed, stdout")
|
|
694
|
+
# assert_equal("No package on server owns file '#{queryfile}'\n",
|
|
695
|
+
# stderr.read, "--qfs, not available, not installed, stderr")
|
|
696
|
+
# end
|
|
697
|
+
# assert_equal(
|
|
698
|
+
# 1, status.exitstatus,
|
|
699
|
+
# "--qfs, not available, not installed, exitstatus")
|
|
700
|
+
#
|
|
701
|
+
# # Available but not installed
|
|
702
|
+
# status = Open4.popen4(
|
|
703
|
+
# "#{RUBY} #{TPKG_EXECUTABLE} --qfs #{queryfile} " +
|
|
704
|
+
# "--source #{@pkgfile} " +
|
|
705
|
+
# "--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
706
|
+
# stdin.close
|
|
707
|
+
# assert_equal(
|
|
708
|
+
# "#{queryfile}: #{File.basename(@pkgfile)}\n", stdout.read,
|
|
709
|
+
# "--qfs, available, not installed, stdout")
|
|
710
|
+
# assert_equal(
|
|
711
|
+
# "", stderr.read, "--qfs, available, not installed, stderr")
|
|
712
|
+
# end
|
|
713
|
+
# assert_equal(
|
|
714
|
+
# 0, status.exitstatus, "--qfs, available, not installed, exitstatus")
|
|
715
|
+
#
|
|
716
|
+
# # Install a package and try again
|
|
717
|
+
# tpkg = Tpkg.new(
|
|
718
|
+
# :file_system_root => testroot,
|
|
719
|
+
# :sources => [@pkgfile])
|
|
720
|
+
# tpkg.install([@pkgfile], PASSPHRASE)
|
|
721
|
+
#
|
|
722
|
+
# # TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
723
|
+
# ENV.delete('TPKG_HOME')
|
|
724
|
+
#
|
|
725
|
+
# # Installed and available
|
|
726
|
+
# status = Open4.popen4(
|
|
727
|
+
# "#{RUBY} #{TPKG_EXECUTABLE} --qfs #{queryfile} " +
|
|
728
|
+
# "--source #{@pkgfile} " +
|
|
729
|
+
# "--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
730
|
+
# stdin.close
|
|
731
|
+
# assert_equal(
|
|
732
|
+
# "#{queryfile}: #{File.basename(@pkgfile)}\n", stdout.read,
|
|
733
|
+
# "--qfs, installed and available, stdout")
|
|
734
|
+
# assert_equal(
|
|
735
|
+
# "", stderr.read, "--qfs, installed and available, stderr")
|
|
736
|
+
# end
|
|
737
|
+
# assert_equal(0, status.exitstatus, "--qfs, installed, exitstatus")
|
|
738
|
+
#
|
|
739
|
+
# # Installed but not available
|
|
740
|
+
# queryfile = File.join(testroot, Tpkg::DEFAULT_BASE, 'file')
|
|
741
|
+
# status = Open4.popen4(
|
|
742
|
+
# "#{RUBY} #{TPKG_EXECUTABLE} --qfs #{queryfile} " +
|
|
743
|
+
# "--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
744
|
+
# stdin.close
|
|
745
|
+
# assert_equal(
|
|
746
|
+
# "", stdout.read, "--qfs, not available, installed, stdout")
|
|
747
|
+
# assert_equal("No package on server owns file '#{queryfile}'\n",
|
|
748
|
+
# stderr.read, "--qfs, not available, installed, stderr")
|
|
749
|
+
# end
|
|
750
|
+
# assert_equal(
|
|
751
|
+
# 1, status.exitstatus,
|
|
752
|
+
# "--qfs, not available, installed, exitstatus")
|
|
753
|
+
# end
|
|
754
|
+
# end
|
|
755
|
+
def test_qs
|
|
756
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
757
|
+
|
|
758
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
759
|
+
pkgfile2 = make_package(:change => {'name' => 'qvpkg'},
|
|
760
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
761
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
762
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
763
|
+
|
|
764
|
+
# Query with no package installed
|
|
765
|
+
# Query for an available package
|
|
766
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
767
|
+
status = Open4.popen4(
|
|
768
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
769
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
770
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
771
|
+
stdin.close
|
|
772
|
+
assert_equal(
|
|
773
|
+
"#{File.basename(@pkgfile)} (#{@pkgfile})\n", stdout.read,
|
|
774
|
+
"--qs #{query}, not installed, stdout")
|
|
775
|
+
assert_equal(
|
|
776
|
+
'', stderr.read,
|
|
777
|
+
"--qs #{query}, not installed, stderr")
|
|
778
|
+
end
|
|
779
|
+
assert_equal(
|
|
780
|
+
0, status.exitstatus,
|
|
781
|
+
"--qs #{query}, not installed, exitstatus")
|
|
782
|
+
# Same query with --quiet should be quiet
|
|
783
|
+
status = Open4.popen4(
|
|
784
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
785
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
786
|
+
"--quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
787
|
+
stdin.close
|
|
788
|
+
assert_equal(
|
|
789
|
+
'', stdout.read,
|
|
790
|
+
"--qs #{query} --quiet, not installed, stdout")
|
|
791
|
+
assert_equal(
|
|
792
|
+
'', stderr.read,
|
|
793
|
+
"--qs #{query} --quiet, not installed, stderr")
|
|
794
|
+
end
|
|
795
|
+
assert_equal(
|
|
796
|
+
0, status.exitstatus,
|
|
797
|
+
"--qs #{query} --quiet, not installed, exitstatus")
|
|
798
|
+
end
|
|
799
|
+
# Query for an unavailable package
|
|
800
|
+
['bogus-1.0-1.tpkg', 'bogus'].each do |query|
|
|
801
|
+
status = Open4.popen4(
|
|
802
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
803
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
804
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
805
|
+
stdin.close
|
|
806
|
+
assert_equal(
|
|
807
|
+
'', stdout.read,
|
|
808
|
+
"--qs #{query}, not installed, stdout")
|
|
809
|
+
assert_equal(
|
|
810
|
+
"No packages matching '#{query}' available\n",
|
|
811
|
+
stderr.read, "--qs #{query}, not installed, stderr")
|
|
812
|
+
end
|
|
813
|
+
assert_equal(1, status.exitstatus, "--qs #{query}, not installed, exitstatus")
|
|
814
|
+
# Same query with --quiet should be quiet
|
|
815
|
+
status = Open4.popen4(
|
|
816
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
817
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
818
|
+
"--quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
819
|
+
stdin.close
|
|
820
|
+
assert_equal(
|
|
821
|
+
'', stdout.read,
|
|
822
|
+
"--qs #{query} --quiet, not installed, stdout")
|
|
823
|
+
assert_equal(
|
|
824
|
+
'', stderr.read,
|
|
825
|
+
"--qs #{query} --quiet, not installed, stderr")
|
|
826
|
+
end
|
|
827
|
+
assert_equal(
|
|
828
|
+
1, status.exitstatus,
|
|
829
|
+
"--qs #{query} --quiet, not installed, exitstatus")
|
|
830
|
+
end
|
|
831
|
+
|
|
832
|
+
# Install package and try again
|
|
833
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :sources => [@pkgfile])
|
|
834
|
+
tpkg.install([@pkgfile], PASSPHRASE)
|
|
835
|
+
|
|
836
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
837
|
+
ENV.delete('TPKG_HOME')
|
|
838
|
+
|
|
839
|
+
# Query package that's installed (should still be available)
|
|
840
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
841
|
+
status = Open4.popen4(
|
|
842
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
843
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
844
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
845
|
+
stdin.close
|
|
846
|
+
assert_equal(
|
|
847
|
+
"#{File.basename(@pkgfile)} (#{@pkgfile})\n", stdout.read,
|
|
848
|
+
"--qs #{query}, installed, stdout")
|
|
849
|
+
assert_equal(
|
|
850
|
+
'', stderr.read,
|
|
851
|
+
"--qs #{query}, installed, stderr")
|
|
852
|
+
end
|
|
853
|
+
assert_equal(
|
|
854
|
+
0, status.exitstatus,
|
|
855
|
+
"--qs #{query}, installed, exitstatus")
|
|
856
|
+
# Same query with --quiet should be quiet
|
|
857
|
+
status = Open4.popen4(
|
|
858
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
859
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
860
|
+
"--quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
861
|
+
stdin.close
|
|
862
|
+
assert_equal(
|
|
863
|
+
'', stdout.read,
|
|
864
|
+
"--qs #{query} --quiet, installed, stdout")
|
|
865
|
+
assert_equal(
|
|
866
|
+
'', stderr.read,
|
|
867
|
+
"--qs #{query} --quiet, installed, stderr")
|
|
868
|
+
end
|
|
869
|
+
assert_equal(
|
|
870
|
+
0, status.exitstatus,
|
|
871
|
+
"--qs #{query} --quiet, installed, exitstatus")
|
|
872
|
+
end
|
|
873
|
+
|
|
874
|
+
# Query package that's available but not installed
|
|
875
|
+
[File.basename(pkgfile2), metadata2[:name]].each do |query|
|
|
876
|
+
status = Open4.popen4(
|
|
877
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
878
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
879
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
880
|
+
stdin.close
|
|
881
|
+
assert_equal(
|
|
882
|
+
"#{File.basename(pkgfile2)} (#{pkgfile2})\n",
|
|
883
|
+
stdout.read, "--qs #{query}, installed, stdout")
|
|
884
|
+
assert_equal(
|
|
885
|
+
'',
|
|
886
|
+
stderr.read, "--qs #{query}, installed, stderr")
|
|
887
|
+
end
|
|
888
|
+
assert_equal(
|
|
889
|
+
0, status.exitstatus,
|
|
890
|
+
"--qs #{query}, installed, exitstatus")
|
|
891
|
+
# Same query with --quiet should be quiet
|
|
892
|
+
status = Open4.popen4(
|
|
893
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
894
|
+
"--source #{[@pkgfile,pkgfile2].join(',')} " +
|
|
895
|
+
"--quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
896
|
+
stdin.close
|
|
897
|
+
assert_equal(
|
|
898
|
+
'', stdout.read,
|
|
899
|
+
"--qs #{query} --quiet, installed, stdout")
|
|
900
|
+
assert_equal(
|
|
901
|
+
'', stderr.read,
|
|
902
|
+
"--qs #{query} --quiet, installed, stderr")
|
|
903
|
+
end
|
|
904
|
+
assert_equal(
|
|
905
|
+
0, status.exitstatus,
|
|
906
|
+
"--qs #{query} --quiet, installed, exitstatus")
|
|
907
|
+
end
|
|
908
|
+
|
|
909
|
+
# Query package that's installed but no longer available
|
|
910
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
911
|
+
status = Open4.popen4(
|
|
912
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
913
|
+
"--source #{[pkgfile2].join(',')} " +
|
|
914
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
915
|
+
stdin.close
|
|
916
|
+
assert_equal(
|
|
917
|
+
'', stdout.read,
|
|
918
|
+
"--qs #{query}, installed but not available, stdout")
|
|
919
|
+
assert_equal(
|
|
920
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
921
|
+
"--qs #{query}, installed but not available, stderr")
|
|
922
|
+
end
|
|
923
|
+
assert_equal(
|
|
924
|
+
1, status.exitstatus,
|
|
925
|
+
"--qs #{query}, installed but not available, exitstatus")
|
|
926
|
+
# Same query with --quiet should be quiet
|
|
927
|
+
status = Open4.popen4(
|
|
928
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qs #{query} " +
|
|
929
|
+
"--source #{[pkgfile2].join(',')} " +
|
|
930
|
+
"--quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
931
|
+
stdin.close
|
|
932
|
+
assert_equal(
|
|
933
|
+
'', stdout.read,
|
|
934
|
+
"--qs #{query} --quiet, installed but not available, stdout")
|
|
935
|
+
assert_equal(
|
|
936
|
+
'', stderr.read,
|
|
937
|
+
"--qs #{query} --quiet, installed but not available, stderr")
|
|
938
|
+
end
|
|
939
|
+
assert_equal(
|
|
940
|
+
1, status.exitstatus,
|
|
941
|
+
"--qs #{query} --quiet, installed but not available, exitstatus")
|
|
942
|
+
end
|
|
943
|
+
end
|
|
944
|
+
end
|
|
945
|
+
def test_qas
|
|
946
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
947
|
+
|
|
948
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
949
|
+
# Names chosen so as to test sorting of output
|
|
950
|
+
pkgfile2 = make_package(:change => {'name' => 'aqvapkg'},
|
|
951
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
952
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
953
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
954
|
+
pkgfile3 = make_package(:change => {'name' => 'zqvapkg'},
|
|
955
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
956
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
957
|
+
metadata3 = Tpkg::metadata_from_package(pkgfile3)
|
|
958
|
+
|
|
959
|
+
# Query with no package installed or available
|
|
960
|
+
status = Open4.popen4(
|
|
961
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas " +
|
|
962
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
963
|
+
stdin.close
|
|
964
|
+
assert_equal(
|
|
965
|
+
'', stdout.read, "--qas, not installed or available, stdout")
|
|
966
|
+
assert_equal(
|
|
967
|
+
"No packages available\n", stderr.read,
|
|
968
|
+
"--qas, not installed or available, stderr")
|
|
969
|
+
end
|
|
970
|
+
assert_equal(
|
|
971
|
+
1, status.exitstatus,
|
|
972
|
+
"--qas, not installed or available, exitstatus")
|
|
973
|
+
# Same query with --quiet should be quiet
|
|
974
|
+
status = Open4.popen4(
|
|
975
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas --quiet " +
|
|
976
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
977
|
+
stdin.close
|
|
978
|
+
assert_equal(
|
|
979
|
+
'', stdout.read,
|
|
980
|
+
"--qas --quiet, not installed or available, stdout")
|
|
981
|
+
assert_equal(
|
|
982
|
+
'', stderr.read,
|
|
983
|
+
"--qas --quiet, not installed or available, stderr")
|
|
984
|
+
end
|
|
985
|
+
assert_equal(
|
|
986
|
+
1, status.exitstatus,
|
|
987
|
+
"--qas --quiet, not installed or available, exitstatus")
|
|
988
|
+
|
|
989
|
+
# Query with no package installed
|
|
990
|
+
status = Open4.popen4(
|
|
991
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas " +
|
|
992
|
+
"--source #{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
993
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
994
|
+
stdin.close
|
|
995
|
+
assert_equal(
|
|
996
|
+
[pkgfile2, @pkgfile, pkgfile3].collect {|p| "#{File.basename(p)} (#{p})"}.join("\n") + "\n",
|
|
997
|
+
stdout.read, "--qas, not installed, stdout")
|
|
998
|
+
assert_equal('', stderr.read, "--qas, not installed, stderr")
|
|
999
|
+
end
|
|
1000
|
+
assert_equal(0, status.exitstatus, "--qas, not installed, exitstatus")
|
|
1001
|
+
# Same query with --quiet should be quiet
|
|
1002
|
+
status = Open4.popen4(
|
|
1003
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas " +
|
|
1004
|
+
"--source #{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
1005
|
+
"--quiet --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1006
|
+
stdin.close
|
|
1007
|
+
assert_equal('', stdout.read, "--qas --quiet, not installed, stdout")
|
|
1008
|
+
assert_equal('', stderr.read, "--qas --quiet, not installed, stderr")
|
|
1009
|
+
end
|
|
1010
|
+
assert_equal(
|
|
1011
|
+
0, status.exitstatus, "--qas --quiet, not installed, exitstatus")
|
|
1012
|
+
|
|
1013
|
+
# Install package and try again
|
|
1014
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :sources => [@pkgfile])
|
|
1015
|
+
tpkg.install([@pkgfile], PASSPHRASE)
|
|
1016
|
+
|
|
1017
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
1018
|
+
ENV.delete('TPKG_HOME')
|
|
1019
|
+
|
|
1020
|
+
# Installed packages should still show up as available
|
|
1021
|
+
status = Open4.popen4(
|
|
1022
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas " +
|
|
1023
|
+
"--source #{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
1024
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1025
|
+
stdin.close
|
|
1026
|
+
assert_equal(
|
|
1027
|
+
[pkgfile2, @pkgfile, pkgfile3].collect {
|
|
1028
|
+
|p| "#{File.basename(p)} (#{p})"}.join("\n") + "\n",
|
|
1029
|
+
stdout.read, "--qas, installed, stdout")
|
|
1030
|
+
assert_equal('', stderr.read, "--qas, installed, stderr")
|
|
1031
|
+
end
|
|
1032
|
+
assert_equal(0, status.exitstatus, "--qas, installed, exitstatus")
|
|
1033
|
+
# Same query with --quiet should be quiet
|
|
1034
|
+
status = Open4.popen4(
|
|
1035
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas " +
|
|
1036
|
+
"--source #{[@pkgfile,pkgfile2,pkgfile3].join(',')} --quiet " +
|
|
1037
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1038
|
+
stdin.close
|
|
1039
|
+
assert_equal('', stdout.read, "--qas --quiet, installed, stdout")
|
|
1040
|
+
assert_equal('', stderr.read, "--qas --quiet, installed, stderr")
|
|
1041
|
+
end
|
|
1042
|
+
assert_equal(
|
|
1043
|
+
0, status.exitstatus, "--qas --quiet, installed, exitstatus")
|
|
1044
|
+
|
|
1045
|
+
# A package that's installed but no longer available should not show up
|
|
1046
|
+
# as available
|
|
1047
|
+
status = Open4.popen4(
|
|
1048
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas " +
|
|
1049
|
+
"--source #{[pkgfile2,pkgfile3].join(',')} " +
|
|
1050
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1051
|
+
stdin.close
|
|
1052
|
+
assert_equal(
|
|
1053
|
+
[pkgfile2, pkgfile3].collect {
|
|
1054
|
+
|p| "#{File.basename(p)} (#{p})"}.join("\n") + "\n",
|
|
1055
|
+
stdout.read, "--qas, installed, stdout")
|
|
1056
|
+
assert_equal('', stderr.read, "--qas, installed, stderr")
|
|
1057
|
+
end
|
|
1058
|
+
assert_equal(
|
|
1059
|
+
0, status.exitstatus, "--qas, installed, exitstatus")
|
|
1060
|
+
# Same query with --quiet should be quiet
|
|
1061
|
+
status = Open4.popen4(
|
|
1062
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas " +
|
|
1063
|
+
"--source #{[pkgfile2,pkgfile3].join(',')} --quiet " +
|
|
1064
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1065
|
+
stdin.close
|
|
1066
|
+
assert_equal('', stdout.read, "--qas --quiet, installed, stdout")
|
|
1067
|
+
assert_equal('', stderr.read, "--qas --quiet, installed, stderr")
|
|
1068
|
+
end
|
|
1069
|
+
assert_equal(
|
|
1070
|
+
0, status.exitstatus, "--qas --quiet, installed, exitstatus")
|
|
1071
|
+
|
|
1072
|
+
# No available packages should still be reported as such even if
|
|
1073
|
+
# packages are installed
|
|
1074
|
+
status = Open4.popen4(
|
|
1075
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas " +
|
|
1076
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1077
|
+
stdin.close
|
|
1078
|
+
assert_equal(
|
|
1079
|
+
'', stdout.read, "--qas, installed but not available, stdout")
|
|
1080
|
+
assert_equal(
|
|
1081
|
+
"No packages available\n",
|
|
1082
|
+
stderr.read, "--qas, installed but not available, stderr")
|
|
1083
|
+
end
|
|
1084
|
+
assert_equal(
|
|
1085
|
+
1, status.exitstatus,
|
|
1086
|
+
"--qas, installed but not available, exitstatus")
|
|
1087
|
+
# Same query with --quiet should be quiet
|
|
1088
|
+
status = Open4.popen4(
|
|
1089
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qas --quiet " +
|
|
1090
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1091
|
+
stdin.close
|
|
1092
|
+
assert_equal(
|
|
1093
|
+
'', stdout.read,
|
|
1094
|
+
"--qas --quiet, installed but not available, stdout")
|
|
1095
|
+
assert_equal(
|
|
1096
|
+
'', stderr.read,
|
|
1097
|
+
"--qas --quiet, installed but not available, stderr")
|
|
1098
|
+
end
|
|
1099
|
+
assert_equal(
|
|
1100
|
+
1, status.exitstatus,
|
|
1101
|
+
"--qas --quiet, installed but not available, exitstatus")
|
|
1102
|
+
end
|
|
1103
|
+
end
|
|
1104
|
+
def test_qr
|
|
1105
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
1106
|
+
|
|
1107
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
1108
|
+
# Query with no package installed
|
|
1109
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1110
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qr #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1111
|
+
stdin.close
|
|
1112
|
+
assert_equal(
|
|
1113
|
+
"No other package depends on '#{query}'\n",
|
|
1114
|
+
stdout.read, "--qr #{query}, not installed, stdout")
|
|
1115
|
+
assert_equal(
|
|
1116
|
+
"No packages matching '#{query}' installed\n",
|
|
1117
|
+
stderr.read, "--qr #{query}, not installed, stderr")
|
|
1118
|
+
end
|
|
1119
|
+
assert_equal(1, status.exitstatus, "--qr #{query}, not installed, exitstatus")
|
|
1120
|
+
end
|
|
1121
|
+
|
|
1122
|
+
pkgfile2 = make_package(
|
|
1123
|
+
:change => {'name' => 'qrdepspkg'},
|
|
1124
|
+
:dependencies => {metadata[:name] => {}},
|
|
1125
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
1126
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
1127
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
1128
|
+
|
|
1129
|
+
# Install packages and try again
|
|
1130
|
+
tpkg = Tpkg.new(
|
|
1131
|
+
:file_system_root => testroot,
|
|
1132
|
+
:sources => [@pkgfile, pkgfile2])
|
|
1133
|
+
tpkg.install([@pkgfile, pkgfile2], PASSPHRASE)
|
|
1134
|
+
|
|
1135
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
1136
|
+
ENV.delete('TPKG_HOME')
|
|
1137
|
+
|
|
1138
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1139
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qr #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1140
|
+
stdin.close
|
|
1141
|
+
assert_equal(
|
|
1142
|
+
"The following package(s) require #{File.basename(@pkgfile)}:\n" +
|
|
1143
|
+
" #{File.basename(pkgfile2)}\n",
|
|
1144
|
+
stdout.read, "--qr #{query}, installed, stdout")
|
|
1145
|
+
assert_equal(
|
|
1146
|
+
"", stderr.read, "--qr #{query}, installed, stderr")
|
|
1147
|
+
end
|
|
1148
|
+
assert_equal(0, status.exitstatus, "--qr, #{metadata[:name]}, installed, exitstatus")
|
|
1149
|
+
end
|
|
1150
|
+
[File.basename(pkgfile2), metadata2[:name]].each do |query|
|
|
1151
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qr #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1152
|
+
stdin.close
|
|
1153
|
+
assert_equal("No other package depends on '#{query}'\n",
|
|
1154
|
+
stdout.read, "--qr #{query}, installed, stdout")
|
|
1155
|
+
assert_equal("", stderr.read, "--qr #{query}, installed, stderr")
|
|
1156
|
+
end
|
|
1157
|
+
assert_equal(0, status.exitstatus, "--qr #{query}, installed, exitstatus")
|
|
1158
|
+
end
|
|
1159
|
+
end
|
|
1160
|
+
end
|
|
1161
|
+
def test_qd
|
|
1162
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
1163
|
+
|
|
1164
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
1165
|
+
pkgfile2 = make_package(
|
|
1166
|
+
:change => {'name' => 'qdslavepkg'},
|
|
1167
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
1168
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
1169
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
1170
|
+
pkgfile3 = make_package(
|
|
1171
|
+
:change => {'name' => 'qddepspkg'},
|
|
1172
|
+
:dependencies => {metadata[:name] => {}, 'qdslavepkg' => {:minimum_version => '1'}},
|
|
1173
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
1174
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
1175
|
+
metadata3 = Tpkg::metadata_from_package(pkgfile3)
|
|
1176
|
+
|
|
1177
|
+
# Query with no package installed
|
|
1178
|
+
# Queries for installed packages should return nothing
|
|
1179
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1180
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qd #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1181
|
+
stdin.close
|
|
1182
|
+
assert_equal("", stdout.read, "--qd #{query}, not installed, stdout")
|
|
1183
|
+
assert_equal("No packages matching '#{query}' installed\n",
|
|
1184
|
+
stderr.read, "--qd #{query}, not installed, stderr")
|
|
1185
|
+
end
|
|
1186
|
+
assert_equal(1, status.exitstatus, "--qd #{query}, not installed, exitstatus")
|
|
1187
|
+
end
|
|
1188
|
+
# But querying a package file should work
|
|
1189
|
+
# This package has no dependencies
|
|
1190
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qd #{@pkgfile} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1191
|
+
stdin.close
|
|
1192
|
+
assert_equal(
|
|
1193
|
+
"Package '#{@pkgfile}' does not depend on other packages\n",
|
|
1194
|
+
stdout.read, "--qd #{@pkgfile}, not installed, stdout")
|
|
1195
|
+
assert_equal(
|
|
1196
|
+
"", stderr.read, "--qd #{@pkgfile}, not installed, stderr")
|
|
1197
|
+
end
|
|
1198
|
+
assert_equal(0, status.exitstatus, "--qd #{@pkgfile}, not installed, exitstatus")
|
|
1199
|
+
# This package has some dependencies
|
|
1200
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qd #{pkgfile3} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1201
|
+
stdin.close
|
|
1202
|
+
assert_equal("Package #{File.basename(pkgfile3)} depends on:\n" +
|
|
1203
|
+
" name: qdslavepkg\n type: tpkg\n\n" +
|
|
1204
|
+
" name: #{metadata[:name]}\n type: tpkg\n",
|
|
1205
|
+
stdout.read, "--qd #{pkgfile3}, not installed, stdout")
|
|
1206
|
+
assert_equal("", stderr.read, "--qd #{pkgfile3}, not installed, stderr")
|
|
1207
|
+
end
|
|
1208
|
+
assert_equal(0, status.exitstatus, "--qd #{pkgfile3}, not installed, exitstatus")
|
|
1209
|
+
|
|
1210
|
+
# Install packages and try again
|
|
1211
|
+
tpkg = Tpkg.new(
|
|
1212
|
+
:file_system_root => testroot,
|
|
1213
|
+
:sources => [@pkgfile, pkgfile2, pkgfile3])
|
|
1214
|
+
tpkg.install([@pkgfile, pkgfile2, pkgfile3], PASSPHRASE)
|
|
1215
|
+
|
|
1216
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
1217
|
+
ENV.delete('TPKG_HOME')
|
|
1218
|
+
|
|
1219
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1220
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qd #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1221
|
+
stdin.close
|
|
1222
|
+
assert_equal(
|
|
1223
|
+
"Package '#{query}' does not depend on other packages\n",
|
|
1224
|
+
stdout.read, "--qd #{query}, installed, stdout")
|
|
1225
|
+
assert_equal(
|
|
1226
|
+
"", stderr.read, "--qd #{query}, installed, stderr")
|
|
1227
|
+
end
|
|
1228
|
+
assert_equal(0, status.exitstatus, "--qd #{query}, installed, exitstatus")
|
|
1229
|
+
end
|
|
1230
|
+
[File.basename(pkgfile3), metadata3[:name]].each do |query|
|
|
1231
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qd #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1232
|
+
stdin.close
|
|
1233
|
+
assert_equal("Package #{File.basename(pkgfile3)} depends on:\n" +
|
|
1234
|
+
" name: qdslavepkg\n type: tpkg\n\n" +
|
|
1235
|
+
" name: #{metadata[:name]}\n type: tpkg\n",
|
|
1236
|
+
stdout.read, "--qd #{query}, installed, stdout")
|
|
1237
|
+
assert_equal("", stderr.read, "--qd #{query}, installed, stderr")
|
|
1238
|
+
end
|
|
1239
|
+
assert_equal(0, status.exitstatus, "--qd #{query}, installed, exitstatus")
|
|
1240
|
+
end
|
|
1241
|
+
end
|
|
1242
|
+
end
|
|
1243
|
+
def test_qds
|
|
1244
|
+
# FIXME: ways to improve this:
|
|
1245
|
+
# - Multiple packages available matching package name
|
|
1246
|
+
# - Some available packages have dependencies, some done
|
|
1247
|
+
# - For the "Installed and available" case make the installed and available packages different to make sure that we're getting the data for the available package instead of the installed package
|
|
1248
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
1249
|
+
|
|
1250
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
1251
|
+
pkgfile2 = make_package(
|
|
1252
|
+
:change => {'name' => 'qdsslavepkg'},
|
|
1253
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
1254
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
1255
|
+
metadata2 = Tpkg::metadata_from_package(pkgfile2)
|
|
1256
|
+
pkgfile3 = make_package(
|
|
1257
|
+
:change => {'name' => 'qdsdepspkg'},
|
|
1258
|
+
:dependencies => {metadata[:name] => {}, 'qdsslavepkg' => {:minimum_version => '1'}},
|
|
1259
|
+
:remove => ['operatingsystem', 'architecture'],
|
|
1260
|
+
:output_directory => File.join(testroot, 'tmp'))
|
|
1261
|
+
metadata3 = Tpkg::metadata_from_package(pkgfile3)
|
|
1262
|
+
|
|
1263
|
+
# Not available, not installed
|
|
1264
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1265
|
+
status = Open4.popen4(
|
|
1266
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qds #{query} " +
|
|
1267
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1268
|
+
stdin.close
|
|
1269
|
+
assert_equal(
|
|
1270
|
+
"", stdout.read,
|
|
1271
|
+
"--qds #{query}, not available, not installed, stdout")
|
|
1272
|
+
assert_equal(
|
|
1273
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
1274
|
+
"--qds #{query}, not available, not installed, stderr")
|
|
1275
|
+
end
|
|
1276
|
+
assert_equal(
|
|
1277
|
+
1, status.exitstatus,
|
|
1278
|
+
"--qds #{query}, not available, not installed, exitstatus")
|
|
1279
|
+
end
|
|
1280
|
+
|
|
1281
|
+
# Available, not installed
|
|
1282
|
+
# This package has no dependencies
|
|
1283
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1284
|
+
status = Open4.popen4(
|
|
1285
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qds #{query} " +
|
|
1286
|
+
"--source=#{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
1287
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1288
|
+
stdin.close
|
|
1289
|
+
assert_equal(
|
|
1290
|
+
"Package '#{query}' does not depend on other packages\n",
|
|
1291
|
+
stdout.read, "--qds #{query}, available, not installed, stdout")
|
|
1292
|
+
assert_equal(
|
|
1293
|
+
"", stderr.read,
|
|
1294
|
+
"--qds #{query}, available, not installed, stderr")
|
|
1295
|
+
end
|
|
1296
|
+
assert_equal(
|
|
1297
|
+
0, status.exitstatus,
|
|
1298
|
+
"--qds #{query}, available, not installed, exitstatus")
|
|
1299
|
+
end
|
|
1300
|
+
# This package has some dependencies
|
|
1301
|
+
[File.basename(pkgfile3), metadata3[:name]].each do |query|
|
|
1302
|
+
status = Open4.popen4(
|
|
1303
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qds #{query} " +
|
|
1304
|
+
"--source=#{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
1305
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1306
|
+
stdin.close
|
|
1307
|
+
assert_equal("Package #{File.basename(pkgfile3)} depends on:\n" +
|
|
1308
|
+
" name: qdsslavepkg\n type: tpkg\n\n" +
|
|
1309
|
+
" name: #{metadata[:name]}\n type: tpkg\n",
|
|
1310
|
+
stdout.read, "--qds #{query}, available, not installed, stdout")
|
|
1311
|
+
assert_equal(
|
|
1312
|
+
"", stderr.read,
|
|
1313
|
+
"--qds #{query}, available, not installed, stderr")
|
|
1314
|
+
end
|
|
1315
|
+
assert_equal(
|
|
1316
|
+
0, status.exitstatus,
|
|
1317
|
+
"--qds #{query}, available, not installed, exitstatus")
|
|
1318
|
+
end
|
|
1319
|
+
|
|
1320
|
+
# Install packages and try again
|
|
1321
|
+
tpkg = Tpkg.new(
|
|
1322
|
+
:file_system_root => testroot,
|
|
1323
|
+
:sources => [@pkgfile, pkgfile2, pkgfile3])
|
|
1324
|
+
tpkg.install([@pkgfile, pkgfile2, pkgfile3], PASSPHRASE)
|
|
1325
|
+
|
|
1326
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
1327
|
+
ENV.delete('TPKG_HOME')
|
|
1328
|
+
|
|
1329
|
+
# Installed and available
|
|
1330
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1331
|
+
status = Open4.popen4(
|
|
1332
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qds #{query} " +
|
|
1333
|
+
"--source=#{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
1334
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1335
|
+
stdin.close
|
|
1336
|
+
assert_equal(
|
|
1337
|
+
"Package '#{query}' does not depend on other packages\n",
|
|
1338
|
+
stdout.read, "--qds #{query}, available, installed, stdout")
|
|
1339
|
+
assert_equal(
|
|
1340
|
+
"", stderr.read, "--qds #{query}, available, installed, stderr")
|
|
1341
|
+
end
|
|
1342
|
+
assert_equal(
|
|
1343
|
+
0, status.exitstatus,
|
|
1344
|
+
"--qds #{query}, available, installed, exitstatus")
|
|
1345
|
+
end
|
|
1346
|
+
[File.basename(pkgfile3), metadata3[:name]].each do |query|
|
|
1347
|
+
status = Open4.popen4(
|
|
1348
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qds #{query} " +
|
|
1349
|
+
"--source=#{[@pkgfile,pkgfile2,pkgfile3].join(',')} " +
|
|
1350
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1351
|
+
stdin.close
|
|
1352
|
+
assert_equal("Package #{File.basename(pkgfile3)} depends on:\n" +
|
|
1353
|
+
" name: qdsslavepkg\n type: tpkg\n\n" +
|
|
1354
|
+
" name: #{metadata[:name]}\n type: tpkg\n",
|
|
1355
|
+
stdout.read, "--qds #{query}, available, installed, stdout")
|
|
1356
|
+
assert_equal(
|
|
1357
|
+
"", stderr.read, "--qds #{query}, available, installed, stderr")
|
|
1358
|
+
end
|
|
1359
|
+
assert_equal(
|
|
1360
|
+
0, status.exitstatus,
|
|
1361
|
+
"--qds #{query}, available, installed, exitstatus")
|
|
1362
|
+
end
|
|
1363
|
+
|
|
1364
|
+
# Not available but installed
|
|
1365
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1366
|
+
status = Open4.popen4(
|
|
1367
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qds #{query} " +
|
|
1368
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1369
|
+
stdin.close
|
|
1370
|
+
assert_equal(
|
|
1371
|
+
"", stdout.read,
|
|
1372
|
+
"--qds #{query}, not available, installed, stdout")
|
|
1373
|
+
assert_equal(
|
|
1374
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
1375
|
+
"--qds #{query}, not available, installed, stderr")
|
|
1376
|
+
end
|
|
1377
|
+
assert_equal(
|
|
1378
|
+
1, status.exitstatus,
|
|
1379
|
+
"--qds #{query}, not available, installed, exitstatus")
|
|
1380
|
+
end
|
|
1381
|
+
end
|
|
1382
|
+
end
|
|
1383
|
+
def test_qX
|
|
1384
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
1385
|
+
|
|
1386
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
1387
|
+
# Query with no package installed
|
|
1388
|
+
# Queries for installed packages should return nothing
|
|
1389
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1390
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qX #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1391
|
+
stdin.close
|
|
1392
|
+
assert_equal("", stdout.read, "--qX #{query}, not installed, stdout")
|
|
1393
|
+
assert_equal("No packages matching '#{query}' installed\n",
|
|
1394
|
+
stderr.read, "--qX #{query}, not installed, stderr")
|
|
1395
|
+
end
|
|
1396
|
+
assert_equal(1, status.exitstatus, "--qX #{query}, not installed, exitstatus")
|
|
1397
|
+
end
|
|
1398
|
+
# But querying a package file should work
|
|
1399
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qX #{@pkgfile} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1400
|
+
stdin.close
|
|
1401
|
+
assert_equal(metadata.text, stdout.read, "--qX #{@pkgfile}, not installed, stdout")
|
|
1402
|
+
assert_equal("", stderr.read, "--qX #{@pkgfile}, not installed, stderr")
|
|
1403
|
+
end
|
|
1404
|
+
assert_equal(0, status.exitstatus, "--qX #{@pkgfile}, not installed, exitstatus")
|
|
1405
|
+
|
|
1406
|
+
# Install package and try again
|
|
1407
|
+
tpkg = Tpkg.new(
|
|
1408
|
+
:file_system_root => testroot,
|
|
1409
|
+
:sources => [@pkgfile])
|
|
1410
|
+
tpkg.install([@pkgfile], PASSPHRASE)
|
|
1411
|
+
|
|
1412
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
1413
|
+
ENV.delete('TPKG_HOME')
|
|
1414
|
+
|
|
1415
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1416
|
+
status = Open4.popen4("#{RUBY} #{TPKG_EXECUTABLE} --qX #{query} --test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1417
|
+
stdin.close
|
|
1418
|
+
assert_equal(
|
|
1419
|
+
metadata.text, stdout.read, "--qX #{query}, installed, stdout")
|
|
1420
|
+
assert_equal("", stderr.read, "--qX #{query}, installed, stderr")
|
|
1421
|
+
end
|
|
1422
|
+
assert_equal(0, status.exitstatus, "--qX #{query}, installed, exitstatus")
|
|
1423
|
+
end
|
|
1424
|
+
end
|
|
1425
|
+
end
|
|
1426
|
+
def test_qXs
|
|
1427
|
+
# FIXME: ways to improve this:
|
|
1428
|
+
# - Multiple packages available matching package name
|
|
1429
|
+
# - For the "Installed and available" case make the installed and available packages different to make sure that we're getting the data for the available package instead of the installed package
|
|
1430
|
+
metadata = Tpkg::metadata_from_package(@pkgfile)
|
|
1431
|
+
|
|
1432
|
+
Dir.mktmpdir('testroot') do |testroot|
|
|
1433
|
+
# Not available, not installed
|
|
1434
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1435
|
+
status = Open4.popen4(
|
|
1436
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qXs #{query} " +
|
|
1437
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1438
|
+
stdin.close
|
|
1439
|
+
assert_equal("", stdout.read,
|
|
1440
|
+
"--qXs #{query}, not available, not installed, stdout")
|
|
1441
|
+
assert_equal(
|
|
1442
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
1443
|
+
"--qXs #{query}, not available, not installed, stderr")
|
|
1444
|
+
end
|
|
1445
|
+
assert_equal(1, status.exitstatus,
|
|
1446
|
+
"--qXs #{query}, not available, not installed, exitstatus")
|
|
1447
|
+
end
|
|
1448
|
+
|
|
1449
|
+
# Available, not installed
|
|
1450
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1451
|
+
status = Open4.popen4(
|
|
1452
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qXs #{query} " +
|
|
1453
|
+
"--source #{@pkgfile} " +
|
|
1454
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1455
|
+
stdin.close
|
|
1456
|
+
assert_equal(metadata.text, stdout.read,
|
|
1457
|
+
"--qXs #{query}, available, not installed, stdout")
|
|
1458
|
+
assert_equal("", stderr.read,
|
|
1459
|
+
"--qXs #{query}, available, not installed, stderr")
|
|
1460
|
+
end
|
|
1461
|
+
assert_equal(0, status.exitstatus,
|
|
1462
|
+
"--qXs #{query}, available, not installed, exitstatus")
|
|
1463
|
+
end
|
|
1464
|
+
|
|
1465
|
+
# Install package and try again
|
|
1466
|
+
tpkg = Tpkg.new(
|
|
1467
|
+
:file_system_root => testroot,
|
|
1468
|
+
:sources => [@pkgfile])
|
|
1469
|
+
tpkg.install([@pkgfile], PASSPHRASE)
|
|
1470
|
+
|
|
1471
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
1472
|
+
ENV.delete('TPKG_HOME')
|
|
1473
|
+
|
|
1474
|
+
# Installed and available
|
|
1475
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1476
|
+
status = Open4.popen4(
|
|
1477
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qXs #{query} " +
|
|
1478
|
+
"--source #{@pkgfile} " +
|
|
1479
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1480
|
+
stdin.close
|
|
1481
|
+
assert_equal(metadata.text, stdout.read,
|
|
1482
|
+
"--qXs #{query}, installed and available, stdout")
|
|
1483
|
+
assert_equal("", stderr.read,
|
|
1484
|
+
"--qXs #{query}, installed and available, stderr")
|
|
1485
|
+
end
|
|
1486
|
+
assert_equal(0, status.exitstatus,
|
|
1487
|
+
"--qXs #{query}, installed and available, exitstatus")
|
|
1488
|
+
end
|
|
1489
|
+
|
|
1490
|
+
# Installed, not available
|
|
1491
|
+
[File.basename(@pkgfile), metadata[:name]].each do |query|
|
|
1492
|
+
status = Open4.popen4(
|
|
1493
|
+
"#{RUBY} #{TPKG_EXECUTABLE} --qXs #{query} " +
|
|
1494
|
+
"--test-root #{testroot}") do |pid, stdin, stdout, stderr|
|
|
1495
|
+
stdin.close
|
|
1496
|
+
assert_equal("", stdout.read,
|
|
1497
|
+
"--qXs #{query}, not available, installed, stdout")
|
|
1498
|
+
assert_equal(
|
|
1499
|
+
"No packages matching '#{query}' available\n", stderr.read,
|
|
1500
|
+
"--qXs #{query}, not available, installed, stderr")
|
|
1501
|
+
end
|
|
1502
|
+
assert_equal(1, status.exitstatus,
|
|
1503
|
+
"--qXs #{query}, not available, installed, exitstatus")
|
|
1504
|
+
end
|
|
1505
|
+
end
|
|
1506
|
+
end
|
|
1507
|
+
|
|
1508
|
+
def test_qenv
|
|
1509
|
+
output = nil
|
|
1510
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1511
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1512
|
+
IO.popen("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --qenv") do |pipe|
|
|
1513
|
+
output = pipe.readlines
|
|
1514
|
+
end
|
|
1515
|
+
# Make sure the expected lines are there
|
|
1516
|
+
assert(output.any? {|line| line.include?('Operating System:')})
|
|
1517
|
+
assert(output.any? {|line| line.include?('Architecture:')})
|
|
1518
|
+
assert(output.any? {|line| line.include?('Tar:')})
|
|
1519
|
+
end
|
|
1520
|
+
|
|
1521
|
+
def test_qconf
|
|
1522
|
+
output = nil
|
|
1523
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1524
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1525
|
+
IO.popen("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --qconf") do |pipe|
|
|
1526
|
+
output = pipe.readlines
|
|
1527
|
+
end
|
|
1528
|
+
# Make sure the expected lines are there
|
|
1529
|
+
assert(output.any? {|line| line.include?('Base:')})
|
|
1530
|
+
assert(output.any? {|line| line.include?('Sources:')})
|
|
1531
|
+
assert(output.any? {|line| line.include?('Report server:')})
|
|
1532
|
+
end
|
|
1533
|
+
|
|
1534
|
+
def test_use_ssh_key
|
|
1535
|
+
# Test --use-ssh-key with argument
|
|
1536
|
+
error = nil
|
|
1537
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1538
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1539
|
+
Open3.popen3("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} -s shell.sourceforge.net --use-ssh-key no_such_file --no-sudo --version --test-root #{@testroot}") do |stdin, stdout, stderr|
|
|
1540
|
+
stdin.close
|
|
1541
|
+
error = stderr.readlines
|
|
1542
|
+
end
|
|
1543
|
+
# Make sure the expected lines are there
|
|
1544
|
+
assert(error.any? {|line| line.include?('Unable to read ssh key from no_such_file')})
|
|
1545
|
+
|
|
1546
|
+
# Test --use-ssh-key without argument
|
|
1547
|
+
output = nil
|
|
1548
|
+
error = nil
|
|
1549
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1550
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1551
|
+
Open3.popen3("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} -s shell.sourceforge.net --use-ssh-key --version --test-root #{@testroot}") do |stdin, stdout, stderr|
|
|
1552
|
+
stdin.close
|
|
1553
|
+
output = stdout.readlines
|
|
1554
|
+
error = stderr.readlines
|
|
1555
|
+
end
|
|
1556
|
+
# Make sure that tpkg didn't prompt for a password
|
|
1557
|
+
assert(!output.any? {|line| line.include?('SSH Password (leave blank if using ssh key):')})
|
|
1558
|
+
|
|
1559
|
+
# Just to make sure our previous test is valid, check that we are prompted
|
|
1560
|
+
# for a password if we don't specify --use-ssh-key
|
|
1561
|
+
output = nil
|
|
1562
|
+
error = nil
|
|
1563
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1564
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1565
|
+
Open3.popen3("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} -s shell.sourceforge.net --version --test-root #{@testroot}") do |stdin, stdout, stderr|
|
|
1566
|
+
stdin.close
|
|
1567
|
+
output = stdout.readlines
|
|
1568
|
+
error = stderr.readlines
|
|
1569
|
+
end
|
|
1570
|
+
# Make sure that tpkg did prompt for a password this time
|
|
1571
|
+
assert(output.any? {|line| line.include?('SSH Password (leave blank if using ssh key):')})
|
|
1572
|
+
end
|
|
1573
|
+
|
|
1574
|
+
def test_base
|
|
1575
|
+
# Test the --base switch
|
|
1576
|
+
output = nil
|
|
1577
|
+
Dir.mktmpdir('clibase') do |clibase|
|
|
1578
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1579
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1580
|
+
IO.popen("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --base #{clibase} --qconf") do |pipe|
|
|
1581
|
+
output = pipe.readlines
|
|
1582
|
+
end
|
|
1583
|
+
# Make sure the expected line is there
|
|
1584
|
+
baseline = output.find {|line| line.include?('Base: ')}
|
|
1585
|
+
assert_equal("Base: #{clibase}\n", baseline)
|
|
1586
|
+
end
|
|
1587
|
+
end
|
|
1588
|
+
|
|
1589
|
+
def test_base_precedence
|
|
1590
|
+
# Test precedence of various methods of setting base directory
|
|
1591
|
+
|
|
1592
|
+
# TPKG_HOME ends up set in our environment due to use of the tpkg library
|
|
1593
|
+
ENV.delete('TPKG_HOME')
|
|
1594
|
+
|
|
1595
|
+
FileUtils.mkdir_p(File.join(@testroot, Tpkg::DEFAULT_CONFIGDIR))
|
|
1596
|
+
File.open(File.join(@testroot, Tpkg::DEFAULT_CONFIGDIR, 'tpkg.conf'), 'w') do |file|
|
|
1597
|
+
file.puts "base = /confbase"
|
|
1598
|
+
end
|
|
1599
|
+
|
|
1600
|
+
output = nil
|
|
1601
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1602
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1603
|
+
# --base, TPKG_HOME and config file all set
|
|
1604
|
+
IO.popen("env TPKG_HOME=/envbase #{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --base /clibase --test-root #{@testroot} --qconf") do |pipe|
|
|
1605
|
+
output = pipe.readlines
|
|
1606
|
+
end
|
|
1607
|
+
# Make sure the expected line is there
|
|
1608
|
+
baseline = output.find {|line| line.include?('Base: ')}
|
|
1609
|
+
assert_equal("Base: #{File.join(@testroot, 'clibase')}\n", baseline)
|
|
1610
|
+
|
|
1611
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1612
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1613
|
+
# TPKG_HOME and config file all set
|
|
1614
|
+
IO.popen("env TPKG_HOME=/envbase #{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --test-root #{@testroot} --qconf") do |pipe|
|
|
1615
|
+
output = pipe.readlines
|
|
1616
|
+
end
|
|
1617
|
+
# Make sure the expected line is there
|
|
1618
|
+
baseline = output.find {|line| line.include?('Base: ')}
|
|
1619
|
+
assert_equal("Base: #{File.join(@testroot, 'envbase')}\n", baseline)
|
|
1620
|
+
|
|
1621
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1622
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1623
|
+
# Only config file set
|
|
1624
|
+
IO.popen("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --test-root #{@testroot} --qconf") do |pipe|
|
|
1625
|
+
output = pipe.readlines
|
|
1626
|
+
end
|
|
1627
|
+
# Make sure the expected line is there
|
|
1628
|
+
baseline = output.find {|line| line.include?('Base: ')}
|
|
1629
|
+
assert_equal("Base: #{File.join(@testroot, 'confbase')}\n", baseline)
|
|
1630
|
+
|
|
1631
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1632
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1633
|
+
# Nothing is set
|
|
1634
|
+
File.delete(File.join(@testroot, Tpkg::DEFAULT_CONFIGDIR, 'tpkg.conf'))
|
|
1635
|
+
IO.popen("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --test-root #{@testroot} --qconf") do |pipe|
|
|
1636
|
+
output = pipe.readlines
|
|
1637
|
+
end
|
|
1638
|
+
# Make sure the expected line is there
|
|
1639
|
+
baseline = output.find {|line| line.include?('Base: ')}
|
|
1640
|
+
assert_equal("Base: #{File.join(@testroot, Tpkg::DEFAULT_BASE)}\n", baseline)
|
|
1641
|
+
end
|
|
1642
|
+
|
|
1643
|
+
def test_test_root
|
|
1644
|
+
# Test the --test-root switch
|
|
1645
|
+
output = nil
|
|
1646
|
+
|
|
1647
|
+
# With --test-root the base directory will be /<testroot>/opt/tpkg
|
|
1648
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1649
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1650
|
+
IO.popen("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --test-root #{@testroot} --qconf") do |pipe|
|
|
1651
|
+
output = pipe.readlines
|
|
1652
|
+
end
|
|
1653
|
+
# Make sure the expected line is there
|
|
1654
|
+
baseline = output.find {|line| line.include?('Base: ')}
|
|
1655
|
+
assert_equal("Base: #{File.join(@testroot, Tpkg::DEFAULT_BASE)}\n", baseline)
|
|
1656
|
+
|
|
1657
|
+
# Without --test-root the base directory will be something else (depending
|
|
1658
|
+
# on what config files are on the system)
|
|
1659
|
+
# The File.join(blah) is roughly equivalent to '../bin/tpkg'
|
|
1660
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1661
|
+
IO.popen("#{RUBY} -I #{File.join(parentdir, 'lib')} #{File.join(parentdir, 'bin', 'tpkg')} --qconf") do |pipe|
|
|
1662
|
+
output = pipe.readlines
|
|
1663
|
+
end
|
|
1664
|
+
# This is a rather lame test, but we don't have any way to know how tpkg
|
|
1665
|
+
# is configured on the system on which the tests are running.
|
|
1666
|
+
baseline = output.find {|line| line.include?('Base: ')}
|
|
1667
|
+
assert_not_equal("Base: #{File.join(@testroot, Tpkg::DEFAULT_BASE)}\n", baseline)
|
|
1668
|
+
end
|
|
1669
|
+
|
|
1670
|
+
def test_compress
|
|
1671
|
+
Dir.mktmpdir('pkgdir') do |pkgdir|
|
|
1672
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(pkgdir, 'tpkg.xml'))
|
|
1673
|
+
|
|
1674
|
+
parentdir = File.dirname(File.dirname(__FILE__))
|
|
1675
|
+
|
|
1676
|
+
# The argument to the --compress switch should be optional
|
|
1677
|
+
Dir.mktmpdir('outdir') do |outdir|
|
|
1678
|
+
system("#{RUBY} #{File.join(parentdir, 'bin', 'tpkg')} --compress --make #{pkgdir} --out #{outdir}")
|
|
1679
|
+
pkgfile = Dir.glob(File.join(outdir, '*.tpkg')).first
|
|
1680
|
+
assert(['bz2', 'gzip'].include?(Tpkg::get_compression(pkgfile)))
|
|
1681
|
+
end
|
|
1682
|
+
|
|
1683
|
+
Dir.mktmpdir('outdir') do |outdir|
|
|
1684
|
+
system("#{RUBY} #{File.join(parentdir, 'bin', 'tpkg')} --compress gzip --make #{pkgdir} --out #{outdir}")
|
|
1685
|
+
pkgfile = Dir.glob(File.join(outdir, '*.tpkg')).first
|
|
1686
|
+
assert_equal('gzip', Tpkg::get_compression(pkgfile))
|
|
1687
|
+
end
|
|
1688
|
+
|
|
1689
|
+
Dir.mktmpdir('outdir') do |outdir|
|
|
1690
|
+
system("#{RUBY} #{File.join(parentdir, 'bin', 'tpkg')} --compress bz2 --make #{pkgdir} --out #{outdir}")
|
|
1691
|
+
pkgfile = Dir.glob(File.join(outdir, '*.tpkg')).first
|
|
1692
|
+
assert_equal('bz2', Tpkg::get_compression(pkgfile))
|
|
1693
|
+
end
|
|
1694
|
+
|
|
1695
|
+
# Invalid argument rejected
|
|
1696
|
+
Dir.mktmpdir('outdir') do |outdir|
|
|
1697
|
+
system("#{RUBY} #{File.join(parentdir, 'bin', 'tpkg')} --compress bogus --make #{pkgdir} --out #{outdir}")
|
|
1698
|
+
# tpkg should have bailed with an error
|
|
1699
|
+
assert_not_equal(0, $?.exitstatus)
|
|
1700
|
+
# And not created anything in the output directory
|
|
1701
|
+
assert_equal(2, Dir.entries(outdir).length)
|
|
1702
|
+
end
|
|
1703
|
+
end
|
|
1704
|
+
end
|
|
1705
|
+
|
|
1706
|
+
def teardown
|
|
1707
|
+
FileUtils.rm_rf(@testroot)
|
|
1708
|
+
FileUtils.rm_f(@pkgfile)
|
|
1709
|
+
end
|
|
1710
|
+
end
|
|
1711
|
+
|