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,805 @@
1
+ #
2
+ # Test tpkg's ability to handle package metadata
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+ require 'webrick'
7
+ require 'pathname'
8
+
9
+ class TpkgMetadataTests < Test::Unit::TestCase
10
+ include TpkgTests
11
+
12
+ def setup
13
+ Tpkg::set_prompt(false)
14
+
15
+ # temp dir that will automatically get deleted at end of test run, can be
16
+ # used for storing packages
17
+ @tempoutdir = Dir.mktmpdir('tempoutdir')
18
+
19
+ # Make up our regular test package
20
+ @pkgfile = make_package
21
+
22
+ # Copy the package into a directory to test directory-related operations
23
+ @pkgdir = Dir.mktmpdir('pkgdir')
24
+ FileUtils.cp(@pkgfile, @pkgdir)
25
+
26
+ # Make a test repository
27
+ @testbase = Dir.mktmpdir('testbase')
28
+ end
29
+
30
+ def test_metadata_from_package
31
+ metadata = Tpkg::metadata_from_package(@pkgfile)
32
+ assert_equal('testpkg', metadata[:name], 'metadata_from_package name')
33
+ assert_equal('1.0', metadata[:version], 'metadata_from_package version')
34
+ assert_equal(File.basename(@pkgfile), metadata[:filename], 'metadata_from_package filename attribute')
35
+ end
36
+
37
+ # FIXME: Seems a bit odd that this never directly calls
38
+ # metadata_xml_to_hash. Some of this should be moved to
39
+ # test_metadata_from_package and then this converted to test
40
+ # metadata_xml_to_hash directly.
41
+ def test_metadata_xml_to_hash
42
+ # FIXME: test allowed_versions
43
+ pkgfile = make_package(:output_directory => @tempoutdir, :dependencies => {'testpkg2' => {'minimum_version' => '1.0', 'maximum_version' => '3.0', 'minimum_package_version' => '1.5', 'maximum_package_version' => '2.5'}, 'testpkg3' => {}})
44
+ metadata = nil
45
+ assert_nothing_raised { metadata = Tpkg::metadata_from_package(pkgfile)}
46
+ assert_equal('testpkg', metadata[:name])
47
+ assert_equal('1.0', metadata[:version])
48
+ assert_equal('1', metadata[:package_version])
49
+ assert_equal(2, metadata[:dependencies].length)
50
+ metadata[:dependencies].each do |depreq|
51
+ if depreq[:name] == 'testpkg2'
52
+ assert_equal('1.0', depreq[:minimum_version])
53
+ assert_equal('3.0', depreq[:maximum_version])
54
+ assert_equal('1.5', depreq[:minimum_package_version])
55
+ assert_equal('2.5', depreq[:maximum_package_version])
56
+ assert_equal(:tpkg, depreq[:type])
57
+ assert_equal(6, depreq.length) # :name, :type and 4 version requirements
58
+ else
59
+ assert_equal('testpkg3', depreq[:name])
60
+ assert_equal(:tpkg, depreq[:type])
61
+ assert_equal(2, depreq.length) # :name and :type only
62
+ end
63
+ end
64
+ FileUtils.rm_f(pkgfile)
65
+
66
+ # FIXME
67
+ # Confirm an exception is thrown if a required field is missing
68
+ # Confirm no problem if an optional field is missing
69
+
70
+ # Check that the array fields are handled properly
71
+ os = ['os1', 'os2', 'os3']
72
+ pkgfile = make_package(:change => {'name' => 'ostest', 'operatingsystem' => os.join(',')})
73
+ metadata = Tpkg::metadata_from_package(pkgfile)
74
+ assert_equal(os, metadata[:operatingsystem])
75
+ FileUtils.rm_f(pkgfile)
76
+
77
+ arch = ['arch1', 'arch2', 'arch3']
78
+ pkgfile = make_package(:change => {'name' => 'archtest', 'architecture' => arch.join(',')})
79
+ metadata = Tpkg::metadata_from_package(pkgfile)
80
+ assert_equal(arch, metadata[:architecture])
81
+ FileUtils.rm_f(pkgfile)
82
+
83
+ # FIXME: files
84
+
85
+ extname = 'testext'
86
+ extdata = "This is a test of parsing an external\nwith multiple lines\nof data"
87
+ pkgfile = make_package(:change => { 'name' => 'externalpkg' }, :externals => { extname => { 'data' => extdata } })
88
+ metadata = Tpkg::metadata_from_package(pkgfile)
89
+ assert_equal(extname, metadata[:externals].first[:name])
90
+ assert_equal(extdata, metadata[:externals].first[:data])
91
+ FileUtils.rm_f(pkgfile)
92
+
93
+ extname = 'testext'
94
+ extdata = "<element>Test external</element>\n<other>with XML data</other>"
95
+ pkgfile = make_package(:change => { 'name' => 'externalpkg' }, :externals => { extname => { 'data' => extdata } })
96
+ metadata = Tpkg::metadata_from_package(pkgfile)
97
+ assert_equal(extname, metadata[:externals].first[:name])
98
+ assert_equal(extdata, metadata[:externals].first[:data])
99
+ FileUtils.rm_f(pkgfile)
100
+ end
101
+
102
+ def test_metadata_from_directory
103
+ metadata = Tpkg::metadata_from_directory(@pkgdir)
104
+ assert_equal(1, metadata.length, 'metadata_from_directory number of results')
105
+ assert_equal('testpkg', metadata.first[:name], 'metadata_from_directory name')
106
+ assert_equal('1.0', metadata.first[:version], 'metadata_from_directory version')
107
+ assert_equal(File.basename(@pkgfile), metadata.first[:filename], 'metadata_from_directory filename attribute')
108
+ end
109
+
110
+ def test_extract_metadata
111
+ assert_nothing_raised('extract_metadata') { Tpkg::extract_metadata(@pkgdir) }
112
+ # we don't generate metadata.xml anymore
113
+ # assert(File.file?(File.join(@pkgdir, 'metadata.xml')), 'extract_metadata metadata file')
114
+ # assert_equal(0644, File.stat(File.join(@pkgdir, 'metadata.xml')).mode & 07777, 'extract_metadata metadata file permissions')
115
+ # metadata_xml = nil
116
+ # assert_nothing_raised('extract_metadata metadata load') { metadata_xml = REXML::Document.new(File.open(File.join(@pkgdir, 'metadata.xml'))) }
117
+ # assert_equal(1, metadata_xml.elements.to_a('/tpkg_metadata/tpkg/name').size, 'extract_metadata name count')
118
+ # assert_equal('testpkg', metadata_xml.elements['/tpkg_metadata/tpkg/name'].text, 'extract_metadata name')
119
+ # assert_equal(File.basename(@pkgfile), metadata_xml.elements['/tpkg_metadata/tpkg'].attributes['filename'], 'extract_metadata filename attribute')
120
+
121
+ # YAML stuff
122
+ assert(File.file?(File.join(@pkgdir, 'metadata.yml')), 'extract_metadata metadata file')
123
+ assert_equal(0644, File.stat(File.join(@pkgdir, 'metadata.yml')).mode & 07777, 'extract_metadata metadata file permissions')
124
+ metadata_contents = File.read(File.join(@pkgdir, 'metadata.yml'))
125
+ metadata = Metadata::get_pkgs_metadata_from_yml_doc(metadata_contents)
126
+ assert_equal(1, metadata['testpkg'].size, 'extract_metadata name and count')
127
+ assert_equal(File.basename(@pkgfile), metadata['testpkg'].first[:filename], 'extract_metadata filename attribute')
128
+ end
129
+
130
+ def test_prep_metadata
131
+ # Add another package in the package directory to make the test a
132
+ # little more realistic
133
+ pkgfile2 = make_package(:change => {'name' => 'testpkg2', 'version' => '2.0'})
134
+ FileUtils.mv(pkgfile2, @pkgdir)
135
+ pkgfile2 = File.join(@pkgdir, File.basename(pkgfile2))
136
+
137
+ Tpkg::extract_metadata(@pkgdir)
138
+
139
+ # Source as filename
140
+ Dir.mktmpdir('testbase') do |testbase|
141
+ tpkg = Tpkg.new(:base => testbase, :sources => [@pkgfile])
142
+ assert_nothing_raised { tpkg.prep_metadata }
143
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg'].length)
144
+ # The metadata in the package is XML as produced by make_package. The
145
+ # metadata extracted by prep_metadata came from the metadata.yml file
146
+ # produced by extract_metadata. Someday we should implement a
147
+ # reasonable == in the Metadata class, but in the meantime check that
148
+ # they look similar by checking the name element.
149
+ assert_equal(Tpkg::metadata_from_package(@pkgfile)[:name],
150
+ tpkg.instance_variable_get(:@metadata)['testpkg'].first[:name])
151
+ end
152
+
153
+ # Source as directory
154
+ Dir.mktmpdir('testbase') do |testbase|
155
+ tpkg = Tpkg.new(:base => testbase, :sources => [@pkgdir])
156
+ assert_nothing_raised { tpkg.prep_metadata }
157
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg'].length)
158
+ assert_equal(Tpkg::metadata_from_package(@pkgfile)[:name],
159
+ tpkg.instance_variable_get(:@metadata)['testpkg'].first[:name])
160
+ end
161
+
162
+ # Source as relative directory
163
+ Dir.mktmpdir('testbase') do |testbase|
164
+ tpkg = Tpkg.new(:base => testbase,
165
+ :sources => [Pathname.new(@pkgdir).relative_path_from(Pathname.getwd).to_s])
166
+ assert_nothing_raised { tpkg.prep_metadata }
167
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg'].length)
168
+ assert_equal(Tpkg::metadata_from_package(@pkgfile)[:name],
169
+ tpkg.instance_variable_get(:@metadata)['testpkg'].first[:name])
170
+ end
171
+
172
+ # Source as URI
173
+
174
+ s = WEBrick::HTTPServer.new(:Port => 3500, :DocumentRoot => @pkgdir)
175
+ # There may be an easier way to push WEBrick into the background, but
176
+ # the WEBrick docs are mostly non-existent so I'm taking the quick and
177
+ # dirty route.
178
+ t = Thread.new { s.start }
179
+
180
+ source = 'http://localhost:3500/'
181
+
182
+ Dir.mktmpdir('testbase') do |testbase|
183
+ tpkg = Tpkg.new(:base => testbase, :sources => [source])
184
+
185
+ assert_nothing_raised { tpkg.prep_metadata }
186
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg'].length)
187
+ assert_equal(Tpkg::metadata_from_package(@pkgfile)[:name], tpkg.instance_variable_get(:@metadata)['testpkg'].first[:name])
188
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg2'].length)
189
+ assert_equal(Tpkg::metadata_from_package(pkgfile2)[:name], tpkg.instance_variable_get(:@metadata)['testpkg2'].first[:name])
190
+ pkgs = tpkg.instance_variable_get(:@metadata).collect {|m| m[1]}.flatten
191
+ assert_equal(2, pkgs.length)
192
+ end
193
+
194
+ # Test when the package directory isn't at the root of the web
195
+ # server hierarchy
196
+ Dir.mkdir(File.join(@pkgdir, 'testdir'))
197
+ FileUtils.mv(File.join(@pkgdir, 'metadata.yml'), File.join(@pkgdir, 'testdir', 'metadata.yml'))
198
+
199
+ Dir.mktmpdir('testbase') do |testbase|
200
+ # With a trailing / on the URL
201
+ tpkg = Tpkg.new(:base => testbase, :sources => [source + 'testdir/'])
202
+ assert_nothing_raised { tpkg.prep_metadata }
203
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg'].length)
204
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg2'].length)
205
+ pkgs = tpkg.instance_variable_get(:@metadata).collect {|m| m[1]}.flatten
206
+ nonnativepkgs = pkgs.select do |pkg|
207
+ pkg[:source] != :native_installed && pkg[:source] != :native_available
208
+ end
209
+ assert_equal(2, nonnativepkgs.length)
210
+ end
211
+
212
+ Dir.mktmpdir('testbase') do |testbase|
213
+ # Without a trailing / on the URL
214
+ tpkg = Tpkg.new(:base => testbase, :sources => [source + 'testdir'])
215
+ assert_nothing_raised { tpkg.prep_metadata }
216
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg'].length)
217
+ assert_equal(1, tpkg.instance_variable_get(:@metadata)['testpkg2'].length)
218
+ pkgs = tpkg.instance_variable_get(:@metadata).collect {|m| m[1]}.flatten
219
+ nonnativepkgs = pkgs.select do |pkg|
220
+ pkg[:source] != :native_installed && pkg[:source] != :native_available
221
+ end
222
+ assert_equal(2, nonnativepkgs.length)
223
+ end
224
+
225
+ s.shutdown
226
+ t.kill
227
+
228
+ # No exception thrown if source is a non-existent directory
229
+ # FIXME: check stderr for warning
230
+ Dir.mktmpdir('testbase') do |testbase|
231
+ tpkg = Tpkg.new(:base => testbase, :sources => ['/path/does/not/exist'])
232
+ assert_nothing_raised { tpkg.prep_metadata }
233
+ assert_equal(0, tpkg.instance_variable_get(:@metadata).length)
234
+ end
235
+ # No exception thrown if source is a relative URI
236
+ # FIXME: check stderr for warning
237
+ Dir.mktmpdir('testbase') do |testbase|
238
+ tpkg = Tpkg.new(:base => testbase, :sources => ['relative/uri'])
239
+ assert_nothing_raised { tpkg.prep_metadata }
240
+ assert_equal(0, tpkg.instance_variable_get(:@metadata).length)
241
+ end
242
+ end
243
+
244
+ def test_load_available_packages
245
+ # Add another package in the package directory to make the test a
246
+ # little more realistic
247
+ pkgfile2 = make_package(:change => {'name' => 'testpkg2', 'version' => '2.0'})
248
+ FileUtils.mv(pkgfile2, @pkgdir)
249
+ pkgfile2 = File.join(@pkgdir, File.basename(pkgfile2))
250
+
251
+ Tpkg::extract_metadata(@pkgdir)
252
+
253
+ s = WEBrick::HTTPServer.new(:Port => 3500, :DocumentRoot => @pkgdir)
254
+ # There may be an easier way to push WEBrick into the background, but
255
+ # the WEBrick docs are mostly non-existent so I'm taking the quick and
256
+ # dirty route.
257
+ t = Thread.new { s.start }
258
+
259
+ Dir.mktmpdir('testbase') do |testbase|
260
+ source = 'http://localhost:3500/'
261
+ tpkg = Tpkg.new(:base => testbase, :sources => [source])
262
+
263
+ assert_nothing_raised { tpkg.load_available_packages('testpkg') }
264
+ assert_equal(1, tpkg.instance_variable_get(:@available_packages)['testpkg'].length)
265
+ expected = Tpkg::metadata_from_package(@pkgfile)
266
+ actual = tpkg.instance_variable_get(:@available_packages)['testpkg'].first[:metadata]
267
+ assert_equal(expected.to_hash, actual.to_hash)
268
+ pkgs = tpkg.instance_variable_get(:@available_packages).collect {|m| m[1]}.flatten
269
+ assert_equal(1, pkgs.length)
270
+
271
+ assert_nothing_raised { tpkg.load_available_packages('testpkg2') }
272
+ assert_equal(1, tpkg.instance_variable_get(:@available_packages)['testpkg2'].length)
273
+ expected = Tpkg::metadata_from_package(pkgfile2)
274
+ actual = tpkg.instance_variable_get(:@available_packages)['testpkg2'].first[:metadata]
275
+ assert_equal(expected.to_hash, actual.to_hash)
276
+ pkgs = tpkg.instance_variable_get(:@available_packages).collect {|m| m[1]}.flatten
277
+ assert_equal(2, pkgs.length)
278
+
279
+ # Test with a package that isn't available
280
+ assert_nothing_raised { tpkg.load_available_packages('otherpkg') }
281
+ assert_equal(0, tpkg.instance_variable_get(:@available_packages)['otherpkg'].length)
282
+ end
283
+
284
+ s.shutdown
285
+ t.kill
286
+ end
287
+
288
+ def test_pkg_for_native_package
289
+ tpkg = Tpkg.new(:base => @testbase)
290
+ name = 'testpkg'
291
+ version = '1.0.1'
292
+ package_version = '5.6'
293
+ source = :native_installed
294
+ pkg = nil
295
+
296
+ # Test with everything specified
297
+ assert_nothing_raised { pkg = Tpkg.pkg_for_native_package(name, version, package_version, source) }
298
+ assert_equal(name, pkg[:metadata][:name])
299
+ assert_equal(version, pkg[:metadata][:version])
300
+ assert_equal(package_version, pkg[:metadata][:package_version])
301
+ assert_equal(source, pkg[:source])
302
+ # If source == :native_installed the :prefer flag should be set
303
+ assert_equal(true, pkg[:prefer])
304
+
305
+ # Test with package_version not specified, it should be optional
306
+ assert_nothing_raised { pkg = Tpkg.pkg_for_native_package(name, version, nil, source) }
307
+ assert_equal(name, pkg[:metadata][:name])
308
+ assert_equal(version, pkg[:metadata][:version])
309
+ assert_equal(nil, pkg[:metadata][:package_version])
310
+ assert_equal(source, pkg[:source])
311
+ assert_equal(true, pkg[:prefer])
312
+
313
+ # Test with source == :native_available, :prefer flag should not be set
314
+ assert_nothing_raised { pkg = Tpkg.pkg_for_native_package(name, version, package_version, :native_available) }
315
+ assert_equal(name, pkg[:metadata][:name])
316
+ assert_equal(version, pkg[:metadata][:version])
317
+ assert_equal(package_version, pkg[:metadata][:package_version])
318
+ assert_equal(:native_available, pkg[:source])
319
+ assert_equal(nil, pkg[:prefer])
320
+ end
321
+
322
+ def test_get_pkgs_metadata_from_yml_doc
323
+ metadatayaml = <<YAML
324
+ ---
325
+ name: pkgone
326
+ version: 1
327
+ maintainer: test@example.com
328
+ description: Package one
329
+ ---
330
+ name: pkgone
331
+ version: 2
332
+ maintainer: newuser@example.com
333
+ description: Updated package
334
+ ---
335
+ name: pkgtwo
336
+ version: 1
337
+ maintainer: otheruser@example.com
338
+ description: Package two
339
+ YAML
340
+
341
+ metadata = Metadata.get_pkgs_metadata_from_yml_doc(metadatayaml)
342
+ # Right overall data structure?
343
+ assert_kind_of(Hash, metadata)
344
+ # Both pkgone entries in the same hash key?
345
+ assert_equal(2, metadata['pkgone'].length)
346
+ # YAML parsed into right object?
347
+ firstpkgone = metadata['pkgone'].shift
348
+ assert_kind_of(Metadata, firstpkgone)
349
+ # Parsing looks reasonable?
350
+ assert_equal('pkgone', firstpkgone[:name])
351
+ # Just one pkgtwo entry in that hash key?
352
+ assert_equal(1, metadata['pkgtwo'].length)
353
+ # Object type and parsing looks reasonable?
354
+ pkgtwo = metadata['pkgtwo'].shift
355
+ assert_kind_of(Metadata, pkgtwo)
356
+ assert_equal('pkgtwo', pkgtwo[:name])
357
+
358
+ # Test the side-effect use case
359
+ metadata = {}
360
+ boguskey = 'Some bogus junk'
361
+ bogusvalue = ['a', 'b']
362
+ bogusvalue2 = ['1', '2']
363
+ metadata[boguskey] = bogusvalue.dup
364
+ metadata['pkgtwo'] = bogusvalue2.dup
365
+ Metadata.get_pkgs_metadata_from_yml_doc(metadatayaml, metadata)
366
+ # Make sure our boguskey hash entry was unchanged
367
+ assert_equal(bogusvalue, metadata[boguskey])
368
+ # Ensure the bogus entries we added to the pkgtwo entry were unchanged
369
+ assert_equal(bogusvalue2, metadata['pkgtwo'].shift(2))
370
+ # Metadata for pkgtwo was appended to our array?
371
+ pkgtwo = metadata['pkgtwo'].shift
372
+ assert_kind_of(Metadata, pkgtwo)
373
+ assert_equal('pkgtwo', pkgtwo[:name])
374
+ end
375
+
376
+ def test_instantiate_from_dir
377
+ Dir.mktmpdir('pkgdir') do |pkgdir|
378
+ yaml = <<YAML
379
+ name: pkgone
380
+ version: 1
381
+ maintainer: test@example.com
382
+ description: Package one
383
+ YAML
384
+ File.open(File.join(pkgdir, 'tpkg.yml'), 'w') do |file|
385
+ file.write yaml
386
+ end
387
+ metadata = Metadata.instantiate_from_dir(pkgdir)
388
+ assert_kind_of(Metadata, metadata)
389
+ assert_equal('pkgone', metadata[:name])
390
+ end
391
+
392
+ Dir.mktmpdir('pkgdir') do |pkgdir|
393
+ xml = <<XML
394
+ <tpkg>
395
+ <name>pkgone</name>
396
+ <version>1</version>
397
+ <maintainer>test@example.com</maintainer>
398
+ <description>Package one</description>
399
+ </tpkg>
400
+ XML
401
+ File.open(File.join(pkgdir, 'tpkg.xml'), 'w') do |file|
402
+ file.write xml
403
+ end
404
+ metadata = Metadata.instantiate_from_dir(pkgdir)
405
+ assert_kind_of(Metadata, metadata)
406
+ assert_equal('pkgone', metadata[:name])
407
+ end
408
+ end
409
+
410
+ def test_initialize
411
+ yaml = <<YAML
412
+ name: pkgone
413
+ version: 1
414
+ maintainer: test@example.com
415
+ description: Package one
416
+ YAML
417
+
418
+ metadata = Metadata.new(yaml, 'yml')
419
+ assert_equal(yaml, metadata.text)
420
+ assert_equal('yml', metadata.format)
421
+ assert_equal(nil, metadata.file)
422
+ assert_equal(nil, metadata.source)
423
+
424
+ file = Tempfile.new('metadata').path
425
+ metadata = Metadata.new(yaml, 'yml', file)
426
+ assert_equal(yaml, metadata.text)
427
+ assert_equal('yml', metadata.format)
428
+ assert_equal(file, metadata.file)
429
+ assert_equal(nil, metadata.source)
430
+
431
+ source = 'http://example.com/tpkg/'
432
+ metadata = Metadata.new(yaml, 'yml', file, source)
433
+ assert_equal(yaml, metadata.text)
434
+ assert_equal('yml', metadata.format)
435
+ assert_equal(file, metadata.file)
436
+ assert_equal(source, metadata.source)
437
+ end
438
+
439
+ def test_square_brackets
440
+ # This method is just a convenience proxy for to_hash, so only minimal
441
+ # testing is called for here
442
+ yaml = <<YAML
443
+ name: pkgone
444
+ version: 1
445
+ maintainer: test@example.com
446
+ description: Package one
447
+ dependencies:
448
+ - name: dep1
449
+ - name: dep2
450
+ YAML
451
+
452
+ metadata = Metadata.new(yaml, 'yml')
453
+ assert_equal('pkgone', metadata[:name])
454
+ assert_equal(1, metadata[:version])
455
+ assert_equal([{'name'=>'dep1', 'type'=>:tpkg},
456
+ {'name'=>'dep2', 'type'=>:tpkg}],
457
+ metadata[:dependencies])
458
+ end
459
+
460
+ def test_square_brackets_assign
461
+ # This method is just a convenience proxy for to_hash, so only minimal
462
+ # testing is called for here
463
+ yaml = <<YAML
464
+ name: pkgone
465
+ version: 1
466
+ maintainer: test@example.com
467
+ description: Package one
468
+ YAML
469
+
470
+ metadata = Metadata.new(yaml, 'yml')
471
+ metadata[:name] = 'pkgtwo'
472
+ assert_equal('pkgtwo', metadata[:name])
473
+ metadata[:version] = 2
474
+ assert_equal(2, metadata[:version])
475
+ metadata[:dependencies] = [{'name'=>'dep1', 'type'=>:tpkg},
476
+ {'name'=>'dep2', 'type'=>:tpkg}]
477
+ assert_equal([{'name'=>'dep1', 'type'=>:tpkg},
478
+ {'name'=>'dep2', 'type'=>:tpkg}],
479
+ metadata[:dependencies])
480
+ end
481
+
482
+ def test_to_hash
483
+ # FIXME
484
+ end
485
+
486
+ def test_write
487
+ Dir.mktmpdir('outputdir') do |outputdir|
488
+ yaml = <<YAML
489
+ name: pkgone
490
+ version: 1
491
+ maintainer: test@example.com
492
+ description: Package one
493
+ YAML
494
+ metadata = Metadata.new(yaml, 'yml')
495
+ metadata.write(outputdir)
496
+ # tpkg.yml there?
497
+ assert(File.file?(File.join(outputdir, 'tpkg.yml')))
498
+ # and nothing else?
499
+ assert_equal(3, Dir.entries(outputdir).length)
500
+ # tpkg.yml contains the right stuff?
501
+ filelines = File.readlines(File.join(outputdir, 'tpkg.yml'))
502
+ filelines.each {|line| line.chomp!}
503
+ assert(filelines.include?('--- ') || filelines.include?('---'))
504
+ assert(filelines.include?('name: pkgone'))
505
+ assert(filelines.include?('version: 1'))
506
+ assert(filelines.include?('maintainer: test@example.com'))
507
+ assert(filelines.include?('description: Package one'))
508
+ assert_equal(5, filelines.length)
509
+ end
510
+
511
+ Dir.mktmpdir('outputdir') do |outputdir|
512
+ xml = <<XML
513
+ <tpkg>
514
+ <name>pkgone</name>
515
+ <version>1</version>
516
+ <maintainer>test@example.com</maintainer>
517
+ <description>Package one</description>
518
+ </tpkg>
519
+ XML
520
+ metadata = Metadata.new(xml, 'xml')
521
+ metadata.write(outputdir)
522
+ # tpkg.yml there?
523
+ assert(File.file?(File.join(outputdir, 'tpkg.yml')))
524
+ # and nothing else?
525
+ assert_equal(3, Dir.entries(outputdir).length)
526
+ # tpkg.yml contains the right stuff?
527
+ filelines = File.readlines(File.join(outputdir, 'tpkg.yml'))
528
+ filelines.each {|line| line.chomp!}
529
+ # The xml to yaml conversion yields slightly different but semantically
530
+ # equivalent results to a direct dump of yaml
531
+ filelines.delete('')
532
+ assert(filelines.include?('--- ') || filelines.include?('---'))
533
+ assert(filelines.include?('name: pkgone'))
534
+ assert(filelines.include?('version: "1"') || filelines.include?("version: '1'"))
535
+ assert(filelines.include?('maintainer: test@example.com'))
536
+ assert(filelines.include?('description: Package one'))
537
+ assert(filelines.include?('files: {}'))
538
+ assert_equal(6, filelines.length)
539
+ end
540
+ end
541
+
542
+ def test_add_tpkg_version
543
+ # yaml, no version, from file
544
+ yaml = <<YAML
545
+ name: pkgone
546
+ version: 1
547
+ maintainer: test@example.com
548
+ description: Package one
549
+ YAML
550
+ Dir.mktmpdir('pkgdir') do |pkgdir|
551
+ File.open(File.join(pkgdir, 'tpkg.yml'), 'w') do |file|
552
+ file.write yaml
553
+ end
554
+ metadata = Metadata.instantiate_from_dir(pkgdir)
555
+ metadata.add_tpkg_version(Tpkg::VERSION)
556
+
557
+ # Added to in-memory data
558
+ assert_equal(Tpkg::VERSION, metadata[:tpkg_version])
559
+ # File updated
560
+ new_metadata = Metadata.instantiate_from_dir(pkgdir)
561
+ assert_equal(Tpkg::VERSION, new_metadata[:tpkg_version])
562
+ end
563
+
564
+ # yaml, correct version, from file
565
+ yaml_with_correct_version = <<YAML
566
+ name: pkgone
567
+ version: 1
568
+ maintainer: test@example.com
569
+ description: Package one
570
+ tpkg_version: #{Tpkg::VERSION}
571
+ YAML
572
+ Dir.mktmpdir('pkgdir') do |pkgdir|
573
+ File.open(File.join(pkgdir, 'tpkg.yml'), 'w') do |file|
574
+ file.write yaml_with_correct_version
575
+ end
576
+ metadata = Metadata.instantiate_from_dir(pkgdir)
577
+ metadata.add_tpkg_version(Tpkg::VERSION)
578
+
579
+ # In-memory data still correct
580
+ assert_equal(Tpkg::VERSION, metadata[:tpkg_version])
581
+ # File still correct
582
+ new_metadata = Metadata.instantiate_from_dir(pkgdir)
583
+ assert_equal(Tpkg::VERSION, new_metadata[:tpkg_version])
584
+ end
585
+
586
+ # yaml, incorrect version, from file
587
+ yaml_with_incorrect_version = <<YAML
588
+ name: pkgone
589
+ version: 1
590
+ maintainer: test@example.com
591
+ description: Package one
592
+ tpkg_version: 0
593
+ YAML
594
+ Dir.mktmpdir('pkgdir') do |pkgdir|
595
+ File.open(File.join(pkgdir, 'tpkg.yml'), 'w') do |file|
596
+ file.write yaml_with_incorrect_version
597
+ end
598
+ metadata = Metadata.instantiate_from_dir(pkgdir)
599
+ metadata.add_tpkg_version(Tpkg::VERSION)
600
+
601
+ # Version mismatch results in warning
602
+ # FIXME, how to check for warning?
603
+ # In-memory data remains incorrect
604
+ assert_equal(0, metadata[:tpkg_version])
605
+ # File remains incorrect
606
+ new_metadata = Metadata.instantiate_from_dir(pkgdir)
607
+ assert_equal(0, new_metadata[:tpkg_version])
608
+ end
609
+
610
+ # yaml, no version, from string
611
+ metadata = Metadata.new(yaml, 'yml')
612
+ metadata.add_tpkg_version(Tpkg::VERSION)
613
+ # Added to in-memory data
614
+ assert_equal(Tpkg::VERSION, metadata[:tpkg_version])
615
+
616
+ # xml, no version, from file
617
+ xml = <<XML
618
+ <tpkg>
619
+ <name>pkgone</name>
620
+ <version>1</version>
621
+ <maintainer>test@example.com</maintainer>
622
+ <description>Package one</description>
623
+ </tpkg>
624
+ XML
625
+ Dir.mktmpdir('pkgdir') do |pkgdir|
626
+ File.open(File.join(pkgdir, 'tpkg.xml'), 'w') do |file|
627
+ file.write xml
628
+ end
629
+ metadata = Metadata.instantiate_from_dir(pkgdir)
630
+ metadata.add_tpkg_version(Tpkg::VERSION)
631
+
632
+ # Added to in-memory data
633
+ assert_equal(Tpkg::VERSION, metadata[:tpkg_version])
634
+ # File updated
635
+ new_metadata = Metadata.instantiate_from_dir(pkgdir)
636
+ assert_equal(Tpkg::VERSION, new_metadata[:tpkg_version])
637
+ # FIXME: verify still complies with DTD?
638
+ end
639
+
640
+ # xml, correct version, from file
641
+ xml_with_correct_version = <<XML
642
+ <tpkg>
643
+ <name>pkgone</name>
644
+ <version>1</version>
645
+ <maintainer>test@example.com</maintainer>
646
+ <description>Package one</description>
647
+ <tpkg_version>#{Tpkg::VERSION}</tpkg_version>
648
+ </tpkg>
649
+ XML
650
+ Dir.mktmpdir('pkgdir') do |pkgdir|
651
+ File.open(File.join(pkgdir, 'tpkg.xml'), 'w') do |file|
652
+ file.write xml_with_correct_version
653
+ end
654
+ metadata = Metadata.instantiate_from_dir(pkgdir)
655
+ metadata.add_tpkg_version(Tpkg::VERSION)
656
+
657
+ # In-memory data still correct
658
+ assert_equal(Tpkg::VERSION, metadata[:tpkg_version])
659
+ # File still correct
660
+ new_metadata = Metadata.instantiate_from_dir(pkgdir)
661
+ assert_equal(Tpkg::VERSION, new_metadata[:tpkg_version])
662
+ # FIXME: verify still complies with DTD?
663
+ end
664
+
665
+ # xml, incorrect version, from file
666
+ xml_with_incorrect_version = <<XML
667
+ <tpkg>
668
+ <name>pkgone</name>
669
+ <version>1</version>
670
+ <maintainer>test@example.com</maintainer>
671
+ <description>Package one</description>
672
+ <tpkg_version>0</tpkg_version>
673
+ </tpkg>
674
+ XML
675
+ Dir.mktmpdir('pkgdir') do |pkgdir|
676
+ File.open(File.join(pkgdir, 'tpkg.xml'), 'w') do |file|
677
+ file.write xml_with_incorrect_version
678
+ end
679
+ metadata = Metadata.instantiate_from_dir(pkgdir)
680
+ metadata.add_tpkg_version(Tpkg::VERSION)
681
+
682
+ # Version mismatch results in warning
683
+ # FIXME, how to check for warning?
684
+ # In-memory data remains incorrect
685
+ assert_equal('0', metadata[:tpkg_version])
686
+ # File remains incorrect
687
+ new_metadata = Metadata.instantiate_from_dir(pkgdir)
688
+ assert_equal('0', new_metadata[:tpkg_version])
689
+ end
690
+
691
+ # xml, no version, from string
692
+ metadata = Metadata.new(xml, 'xml')
693
+ metadata.add_tpkg_version(Tpkg::VERSION)
694
+ # Added to in-memory data
695
+ assert_equal(Tpkg::VERSION, metadata[:tpkg_version])
696
+ end
697
+
698
+ def test_generate_package_filename
699
+ # FIXME
700
+ end
701
+
702
+ def test_validate
703
+ # FIXME
704
+ end
705
+
706
+ def test_verify_yaml
707
+ # FIXME
708
+ end
709
+
710
+ def test_verify_required_fields
711
+ # FIXME
712
+ end
713
+
714
+ def test_get_native_deps
715
+ # Metadata with no dependencies
716
+ yaml = <<YAML
717
+ name: pkgone
718
+ version: 1
719
+ maintainer: test@example.com
720
+ description: Package one
721
+ YAML
722
+ metadata = Metadata.new(yaml, 'yml')
723
+ assert_equal([], metadata.get_native_deps)
724
+ # Metadata with empty dependencies
725
+ yaml = <<YAML
726
+ name: pkgone
727
+ version: 1
728
+ maintainer: test@example.com
729
+ description: Package one
730
+ dependencies:
731
+ YAML
732
+ metadata = Metadata.new(yaml, 'yml')
733
+ assert_equal([], metadata.get_native_deps)
734
+ # Metadata with dependencies but none native
735
+ yaml = <<YAML
736
+ name: pkgone
737
+ version: 1
738
+ maintainer: test@example.com
739
+ description: Package one
740
+ dependencies:
741
+ - name: dep1
742
+ - name: dep2
743
+ YAML
744
+ metadata = Metadata.new(yaml, 'yml')
745
+ assert_equal([], metadata.get_native_deps)
746
+ # Metadata with native dependencies
747
+ yaml = <<YAML
748
+ name: pkgone
749
+ version: 1
750
+ maintainer: test@example.com
751
+ description: Package one
752
+ dependencies:
753
+ - name: dep1
754
+ - name: nativedep1
755
+ native: true
756
+ - name: nativedep2
757
+ native: true
758
+ YAML
759
+ metadata = Metadata.new(yaml, 'yml')
760
+ assert_equal([{'name'=>'nativedep1', 'native'=>true, 'type'=>:native},
761
+ {'name'=>'nativedep2', 'native'=>true, 'type'=>:native}],
762
+ metadata.get_native_deps)
763
+ end
764
+
765
+ def test_init_scripts
766
+ # FIXME
767
+ end
768
+ def test_init_links
769
+ pkg = nil
770
+ pkg2 = nil
771
+ Dir.mktmpdir('srcdir') do |srcdir|
772
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
773
+ FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
774
+ File.open(File.join(srcdir, 'reloc', 'myinit'), 'w') do |file|
775
+ file.puts('init script')
776
+ end
777
+ pkg = make_package(:change => { 'name' => 'a' }, :source_directory => srcdir, :files => { 'myinit' => { 'init' => {} } }, :remove => ['operatingsystem', 'architecture'])
778
+ pkg2 = make_package(:change => { 'name' => 'b' }, :source_directory => srcdir, :files => { 'myinit' => { 'init' => { 'levels' => '' } } }, :remove => ['operatingsystem', 'architecture'])
779
+ end
780
+ Dir.mktmpdir('testroot') do |testroot|
781
+ testbase = File.join(testroot, 'home', 'tpkg')
782
+ FileUtils.mkdir_p(testbase)
783
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
784
+ metadata = Tpkg::metadata_from_package(pkg)
785
+ metadata2 = Tpkg::metadata_from_package(pkg2)
786
+ links = tpkg.init_links(metadata)
787
+ links.each do |link, init_script|
788
+ # Not quite sure how to verify that link is valid without
789
+ # reproducing all of the code of init_links here
790
+ assert_equal(File.join(testroot, 'home', 'tpkg', 'myinit'), init_script)
791
+ end
792
+ # Test a package with an empty set of runlevels specified
793
+ assert(tpkg.init_links(metadata2).empty?)
794
+ end
795
+ FileUtils.rm_f(pkg)
796
+ FileUtils.rm_f(pkg2)
797
+ end
798
+
799
+ def teardown
800
+ FileUtils.rm_f(@pkgfile)
801
+ FileUtils.rm_rf(@pkgdir)
802
+ FileUtils.rm_rf(@testbase)
803
+ FileUtils.rm_rf(@tempoutdir)
804
+ end
805
+ end