tpkg 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/Portfile +39 -0
  6. data/Portfile.template +39 -0
  7. data/README.md +43 -0
  8. data/Rakefile +468 -18
  9. data/bin/gem2tpkg +2 -2
  10. data/bin/tpkg +18 -13
  11. data/bin/tpkg_uploader +132 -0
  12. data/ca.pem +1 -0
  13. data/control +7 -0
  14. data/depend +3 -0
  15. data/externals-etch/authorized_keys +40 -0
  16. data/externals-etch/group +9 -0
  17. data/externals-etch/iptables +38 -0
  18. data/externals-etch/limits +30 -0
  19. data/externals-etch/nfs +30 -0
  20. data/externals-etch/sudo +30 -0
  21. data/externals-etch/supplemental_groups +8 -0
  22. data/externals-etch/sysctl +30 -0
  23. data/externals-etch/user +41 -0
  24. data/externals/group +39 -0
  25. data/externals/supplemental_groups +48 -0
  26. data/externals/user +39 -0
  27. data/lib/tpkg.rb +260 -991
  28. data/lib/tpkg/os.rb +164 -0
  29. data/lib/tpkg/os/debian.rb +159 -0
  30. data/lib/tpkg/os/freebsd.rb +113 -0
  31. data/lib/tpkg/os/macosx.rb +113 -0
  32. data/lib/tpkg/os/redhat.rb +173 -0
  33. data/lib/tpkg/os/solaris.rb +101 -0
  34. data/lib/tpkg/os/windows.rb +26 -0
  35. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
  36. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
  37. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
  38. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
  39. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
  40. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
  41. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
  42. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
  43. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
  44. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
  45. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
  46. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
  47. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
  48. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
  49. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
  50. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
  51. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
  52. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
  53. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
  54. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
  55. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
  56. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
  57. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
  58. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
  59. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
  60. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
  61. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  62. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  63. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  64. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
  65. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  66. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
  67. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
  68. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
  69. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
  70. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
  71. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
  72. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
  73. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
  74. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
  75. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
  76. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
  77. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
  78. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
  79. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
  80. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
  81. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
  82. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
  83. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
  84. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
  85. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
  86. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
  87. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
  88. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
  89. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
  90. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
  91. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
  92. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
  93. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
  94. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
  95. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
  96. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
  97. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
  98. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
  99. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
  100. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
  101. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  102. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
  103. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  104. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
  105. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  106. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  107. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
  108. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
  109. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  110. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  111. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
  112. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
  113. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
  114. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
  115. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
  116. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
  117. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
  118. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
  119. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
  120. data/lib/tpkg/version.rb +3 -0
  121. data/man/man1/cpan2tpkg.1 +82 -0
  122. data/man/man1/gem2tpkg.1 +120 -0
  123. data/man/man1/tpkg.1 +411 -0
  124. data/pkginfo +8 -0
  125. data/postinstall.solaris +11 -0
  126. data/postremove.solaris +16 -0
  127. data/schema/schema-1.0.5.yml +0 -0
  128. data/schema/schema-1.0.6.yml +0 -0
  129. data/schema/schema-1.0.7.yml +0 -0
  130. data/schema/schema-1.0.8.yml +0 -0
  131. data/schema/schema-1.0.9.yml +0 -0
  132. data/schema/schema.yml +0 -0
  133. data/schema/tpkg-1.0.0.dtd +0 -0
  134. data/schema/tpkg-1.0.1.dtd +0 -0
  135. data/schema/tpkg-1.0.2.dtd +0 -0
  136. data/schema/tpkg-1.0.3.dtd +0 -0
  137. data/schema/tpkg-1.0.4.dtd +0 -0
  138. data/schema/tpkg-1.0.5.dtd +0 -0
  139. data/schema/tpkg-1.0.6.dtd +0 -0
  140. data/schema/tpkg-1.0.7.dtd +0 -0
  141. data/schema/tpkg-1.0.8.dtd +0 -0
  142. data/schema/tpkg-1.0.9.dtd +0 -0
  143. data/schema/tpkg.dtd +0 -0
  144. data/test/TODO +30 -0
  145. data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
  146. data/test/test_checksum.rb +53 -0
  147. data/test/test_compress.rb +55 -0
  148. data/test/test_conflict.rb +41 -0
  149. data/test/test_crontabs.rb +398 -0
  150. data/test/test_dependency.rb +1113 -0
  151. data/test/test_downgrade.rb +80 -0
  152. data/test/test_download.rb +95 -0
  153. data/test/test_encrypt.rb +136 -0
  154. data/test/test_filemetadata.rb +131 -0
  155. data/test/test_initscript.rb +93 -0
  156. data/test/test_install.rb +186 -0
  157. data/test/test_lock.rb +82 -0
  158. data/test/test_make.rb +410 -0
  159. data/test/test_metadata.rb +805 -0
  160. data/test/test_misc.rb +379 -0
  161. data/test/test_options.rb +1711 -0
  162. data/test/test_os.rb +193 -0
  163. data/test/test_os_debian.rb +99 -0
  164. data/test/test_os_freebsd.rb +89 -0
  165. data/test/test_os_macosx.rb +79 -0
  166. data/test/test_os_redhat.rb +124 -0
  167. data/test/test_os_solaris.rb +85 -0
  168. data/test/test_os_windows.rb +26 -0
  169. data/test/test_query.rb +134 -0
  170. data/test/test_remove.rb +539 -0
  171. data/test/test_tar.rb +99 -0
  172. data/test/test_unpack.rb +977 -0
  173. data/test/test_upgrade.rb +398 -0
  174. data/test/test_version.rb +54 -0
  175. data/test/testcmds/crontab +14 -0
  176. data/test/testcmds/debian/apt-cache +145 -0
  177. data/test/testcmds/debian/dpkg-query +16 -0
  178. data/test/testcmds/freebsd/pkg_info +13 -0
  179. data/test/testcmds/macosx/port +35 -0
  180. data/test/testcmds/redhat/rpmbuild +6 -0
  181. data/test/testcmds/redhat/yum +90 -0
  182. data/test/testcmds/solaris/pkginfo +25 -0
  183. data/test/testcmds/solaris/pkgutil +36 -0
  184. data/test/testpkg/reloc/encfile +2 -0
  185. data/test/testpkg/reloc/file +2 -0
  186. data/test/testpkg/reloc/precryptfile +1 -0
  187. data/test/testpkg/reloc/precryptfile.plaintext +3 -0
  188. data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
  189. data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
  190. data/test/testpkg/tpkg-default-perms.xml +28 -0
  191. data/test/testpkg/tpkg-default-perms.yml +20 -0
  192. data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
  193. data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
  194. data/test/testpkg/tpkg-nativedeps.yml +13 -0
  195. data/test/testpkg/tpkg-nofiles.xml +14 -0
  196. data/test/testpkg/tpkg-nofiles.yml +9 -0
  197. data/test/testpkg/tpkg.xml +35 -0
  198. data/test/testpkg/tpkg.yml +25 -0
  199. data/test/tpkgtest.rb +300 -0
  200. data/tpkg.conf +16 -0
  201. data/tpkg.gemspec +24 -0
  202. data/tpkg.spec +28 -0
  203. data/tpkg.xml +17 -0
  204. data/tpkg_profile.sh +32 -0
  205. metadata +306 -31
@@ -0,0 +1,398 @@
1
+ #
2
+ # Test tpkg's ability to upgrade packages
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+
7
+ # Note that all first-time installs in this file are done using the upgrade
8
+ # method to ensure that it works in that capacity. (Elsewhere in the test
9
+ # suite first-time installs are done with the install method.)
10
+
11
+ class TpkgUpgradeTests < Test::Unit::TestCase
12
+ include TpkgTests
13
+
14
+ def setup
15
+ Tpkg::set_prompt(false)
16
+
17
+ @pkgfiles = []
18
+ ['a', 'b'].each do |pkgname|
19
+ # Make sure the files in the a packages don't conflict with
20
+ # the b packages
21
+ Dir.mktmpdir('srcdir') do |srcdir|
22
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
23
+ FileUtils.mkdir(File.join(srcdir, 'reloc'))
24
+ File.open(File.join(srcdir, 'reloc', pkgname), 'w') do |file|
25
+ file.puts pkgname
26
+ end
27
+ # Make the 'b' packages depend on 'a' so that we ensure that we
28
+ # can upgrade a package on which other packages depend.
29
+ deps = {}
30
+ if pkgname == 'b'
31
+ deps['a'] = {}
32
+ end
33
+ ['1.0', '2.0'].each do |pkgver|
34
+ @pkgfiles << make_package(:change => {'name' => pkgname, 'version' => pkgver}, :source_directory => srcdir, :dependencies => deps, :remove => ['operatingsystem', 'architecture'])
35
+ end
36
+ end
37
+ end
38
+
39
+ # Create pkg c-1.2-3 and c-2.3-1
40
+ Dir.mktmpdir('srcdir') do |srcdir|
41
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
42
+ FileUtils.mkdir(File.join(srcdir, 'reloc'))
43
+ File.open(File.join(srcdir, 'reloc', 'c'), 'w') do |file|
44
+ file.puts "this file belong to c package"
45
+ end
46
+ @pkgfiles << make_package(:change => {'name' => 'c', 'version' => '1.2', 'package_version' => '3'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
47
+ @pkgfiles << make_package(:change => {'name' => 'c', 'version' => '2.3', 'package_version' => '1'}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
48
+ end
49
+
50
+ @testroot = Dir.mktmpdir('testroot')
51
+ @testbase = File.join(@testroot, 'home', 'tpkg')
52
+ FileUtils.mkdir_p(@testbase)
53
+ @tpkg = Tpkg.new(:file_system_root => @testroot, :base => File.join('home', 'tpkg'), :sources => @pkgfiles)
54
+ @tpkg.upgrade(['a=1.0', 'b=1.0'], PASSPHRASE)
55
+ end
56
+
57
+ # pkg ordera-1 and orderb-1 are installed. Package orderb depends on ordera.
58
+ # Now if we were to upgrade orderb-1 to orderb-2, which depends on ordera-2, then
59
+ # tpkg should do things in the following order:
60
+ # remove orderb-1, remove ordera-1, install ordera-2, install orderb-2
61
+ def test_upgrade_order
62
+ pkgfiles = []
63
+ Dir.mktmpdir('srcdir') do |srcdir|
64
+ # Create pkg ordera-1 and orderb-1
65
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
66
+ pkgfiles << make_package(:change => { 'name' => 'ordera', 'version' => '1' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
67
+ deps = {'ordera'=> {'minimum_version' => '1.0'}}
68
+ pkgfiles << make_package(:change => { 'name' => 'orderb', 'version' => '1' }, :source_directory => srcdir, :dependencies => deps, :remove => ['operatingsystem', 'architecture'])
69
+
70
+ # Create pkg ordera-2, which has a file called pkga2
71
+ FileUtils.mkdir(File.join(srcdir, 'reloc'))
72
+ File.open(File.join(srcdir, 'reloc', 'pkga2'), 'w') do |file|
73
+ file.puts "Hello world"
74
+ end
75
+ pkgfiles << make_package(:change => { 'name' => 'ordera', 'version' => '2' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
76
+ FileUtils.rm(File.join(srcdir, 'reloc', 'pkga2'))
77
+
78
+ # Create pkg orderb-2, which test that a file called pkga2 exists. We will use this
79
+ # to ensure that during the upgrade, pkg b-2 is installed after pkg a-2
80
+ deps = {'ordera'=> {'minimum_version' => '2.0'}}
81
+ File.open(File.join(srcdir, 'preinstall'), 'w') do |scriptfile|
82
+ scriptfile.puts('#!/bin/sh')
83
+ # Test that tpkg set $TPKG_HOME before running the script
84
+ scriptfile.puts('ls "$TPKG_HOME"/pkga2 || exit 1')
85
+ end
86
+ File.chmod(0755, File.join(srcdir, 'preinstall'))
87
+ pkgfiles << make_package(:change => { 'name' => 'orderb', 'version' => '2' }, :source_directory => srcdir, :dependencies => deps, :remove => ['operatingsystem', 'architecture'])
88
+ end
89
+
90
+ tpkg = Tpkg.new(:file_system_root => @testroot, :base => File.join('home', 'tpkg'), :sources => pkgfiles)
91
+ tpkg.upgrade(['ordera=1.0', 'orderb=1.0'], PASSPHRASE)
92
+
93
+ assert_nothing_raised { tpkg.upgrade(['orderb']) }
94
+
95
+ pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
96
+ end
97
+
98
+ def test_upgrade
99
+ assert_nothing_raised { @tpkg.upgrade(['a']) }
100
+ # Should have two packages installed: a-2.0 and b-1.0
101
+ metadata = @tpkg.metadata_for_installed_packages
102
+ assert_equal(2, metadata.length)
103
+ apkg = nil
104
+ bpkg = nil
105
+ metadata.each do |m|
106
+ if m[:name] == 'a'
107
+ apkg = m
108
+ elsif m[:name] == 'b'
109
+ bpkg = m
110
+ end
111
+ end
112
+ assert_not_nil(apkg)
113
+ assert_equal('2.0', apkg[:version])
114
+ assert_not_nil(bpkg)
115
+ assert_equal('1.0', bpkg[:version])
116
+
117
+ assert_nothing_raised { @tpkg.upgrade }
118
+ # Should have two packages installed: a-2.0 and b-2.0
119
+ metadata = @tpkg.metadata_for_installed_packages
120
+ assert_equal(2, metadata.length)
121
+ apkg = nil
122
+ bpkg = nil
123
+ metadata.each do |m|
124
+ if m[:name] == 'a'
125
+ apkg = m
126
+ elsif m[:name] == 'b'
127
+ bpkg = m
128
+ end
129
+ end
130
+ assert_not_nil(apkg)
131
+ assert_equal('2.0', apkg[:version])
132
+ assert_not_nil(bpkg)
133
+ assert_equal('2.0', bpkg[:version])
134
+
135
+ # These test cases are for: Can't upgrade if package has higher version
136
+ # number but lower package version number
137
+ # install c-1.2-3
138
+ assert_nothing_raised{@tpkg.upgrade(['c=1.2'], PASSPHRASE)}
139
+ metadata = @tpkg.metadata_for_installed_packages
140
+ assert_equal(3, metadata.length)
141
+ # upgrade to c-2.3-1
142
+ assert_nothing_raised{@tpkg.upgrade(['c'], PASSPHRASE)}
143
+ metadata = @tpkg.metadata_for_installed_packages
144
+ cpkg = nil
145
+ metadata.each do |m|
146
+ if m[:name] == 'c'
147
+ assert_equal('2.3', m[:version])
148
+ end
149
+ end
150
+ end
151
+
152
+ # Test an upgrade using a filename rather than a package spec ('a')
153
+ def test_upgrade_by_filename
154
+ a2pkgfile = @pkgfiles.find {|pkgfile| pkgfile =~ /a-2.0/}
155
+ assert_nothing_raised { @tpkg.upgrade([a2pkgfile]) }
156
+ # Should have two packages installed: a-2.0 and b-1.0
157
+ metadata = @tpkg.metadata_for_installed_packages
158
+ assert_equal(2, metadata.length)
159
+ apkg = nil
160
+ bpkg = nil
161
+ metadata.each do |m|
162
+ if m[:name] == 'a'
163
+ apkg = m
164
+ elsif m[:name] == 'b'
165
+ bpkg = m
166
+ end
167
+ end
168
+ assert_not_nil(apkg)
169
+ assert_equal('2.0', apkg[:version])
170
+ assert_not_nil(bpkg)
171
+ assert_equal('1.0', bpkg[:version])
172
+ end
173
+
174
+ # Test upgrading all packages by passing no arguments to upgrade
175
+ def test_upgrade_all
176
+ assert_nothing_raised { @tpkg.upgrade }
177
+ # Should have two packages installed: a-2.0 and b-2.0
178
+ metadata = @tpkg.metadata_for_installed_packages
179
+ assert_equal(2, metadata.length)
180
+ apkg = nil
181
+ bpkg = nil
182
+ metadata.each do |m|
183
+ if m[:name] == 'a'
184
+ apkg = m
185
+ elsif m[:name] == 'b'
186
+ bpkg = m
187
+ end
188
+ end
189
+ assert_not_nil(apkg)
190
+ assert_equal('2.0', apkg[:version])
191
+ assert_not_nil(bpkg)
192
+ assert_equal('2.0', bpkg[:version])
193
+ end
194
+
195
+ def test_upgrade_with_externals_add
196
+ oldpkg = nil
197
+ newpkg = nil
198
+ extname1 = 'testext1'
199
+ extdata1 = "This is a test of an external hook\nwith multiple lines\nof data"
200
+ Dir.mktmpdir('srcdir') do |srcdir|
201
+ # Older version has no external, newer version has external
202
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
203
+ oldpkg = make_package(:change => { 'name' => 'externalpkg', 'version' => '1' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
204
+ newpkg = make_package(:change => { 'name' => 'externalpkg', 'version' => '2' }, :externals => { extname1 => {'data' => extdata1} }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
205
+ end
206
+ # Make external scripts which write the data they receive to temporary
207
+ # files, so that we can verify the external scripts received the data
208
+ # properly.
209
+ exttmpfile1 = Tempfile.new('tpkgtest_external')
210
+ externalsdir = File.join(@testroot, 'usr', 'lib', 'tpkg', 'externals')
211
+ FileUtils.mkdir_p(externalsdir)
212
+ extscript1 = File.join(externalsdir, extname1)
213
+ File.open(extscript1, 'w') do |file|
214
+ file.puts('#!/bin/sh')
215
+ # Operation (install/remove)
216
+ file.puts("echo $2 >> #{exttmpfile1.path}")
217
+ # Data
218
+ file.puts("cat >> #{exttmpfile1.path}")
219
+ end
220
+ File.chmod(0755, extscript1)
221
+ # And run the test
222
+ assert_nothing_raised { @tpkg.upgrade([oldpkg], PASSPHRASE) }
223
+ assert_equal('', IO.read(exttmpfile1.path))
224
+ assert_nothing_raised { @tpkg.upgrade([newpkg], PASSPHRASE) }
225
+ assert_equal("install\n#{extdata1}", IO.read(exttmpfile1.path))
226
+ FileUtils.rm_f(oldpkg)
227
+ FileUtils.rm_f(newpkg)
228
+ end
229
+
230
+ def test_upgrade_with_externals_add_second
231
+ oldpkg = nil
232
+ newpkg = nil
233
+ extname1 = 'testext1'
234
+ extdata1 = "This is a test of an external hook\nwith multiple lines\nof data"
235
+ extname2 = 'testext2'
236
+ extdata2 = "This is a test of a different external hook\nwith multiple lines\nof different data"
237
+ Dir.mktmpdir('srcdir') do |srcdir|
238
+ # Older version has one external, newer version has same external plus an
239
+ # additional one
240
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
241
+ oldpkg = make_package(:change => { 'name' => 'externalpkg', 'version' => '1' }, :externals => { extname1 => {'data' => extdata1} }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
242
+ newpkg = make_package(:change => { 'name' => 'externalpkg', 'version' => '2' }, :externals => { extname1 => {'data' => extdata1}, extname2 => {'data' => extdata2} }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
243
+ end
244
+ # Make external scripts which write the data they receive to temporary
245
+ # files, so that we can verify the external scripts received the data
246
+ # properly.
247
+ exttmpfile1 = Tempfile.new('tpkgtest_external')
248
+ exttmpfile2 = Tempfile.new('tpkgtest_external')
249
+ externalsdir = File.join(@testroot, 'usr', 'lib', 'tpkg', 'externals')
250
+ FileUtils.mkdir_p(externalsdir)
251
+ extscript1 = File.join(externalsdir, extname1)
252
+ extscript2 = File.join(externalsdir, extname2)
253
+ File.open(extscript1, 'w') do |file|
254
+ file.puts('#!/bin/sh')
255
+ # Operation (install/remove)
256
+ file.puts("echo $2 >> #{exttmpfile1.path}")
257
+ # Data
258
+ file.puts("cat >> #{exttmpfile1.path}")
259
+ end
260
+ File.open(extscript2, 'w') do |file|
261
+ file.puts('#!/bin/sh')
262
+ # Operation (install/remove)
263
+ file.puts("echo $2 >> #{exttmpfile2.path}")
264
+ # Data
265
+ file.puts("cat >> #{exttmpfile2.path}")
266
+ end
267
+ File.chmod(0755, extscript1)
268
+ File.chmod(0755, extscript2)
269
+ # And run the test
270
+ assert_nothing_raised { @tpkg.upgrade([oldpkg], PASSPHRASE) }
271
+ assert_equal("install\n#{extdata1}", IO.read(exttmpfile1.path))
272
+ assert_equal('', IO.read(exttmpfile2.path))
273
+ assert_nothing_raised { @tpkg.upgrade([newpkg], PASSPHRASE) }
274
+ # The expectation is that since the old and new packages have the same
275
+ # extname1 external that it will not be run during the upgrade, and thus
276
+ # the extdata1 should only occur once in the tempfile.
277
+ assert_equal("install\n#{extdata1}", IO.read(exttmpfile1.path))
278
+ assert_equal("install\n#{extdata2}", IO.read(exttmpfile2.path))
279
+ FileUtils.rm_f(oldpkg)
280
+ FileUtils.rm_f(newpkg)
281
+ end
282
+
283
+ def test_upgrade_with_externals_different_data
284
+ oldpkg = nil
285
+ newpkg = nil
286
+ extname1 = 'testext1'
287
+ extdata1 = "This is a test of an external hook\nwith multiple lines\nof data"
288
+ extdata2 = "This is a test of an external hook\nwith multiple lines\nof different data"
289
+ Dir.mktmpdir('srcdir') do |srcdir|
290
+ # Both versions have an external with the same name but different data
291
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
292
+ oldpkg = make_package(:change => { 'name' => 'externalpkg', 'version' => '1' }, :externals => { extname1 => {'data' => extdata1} }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
293
+ newpkg = make_package(:change => { 'name' => 'externalpkg', 'version' => '2' }, :externals => { extname1 => {'data' => extdata2} }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
294
+ end
295
+ # Make external scripts which write the data they receive to temporary
296
+ # files, so that we can verify the external scripts received the data
297
+ # properly.
298
+ exttmpfile1 = Tempfile.new('tpkgtest_external')
299
+ externalsdir = File.join(@testroot, 'usr', 'lib', 'tpkg', 'externals')
300
+ FileUtils.mkdir_p(externalsdir)
301
+ extscript1 = File.join(externalsdir, extname1)
302
+ File.open(extscript1, 'w') do |file|
303
+ file.puts('#!/bin/sh')
304
+ # Operation (install/remove)
305
+ file.puts("echo $2 >> #{exttmpfile1.path}")
306
+ # Data
307
+ file.puts("cat >> #{exttmpfile1.path}")
308
+ end
309
+ File.chmod(0755, extscript1)
310
+ # And run the test
311
+ assert_nothing_raised { @tpkg.upgrade([oldpkg], PASSPHRASE) }
312
+ assert_equal("install\n#{extdata1}", IO.read(exttmpfile1.path))
313
+ assert_nothing_raised { @tpkg.upgrade([newpkg], PASSPHRASE) }
314
+ assert_equal("install\n#{extdata1}remove\n#{extdata1}install\n#{extdata2}", IO.read(exttmpfile1.path))
315
+ FileUtils.rm_f(oldpkg)
316
+ FileUtils.rm_f(newpkg)
317
+ end
318
+
319
+ # Install pkgA and pkgB, both of version 1.0. pkgB depends on pkgA, min and
320
+ # max version 1.0. Try to upgrade pkgA to 2.0. This should not be allowed.
321
+ def test_upgrade_with_strict_dependency
322
+ pkgfiles = []
323
+ Dir.mktmpdir('srcdir') do |srcdir|
324
+ # Create pkg stricta-1 and strictb-1
325
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
326
+ pkgfiles << make_package(:change => { 'name' => 'stricta', 'version' => '1.0' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
327
+ pkgfiles << make_package(:change => { 'name' => 'stricta', 'version' => '2.0' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
328
+ pkgfiles << make_package(:change => { 'name' => 'strictb', 'version' => '1.0' }, :source_directory => srcdir, :dependencies => {'stricta' => {'minimum_version' => '1.0', 'maximum_version' => '1.0'}}, :remove => ['operatingsystem', 'architecture'])
329
+ end
330
+
331
+ tpkg = Tpkg.new(:file_system_root => @testroot, :base => File.join('home', 'tpkg'), :sources => pkgfiles)
332
+ tpkg.upgrade(['stricta=1.0', 'strictb=1.0'], PASSPHRASE)
333
+ metadata = @tpkg.metadata_for_installed_packages
334
+
335
+ # Should not be able to upgrade stricta to 2.0
336
+ tpkg.upgrade(['stricta'])
337
+
338
+ metadata = @tpkg.metadata_for_installed_packages
339
+
340
+ apkg = nil
341
+ bpkg = nil
342
+ metadata.each do |m|
343
+ if m[:name] == 'stricta'
344
+ apkg = m
345
+ elsif m[:name] == 'strictb'
346
+ bpkg = m
347
+ end
348
+ end
349
+ # Package stricta should still be of version 1.0
350
+ assert_equal('1.0', apkg[:version])
351
+
352
+ pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
353
+ end
354
+
355
+ # b-1 depends on a-2
356
+ # b-2 depends on a-1
357
+ # Can we upgrade from b-1 to b-2?
358
+ def test_upgrade_with_dependency_rollback
359
+ pkgfiles = []
360
+ Dir.mktmpdir('srcdir') do |srcdir|
361
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
362
+ pkgfiles << make_package(:change => { 'name' => 'deprolla', 'version' => '1' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
363
+ pkgfiles << make_package(:change => { 'name' => 'deprolla', 'version' => '2' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
364
+ pkgfiles << make_package(:change => { 'name' => 'deprollb', 'version' => '1' }, :source_directory => srcdir, :dependencies => {'deprolla' => {'minimum_version' => '2', 'maximum_version' => '2'}}, :remove => ['operatingsystem', 'architecture'])
365
+ pkgfiles << make_package(:change => { 'name' => 'deprollb', 'version' => '2' }, :source_directory => srcdir, :dependencies => {'deprolla' => {'minimum_version' => '1', 'maximum_version' => '1'}}, :remove => ['operatingsystem', 'architecture'])
366
+ end
367
+
368
+ tpkg = Tpkg.new(:file_system_root => @testroot, :base => File.join('home', 'tpkg'), :sources => pkgfiles)
369
+ tpkg.upgrade(['deprollb=1.0'], PASSPHRASE)
370
+ metadata = @tpkg.metadata_for_installed_packages
371
+
372
+ tpkg.upgrade(['deprollb'])
373
+
374
+ metadata = @tpkg.metadata_for_installed_packages
375
+
376
+ apkg = nil
377
+ bpkg = nil
378
+ metadata.each do |m|
379
+ if m[:name] == 'deprolla'
380
+ apkg = m
381
+ elsif m[:name] == 'deprollb'
382
+ bpkg = m
383
+ end
384
+ end
385
+ # Package b should version 2
386
+ assert_equal('2', bpkg[:version])
387
+ # Package a should version 1
388
+ assert_equal('1', apkg[:version])
389
+
390
+ pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
391
+ end
392
+
393
+ def teardown
394
+ @pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
395
+ FileUtils.rm_rf(@testroot)
396
+ end
397
+ end
398
+
@@ -0,0 +1,54 @@
1
+ #
2
+ # Test the Version class
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+ require 'tpkg/versiontype'
7
+
8
+ class VersionTests < Test::Unit::TestCase
9
+
10
+ def test_version
11
+ assert(Version.new('1') == Version.new('1'))
12
+ assert(Version.new('1') == Version.new('1.0'))
13
+ assert(Version.new('.5') == Version.new('0.5'))
14
+ assert(Version.new('5.') == Version.new('5'))
15
+ assert(Version.new('5.') == Version.new('5.0'))
16
+
17
+ assert(Version.new('1') >= Version.new('1'))
18
+ assert(Version.new('1') >= Version.new('1.0'))
19
+
20
+ assert(Version.new('1') < Version.new('1.1'))
21
+ assert(Version.new('1.01') < Version.new('1.1'))
22
+ assert(Version.new('1.009') < Version.new('1.010'))
23
+ assert(Version.new('1') < Version.new('2'))
24
+ assert(Version.new('1.0') < Version.new('2.0'))
25
+ assert(Version.new('1.0') < Version.new('2.0.0'))
26
+ assert(Version.new('2.5') < Version.new('2.5.1'))
27
+ assert(Version.new('2.5.1') < Version.new('2.6'))
28
+ assert(Version.new('2.9') < Version.new('2.10'))
29
+
30
+ assert(Version.new('1') != Version.new('2'))
31
+ assert(Version.new('1') != Version.new('2.0'))
32
+ assert(Version.new('1..0') != Version.new('1'))
33
+ assert(Version.new('1..0') != Version.new('1.0'))
34
+ assert(Version.new('1..0') != Version.new('1.0.0'))
35
+
36
+ assert(Version.new('.5') < Version.new('5.0'))
37
+ assert(Version.new('.5') < Version.new('5'))
38
+
39
+ assert(Version.new('a') < Version.new('b'))
40
+ assert(Version.new('1.0a') < Version.new('1.0b'))
41
+ assert(Version.new('1.0') < Version.new('1.0b'))
42
+ assert(Version.new('1.0.a') < Version.new('1.0.b'))
43
+ assert(Version.new('1.9a') < Version.new('1.10b'))
44
+ assert(Version.new('1.9a.2') != Version.new('1.9.a.2'))
45
+ assert(Version.new('1.9a.2') < Version.new('1.10b.1'))
46
+
47
+ assert_nothing_raised {Version.new('0') <=> Version.new(0)}
48
+ assert(Version.new('0') == Version.new(0))
49
+
50
+ # The result of this comparison is meaningless, we just want to
51
+ # verify that it doesn't throw an exception
52
+ assert_nothing_raised { Version.new('1.a') <=> Version.new('1.1') }
53
+ end
54
+ end