Arch Linux helpers and parsers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.4 KiB

  1. package archlinux
  2. import (
  3. "bytes"
  4. "encoding/hex"
  5. "testing"
  6. )
  7. func TestReadSrcInfo(t *testing.T) {
  8. for _, test := range []struct {
  9. SrcInfo string
  10. Packages int
  11. MD5Sums int
  12. SHA256Sums int
  13. Depends int
  14. }{
  15. {testReadSrcInfoPwnypack, 1, 0, 1, 0},
  16. {testReadSrcInfoPythonPyJnius, 2, 1, 0, 2},
  17. } {
  18. build, err := ReadSrcInfo(bytes.NewBufferString(test.SrcInfo))
  19. if err != nil {
  20. t.Fatal(err)
  21. }
  22. t.Run(build.String(), func(t *testing.T) {
  23. if l := len(build.Packages); l != test.Packages {
  24. t.Fatalf(`expected %d packages, got %d`, test.Packages, l)
  25. }
  26. if l := len(build.MD5Sums); l != test.MD5Sums {
  27. t.Fatalf(`expected %d md5sums, got %d`, test.MD5Sums, l)
  28. }
  29. if l := len(build.SHA256Sums); l != test.SHA256Sums {
  30. t.Fatalf(`expected %d sha256sums, got %d`, test.SHA256Sums, l)
  31. }
  32. if len(build.MD5Sums) > 0 {
  33. t.Log("MD5", hex.EncodeToString(build.MD5Sums[0]))
  34. }
  35. if len(build.SHA256Sums) > 0 {
  36. t.Log("SHA256", hex.EncodeToString(build.SHA256Sums[0]))
  37. }
  38. t.Run("packages", func(t *testing.T) {
  39. for name, pkg := range build.Packages {
  40. t.Run(name, func(t *testing.T) {
  41. t.Log(pkg)
  42. if l := len(pkg.Depends); l != test.Depends {
  43. t.Fatalf(`expected %d dependencies, got %d`, test.Depends, l)
  44. }
  45. })
  46. }
  47. })
  48. })
  49. }
  50. }
  51. var (
  52. testReadSrcInfoPwnypack = `pkgbase = pwnypack
  53. pkgdesc = Official Certified Edible Dinosaurs CTF toolkit
  54. pkgver = 0.8.0
  55. pkgrel = 1
  56. url = https://github.com/edibledinos/pwnypack
  57. arch = any
  58. license = MIT
  59. makedepends = python
  60. depends = ipython
  61. depends = nasm
  62. depends = python
  63. depends = python-capstone
  64. depends = python-nose
  65. depends = python-six
  66. options = !emptydirs
  67. source = https://pypi.python.org/packages/0e/e5/7ea712cc0a2b37a1efc1ae314ae1c39438a16a70ac43e36f3d190911ce94/pwnypack-0.8.0.tar.gz
  68. sha256sums = 30d88155707a9b2a11aaf6bc8004dddc7c7545d8fa8f17b8d42de54e87a1b57d
  69. pkgname = pwnypack
  70. `
  71. testReadSrcInfoPythonPyJnius = `pkgbase = python-pyjnius
  72. pkgdesc = Python module to access Java class as Python class, using JNI.
  73. pkgver = 1.1.1
  74. pkgrel = 1
  75. url = https://github.com/kivy/pyjnius
  76. arch = any
  77. license = LGPL3
  78. source = pyjnius-1.1.1.tar.gz::https://github.com/kivy/pyjnius/tarball/1.1.1
  79. md5sums = 2d457e4761b27e6760cf54efb6201f17
  80. pkgname = python2-pyjnius
  81. depends = java-environment
  82. depends = python2
  83. pkgname = python-pyjnius
  84. depends = java-environment
  85. depends = python
  86. `
  87. )