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.

194 lines
33 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package archlinux
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "os"
  7. "testing"
  8. "maze.io/archlinux.v0/version"
  9. )
  10. type testReadNamer struct {
  11. name string
  12. io.Reader
  13. }
  14. func (r testReadNamer) Name() string {
  15. return r.name
  16. }
  17. func ExampleParsePackageName() {
  18. fmt.Println(ParsePackageName("go-2:1.9-1"))
  19. // Output: go 2:1.9-1 <nil>
  20. }
  21. func ExampleParsePackageArchiveName() {
  22. fmt.Println(ParsePackageArchiveName("go-2:1.9-1-x86_64.pkg.tar.xz"))
  23. // Output: go 2:1.9-1 x86_64 .pkg.tar.xz <nil>
  24. }
  25. // This example demonstrates how to load a package from disk
  26. func ExampleReadPackage() {
  27. f, err := os.Open("go-2:1.9-1-x86_64.pkg.tar.xz")
  28. if err != nil {
  29. fmt.Println("error opening package:", err)
  30. return
  31. }
  32. defer f.Close()
  33. pkg, err := ReadPackage(f)
  34. if err != nil {
  35. fmt.Println("error reading package:", err)
  36. return
  37. }
  38. fmt.Println(pkg, pkg.Description)
  39. }
  40. func testComparePackage(t *testing.T, a, b *Package) {
  41. t.Helper()
  42. if b.Name != a.Name {
  43. t.Fatalf(`expected package %q, got %q`, a.Name, b.Name)
  44. }
  45. if b.Version != a.Version {
  46. t.Fatalf(`expected version %q, got %q"`, a.Version, b.Version)
  47. }
  48. if b.Release != a.Release {
  49. t.Fatalf(`expected version %q, got %q"`, a.Release, b.Release)
  50. }
  51. if l := len(b.Arch); l != len(a.Arch) {
  52. t.Fatalf(`expected %d arch(s), got %d`, len(a.Arch), l)
  53. }
  54. if b.Arch[0] != a.Arch[0] {
  55. t.Fatalf(`expected arch %q, got %q`, a.Arch[0], b.Arch[0])
  56. }
  57. if b.Size != a.Size {
  58. t.Fatalf(`expected size %d, got %d`, a.Size, b.Size)
  59. }
  60. }
  61. func TestReadPackage(t *testing.T) {
  62. var tests = []struct {
  63. Name string
  64. io.Reader
  65. Package
  66. }{
  67. {"pkg.tar.bz2", bytes.NewBuffer(testReadPackageTarBz2), testReadPackage},
  68. {"pkg.tar.gz", bytes.NewBuffer(testReadPackageTarGz), testReadPackage},
  69. }
  70. for _, test := range tests {
  71. t.Run(test.Name, func(t *testing.T) {
  72. p, err := ReadPackage(testReadNamer{test.Name, test.Reader})
  73. if err != nil {
  74. t.Fatal(err)
  75. }
  76. testComparePackage(t, &test.Package, p)
  77. })
  78. }
  79. }
  80. var (
  81. testReadPackage = Package{
  82. Name: "imagemagick",
  83. Version: "6.9.9.15",
  84. Release: "1",
  85. Arch: []string{"x86_64"},
  86. Size: 9897984,
  87. }
  88. testReadPackageTarBz2 = []byte("\x42\x5a\x68\x39\x31\x41\x59\x26\x53\x59\x45\x5e\xb7\x73\x00\x02\x94\x7f\x94\xc8\x10\x02\x40\x68\x0b\xff\xf7\x7f\xbf\xdf\xc0\xff\xff\xff\xf0\x20\x00\x00\x04\x80\x08\x60\x08\xbf\x6f\x5d\xcb\xbd\x84\x3b\x8a\x3c\xa7\x9d\x41\xdd\x8c\x9d\x1d\x02\xa9\x6e\x0d\x13\x44\x69\xa2\x6c\x80\x46\xd2\x99\x20\x7a\x13\xd4\x6d\x40\x34\xc4\xd3\xd4\x00\xda\x6a\x69\xa0\xd4\xf4\x8d\x1a\x99\x34\x10\x4c\x53\xc9\xa8\xf4\x80\x36\xa1\xa0\x00\x68\x7a\x41\xa0\x34\x11\x4f\xd1\xa1\x15\x00\x0d\x34\xd0\xd0\x00\x00\x00\x00\x00\x00\x0c\xd2\x84\x2a\x9f\xe9\x92\x6a\x9f\x82\xa7\x9a\x86\xd3\x54\x7a\x99\x3d\x46\x43\x0d\x21\x88\xc9\x90\x01\x90\x71\x93\x26\x86\x23\x13\x46\x01\x18\x09\x84\x01\x80\x9a\x68\xd3\x23\x40\x30\x91\x40\x40\x11\xa0\x98\x53\xca\x64\xd2\x68\x34\x01\xa6\x83\x13\x40\x06\x8d\x1a\x79\xff\x7f\x77\x94\xd4\x56\x73\x9a\x44\x68\x24\x8d\xdb\x77\x17\x16\xcb\x6e\xf2\x92\x55\x46\x63\x49\x40\x3f\x9a\x76\x09\xf0\xe0\x03\xb5\x7d\xfd\xfd\x1c\xe9\x9a\x24\xaf\xca\x76\x63\x08\x63\x58\xd4\x87\x98\xc2\x10\x40\x09\x74\x09\x04\x10\x44\x43\x59\x40\x17\x12\xa3\x75\x12\x83\x44\x22\x04\x29\x2b\xd5\x2a\x80\x69\x92\x00\x0f\x24\x84\x04\x84\x08\x84\x46\xd1\xf4\xaa\xbf\xf2\x9c\x2e\x17\x07\xdf\xf8\x92\xf4\xcf\x08\x00\x3f\x51\xb7\x34\xed\x5b\x41\xd7\x76\x9a\xe8\x4d\x8f\x88\xc8\x54\x36\x10\x08\x28\x56\xdc\xef\x82\xc4\x3b\x8c\xcc\x19\x89\xac\x33\xca\x1a\x23\x26\x05\x06\xa6\xca\x37\x6a\x14\x12\x4b\x6b\x24\x30\x01\x49\xa1\xb4\xbf\x86\x28\x3b\x8b\x7e\x06\x1e\xc7\x0e\x3c\x22\xa6\xd8\x14\x62\x4b\x36\x07\xca\x21\xa0\x5b\x1a\xc5\xa2\x20\x07\x03\x00\x12\x19\x01\xd1\xd7\xf3\xe9\x4e\x33\xa7\x74\xa5\x03\x4b\x54\x08\x64\x00\xf0\xf4\x0b\x76\x72\x61\x63\x8a\xe5\xf2\x1d\x6b\xad\xf6\x43\x08\x8e\x58\x8b\x69\x14\xb1\x6b\xab\x25\xad\x97\x65\x2a\xbb\x65\xd2\xd8\x5a\x5a\x88\x08\x4a\x18\x12\x66\x4e\xbb\x11\x30\xeb\x61\x8b\xc0\xbf\x06\xa6\x2e\xe9\xec\x8a\x62\xed\xdc\x4b\x56\xb4\x74\xde\x86\xde\x15\x79\x1d\x4a\xa4\xbb\x33\x42\xd7\xbf\xcb\x77\x7c\x39\x4f\x2c\x1b\x65\x10\x86\x55\xaa\x88\xd9\x2a\x3b\x46\x31\x5a\xd4\x6a\x5a\xd8\x6e\x39\x24\xca\x45\xa0\x7e\x27\x0c\xc9\x5d\x5a\x2c\x93\x9c\x5e\xcd\x0d\xa9\x98\xb9\x2f\xa1\xd8\xd0\x15\x9a\x9c\x79\xa6\xae\xbb\x8c\x94\x63\x03\x5d\x96\xda\xfe\x06\x27\x84\x06\x13\xed\x4a\x25\x7e\xab\x98\x23\x23\x71\x7e\x98\xe8\xa3\x57\x14\xf7\x6a\xa8\x81\x4f\x2a\x46\x45\x1b\x91\xa8\xcd\x2a\xbc\x0c\x96\xe5\x22\x37\x39\x89\x6b\x72\x0b\xc3\x6b\x9d\xf5\x22\x4f\x48\x80\x38\xa9\x5a\xb8\x86\x2f\x43\x19\xc0\x58\x54\xb2\x72\x08\xbb\x33\x31\x47\x4a\x58\xc1\x08\x4a\x20\xa8\x47\x41\x50\xe0\x52\xa5\xe8\xb0\xe0\x85\x2e\xc8\xae\x20\x23\x40\x60\xce\x50\xbb\xb0\x85\xab\x28\x44\x95\x42\xc1\x0a\xc1\xa3\x43\x24\xb3\xa5\x0b\xc2\xbd\x61\x5a\xaa\x8a\x8b\x04\x88\xa1\x25\x91\x62\xc1\x2b\x56\x28\xb2\xce\x00\x84\x10\x8d\x53\x28\xf4\x57\x0d\x00\x13\x10\xee\x1d\xd9\x98\x38\x54\x01\x59\x67\xf7\xb1\xae\xdc\xb7\x80\x73\x70\xcd\xdc\x36\x78\x99\xd3\xba\x85\x3e\x4a\xa1\x79\x35\xa2\x4c\x0f\xa6\x26\x38\xa5\xe8\x37\xb6\x3e\x2c\x5c\x46\x11\x3d\x20\xc4\x21\xa0\x62\x39\xee\x4d\xff\x3f\xdf\x6a\x74\xb5\xa9\x08\x9a\xa0\x53\xbc\xa9\xa6\x3c\x6d\x16\x5d\x39\x59\x66\x57\x36\xda\x55\x1a\x4d\x0b\x15\x51\x22\x63\x46\x14\x14\x1f\x12\xb6\x69\x44\xa1\x1a\x63\xd9\x14\xd5\x14\x10\x50\x70\x60\x84\x28\x35\x12\xca\x4c\xf8\x72\x8e\x0d\x51\x8f\x08\x28\x6a\x3d\x50\x8a\xbe\xde\xfa\xce\x6d\x03\x0b\xd6\x64\x38\x44\x42\xf1\xf0\x8f\xd5\x33\x44\x33\x54\x43\xfa\x69\x4e\xff\x1d\x95\xab\xd0\x80\x43\x72\x94\xca\xad\xc1\x33\xa2\x2d\x63\x5b\x05\xb2\xce\xa2\xc2\x45\x2b\xd1\x6a\xac\x3e\x88\x9e\x3c\x37\x78\x2a\xd5\xb6\xee\xd5\x85\xf9\x34\xf1\xc3\x30\x15\x64\x5b\xc4\x0a\x85\x84\x5a\x40\x01\x0f\x29\x1d\x22\xce\xe5\x7d\x18\xab\x85\x27\xdf\x6c\x6c\x13\x3c\x57\x35\x05\x29\x47\x6f\xde\x80\x55\x92\x8c\xe4\x24\xb8\xb8\x13\x2a\x25\x80\xe3\xc6\x99\xe5\x7d\xe6\x97\xd8\x14\x0a\xc1\x92\xa8\xe1\x5e\x23\x0c\xf2\x7a\xb9\x39\x8f\x39\x0f\xb9\x4e\x2f\x05\xb3\xd3\x15\xb9\xa3\x63\x3c\x87\xbd\x40\x42\xe8\x42\x00\xb2\x8d\x3d\x76\xb8\xc5\x7f\x9c\x56\x39\xd9\x71\xd1\x5d\x9c\xd9\x69\xcb\x05\x2f\xb8\x80\x1b\x2d\x72\x24\x08\x02\x08\x47\x09\x95\xe6\x4b\xab\xaa\xe5\xc2\x2c\x82\x94\xa2\xd1\x1c\x49\x21\xe1\xeb\x53\x2d\xcc\xfb\x1a\xc2\x70\x4c\x08\x7c\xd0\x
  89. testReadPackageTarGz = []byte("\x1f\x8b\x08\x00\x2b\xf1\xcc\x59\x00\x03\xed\x58\x5b\x8f\xdb\xb6\x12\xde\x67\xff\x0a\x15\x7d\x0c\xa4\xd5\x5d\xd6\xa2\x2d\x7a\x0f\x72\x4e\xd3\x06\xcd\xe9\x39\x7d\x0b\x28\x89\x92\x19\xeb\xc2\x25\xa9\xb5\xd7\xbf\xfe\xcc\x50\xde\xae\x4c\xca\x71\x5e\xd2\x22\x80\x19\x04\x5e\xcd\x37\x1c\x0e\x87\xdf\x8c\x86\xf2\xde\xfc\xfb\xe5\xab\x5f\x7f\xfe\xed\xe6\x13\x0e\x1f\x46\x1a\xc7\xfa\x17\x86\xf9\x1b\x25\x51\x74\x13\x44\x41\x1a\x24\x49\x94\x25\xc1\x8d\x1f\xf8\x69\x9a\xdc\x38\xfe\xa7\x74\xea\x69\x8c\x52\x11\xe1\x38\x37\x62\x18\xd4\x87\xf4\x2e\xe1\x9f\xe9\xf8\xd2\x79\x49\x7b\x2a\x88\xa2\x95\x53\x3c\x3a\x1d\xd9\x52\xbe\x6d\x9c\xc4\xf3\xbd\x70\xf5\xa5\x33\x4a\xd6\x37\x4e\x0d\x52\xdc\xbf\xf3\x40\x85\x64\x43\xef\x04\x5e\x88\xe8\x5b\xa2\x9c\xb7\x94\x3b\x61\xe4\x84\xc1\x5d\x12\xdd\xc5\x89\xf3\xc7\x7f\x7e\x70\x42\x3f\xc8\x56\x60\xa6\x27\x1d\x75\xbe\x76\x58\x47\x1a\x0a\xff\x59\xb9\x45\x69\x41\xe4\x82\x14\x4c\x83\x30\xf5\x72\xf8\x17\x24\x6e\x80\xb2\x8a\xca\x12\x84\xdf\xf5\x93\xb2\xf3\xc0\xe8\x0e\xfc\xb9\xed\x48\xcf\xf8\xd8\x12\x85\xbe\x70\x31\x34\x82\x74\xab\x51\xb4\xa0\xbb\x51\x8a\xdf\xdd\xde\xee\x76\x3b\x6f\xb6\x80\x37\x88\xe6\x76\x55\x8c\xac\xad\x2a\xd8\x2a\xe8\x05\x89\x9f\x86\x7e\x94\x86\xc9\x8a\x93\x72\x0b\x9a\x42\xaf\xa4\x86\x9e\x0d\xce\xef\xc3\x7b\x22\x9d\xaf\x88\xc0\xdf\x6f\x89\x28\x37\x2d\xeb\xc7\x3d\x9a\xf9\x66\x25\xd9\x01\x2d\xe4\xeb\x3c\xcb\xd7\xf1\x0a\x51\x78\xdc\xaf\xd3\x77\x69\xbc\x6a\x59\x49\x7b\xbd\xbf\x12\x98\x35\x74\xab\x02\xac\x8f\x1c\x9e\xa9\x2a\x6f\x5f\xa1\x4b\xaf\xb5\x4b\x6e\x7a\x5b\x0e\x15\x15\xde\xbe\x6b\x3f\xac\xd4\x0e\x42\x5e\xd2\xaa\x68\x4b\x1b\xd8\xd9\x45\xc5\x76\x68\x2e\xa9\xe8\x90\x5d\x54\x62\x1d\xbd\xa4\xc3\x07\x88\xc6\xe3\x25\xad\xfb\x91\xf4\x8a\x1d\xf4\x61\xba\x8a\x14\xed\x45\xbb\x6a\x23\xa8\xdc\x0c\x6d\x75\x71\xb7\xea\x91\x5f\xb6\x06\x3a\x6e\x45\xdf\x93\x87\xf1\xa3\x54\x9b\xcd\x20\x95\x2c\x05\xe3\xea\xa3\xf4\x81\xb1\xd5\xb0\x9b\x5c\xad\x28\xa7\x7d\x05\xba\x2d\x2b\x5a\x55\xcd\x05\x65\x27\xc3\x13\x7c\xaf\x9e\x1f\xeb\xa1\x57\xe5\xd0\xd7\xac\x39\x55\xa1\x73\x25\xb4\x79\x2f\x4e\x9e\x05\xb9\xef\x9e\x05\x03\xfc\x96\xad\xcb\xca\xca\x6d\x07\x02\xdc\x7b\x86\x38\x15\xed\x37\x5f\x27\x5e\x98\x9e\xca\xbe\x02\x51\xb6\x1a\xb8\xfa\x4b\x3a\xcb\x2a\xb7\x1a\xca\x3b\xf0\x4d\x38\xa4\xaa\x18\x9e\x1f\x69\x1d\xd6\x83\xa0\xd3\xa7\x79\x32\x6f\x16\xb6\x69\xce\xcb\x67\x81\x23\x47\xce\x07\xa1\x4e\x26\xa0\xb7\x74\x2f\x26\xe5\xdf\xe0\xe1\xa7\x3f\x7f\x3f\xab\xf8\x9e\xd3\x26\x9c\x54\xff\xf5\x26\x5c\x54\x83\x70\xec\xba\x7a\xd2\xf9\xdf\xeb\x9f\xcf\xe9\x08\xf9\xd0\x4c\x4a\x6f\xff\xfb\xf2\x9c\x12\x9c\xe5\x71\xb5\x3f\x5f\xff\x72\x4e\x89\xf7\x47\x43\x6f\x7e\x3d\x6b\x68\x47\x0b\x7e\x74\xe9\xa7\xef\xdf\x9c\xf5\x89\xec\x26\xa5\x1f\x67\x96\xb0\x54\x5b\x7c\x3a\x15\x6a\x4e\x99\x7a\x7b\x63\xea\x8c\x5b\x96\x2a\x35\x95\x67\xa7\x78\x0a\x1c\x4f\xcb\x32\x01\x21\xb7\x64\x18\x62\x7b\x2d\x08\xa9\xbd\xa7\x7b\x61\x2f\xa3\xcf\xda\x36\x4a\x76\x0b\x32\xa0\xbf\x35\x1f\x52\x60\x43\x91\xfe\x72\x11\x9b\xa5\x87\xb5\x19\x38\xad\x53\xa1\x1c\x8b\xe3\x3b\xd1\x88\x53\x3b\xae\xfe\xe9\x57\xfb\x47\x0d\xef\xfb\x3f\x5e\xfd\xf2\xe3\xa7\xed\x00\xe7\xfd\x5f\x06\x8d\x1d\xfc\x04\x59\xf2\x57\xff\x97\x65\x7e\x8a\xfd\x5f\x18\x85\x59\x08\x9a\xd0\xff\x85\x61\x12\xfd\xcd\xfd\xdf\x8e\xbd\xef\x49\x5f\x9d\xd5\xbb\x84\x7f\xa6\x63\xea\x89\x18\x36\x3f\xb7\xfa\x6f\xdd\xa1\xe1\x1f\xef\xe4\x86\x84\x49\x2a\xc7\x0e\xb0\x22\xcf\xf3\xac\xaa\xb2\xac\x0a\x12\x1a\xa5\x91\x9f\x94\x75\x16\x67\x75\xb6\x8e\x6b\x42\x62\x5a\xd2\xba\xa2\x31\x25\x61\x9e\xd1\xb8\x5e\x57\x69\x9a\xc7\x80\x44\x34\xca\x53\x3f\x2a\xca\xa9\xf7\xa2\xfd\x03\xd8\xfa\xa2\x62\x52\x95\x27\x22\xdd\xe4\x9c\xe8\x94\x25\x29\x37\xf4\x44\x67\x43\xa1\x53\x9c\xeb\x48\xd6\xe8\x77\x0c\x64\x9f\xc4\x5c\x54\x50\x96\x66\xcf\xf0\x76\x92\xb3\xc7\x2f\x20\x81\xd5\x30\xb4\x73\x11\x9c\xbd\x62\x25\x00\x73\x45\xda\x71\xf5\x08\x21\x99\xcb\x0e\x8c\x43\xd3\x39\x13\xf0\x51\x34\x74\x6e\x0a\xff\x84\x8a\x3f\x17\x8d\x7c\x3f\x7f\xac\x68\x31\x36\x2b\xd6\xc3\xa2\x6d\x4b\xb1\x4a\x10\x28\x37\xa1\x17\x7a\x49\xe8\x46\xa7\xc0\x53\xc7\xe9\x6e\xe9\xa3\x80\x96\xd7\xc5\x96\xda\x4f\x83\x00\x1a\xe3\x13\x45\xa5\x04\x98\x88\xbd\x38\x73\xc3\x53\x64\x54\x03\x96\x7
  90. testReadPackageTarXz = []byte("\x1f\x9d\x90\x2e\xa0\x2c\x39\x92\xc4\x89\x91\x27\x00\x12\x2a\x5c\xc8\xb0\xa1\xc3\x87\x10\x23\x4a\x9c\x48\x11\x00\x8c\x8b\x30\x6c\xd0\xa0\x61\x11\x23\xc6\x8e\x1e\x61\x80\xf4\x38\xa3\xc6\x8c\x19\x00\x62\xcc\x88\x61\x23\x46\x0d\x93\x37\x6a\xc4\xb0\x18\x23\xa3\x8d\x1a\x00\x40\x88\xac\xc8\xb3\xa7\xcf\x9f\x40\xeb\xcc\xa1\x13\x46\x0e\x08\x10\x00\xe4\xbc\x79\x43\x07\x28\x44\xa5\x4c\x9d\x4a\x9d\x4a\xb5\xaa\xd5\xab\x58\xa9\x8e\x00\x71\xa4\x8c\x9b\x32\x72\xc2\xd0\x29\x43\x06\x84\x98\x3c\x20\xda\x84\x59\x53\x06\xce\x9a\x33\x20\x6a\xb8\x80\xe1\x42\x86\x82\xad\x42\xd3\xb8\x81\x6b\x66\x2d\xd8\xa5\x74\x40\xd8\x01\x3b\x27\xcd\x1b\x37\x20\x62\xd4\xb5\xbb\x75\x8a\x58\x10\x53\xda\x82\x90\x31\x63\x72\x0c\x1d\x26\x75\xd0\xa8\x01\xa2\x0a\x95\x21\x93\x61\xc4\xb8\xa1\xc0\xed\x19\x37\x61\xda\x94\x01\xd1\x03\x44\x1a\xb5\x67\xca\xc0\x4e\x33\x66\x4d\xe9\xb7\x62\xc2\xcc\x59\xdd\xfa\x75\x98\xd8\xb3\x6b\xdf\x3e\x33\xd8\x68\x6b\x1b\x2e\x72\x24\x77\xe1\xb2\x45\x8c\xe1\x64\xca\xcc\x19\xc3\x1a\x44\x10\xc4\xbe\x63\x0b\x4e\x53\xe6\x8e\xde\x33\x2f\xd4\xba\x49\x03\xa7\x0e\x1b\xb1\x86\x11\xc3\x51\x7a\x26\x6c\x1b\x05\x75\xe4\xb0\xa9\x8e\x86\x0e\x1d\x38\x3a\x5e\xbc\xb8\xc3\xdf\x45\x76\xd9\xbf\xd1\xb6\x86\x0b\x6f\xc8\x01\x9e\x02\x62\xd4\x91\x06\x1b\x64\x90\x21\x16\x6f\x89\xd5\x90\x91\x0c\x30\xcc\x60\x83\x0c\x35\x94\x16\x46\x6d\xbf\x81\x55\xdd\x75\x74\x1c\x66\x18\x08\x52\xbc\xa1\x86\x6e\x20\xf0\x50\x94\x89\xba\x01\x51\xd4\x18\x68\xb0\xa1\x57\x1d\x78\x10\x68\xa0\x0f\x0a\x14\xa6\x07\x84\x39\xe0\x90\xc3\x0d\x3d\xd2\xa0\xc0\x8b\x68\x54\x87\x07\x0e\x36\x7c\xa1\x91\x02\x32\x8e\xe1\xd5\x6e\xd5\x8d\x21\x54\x88\xef\xe5\x56\x5b\x1d\x70\x54\x57\x06\x1d\x63\xbc\x90\x04\x6c\x65\x34\x11\x60\x6d\x2d\xd8\xf0\xc2\x18\x6f\x44\x27\x87\x0b\x78\xb4\xc1\x06\x82\x1b\xae\x81\xa5\x96\x5c\x7a\x09\xa6\x98\x67\x08\x58\xe6\x99\x6f\xb0\x51\xe0\x1c\x6c\xba\x09\xe7\x95\x59\xb6\xb6\x65\x97\x5f\x76\x88\xa7\x9e\x66\x46\xc7\x46\x19\x67\x3c\x08\x68\x9b\x6f\x5a\x29\x67\xa1\x20\x1c\x6a\xa7\xa2\x63\xae\xb1\xa7\x9f\x67\x04\x5a\x69\x9c\x73\x1a\x5a\x67\xa2\xb1\x2d\x4a\xa6\x99\xc1\x89\x3a\xe8\xa5\x74\x22\x7a\x67\xa7\x7b\xb6\xf1\x5a\x19\xae\x5a\x5a\x6a\xa6\xa7\xce\x9a\xe7\xaa\x2f\xc0\xd1\x27\x6d\x79\xe4\x4a\x2a\xa6\x9a\xa2\x1a\x26\xad\x66\xc6\x51\x47\x18\x6e\xd0\x91\x86\x1e\xe8\x1d\xd6\x02\x51\x62\x3c\x6a\x2c\xa1\xb1\x6e\x9a\x2a\xb3\x2f\xd0\x81\x86\x1c\xd2\xa1\xd1\x27\x19\x93\x0a\xaa\x2b\xb2\xbd\x72\xfa\xab\xa7\x66\xd2\x91\x07\x1c\xb8\x52\xfa\xea\xae\xc9\xfa\xca\x68\xb8\xf3\x96\xd1\x42\x74\x27\xda\x51\xc7\xb6\xb0\x9a\x2a\xab\xbb\xfb\xca\x4b\x6f\x0b\x67\x98\x3b\xd4\x74\x72\x90\x47\x07\xc1\xf8\xb6\xfb\xed\xbb\x7b\x2a\xec\xaf\x77\x6e\x90\xf1\xc6\x1d\xe9\xbe\x19\x1d\xbd\x1d\x57\x27\x63\xb6\x74\x90\x21\x72\x5b\x5e\x95\xd5\x1a\x1b\x63\xb4\x31\x87\x5d\x23\xb7\x6c\x72\x1a\x62\xe0\x41\x87\x02\x35\x97\xdc\x9a\x19\x87\x71\x79\x98\x19\x69\x9c\xc1\x33\xcb\x3e\x83\x70\x32\x1e\x65\xe8\x7c\x34\xc9\x2e\x2b\x8d\x33\x1b\x71\xc8\xf1\xb4\xcd\x2f\xe3\x1c\x56\x1c\xef\xf5\x1c\xf5\x1b\x24\x8f\xc1\x46\x0b\xb4\x91\xd1\x82\x9f\x61\xa8\x79\x75\xd2\xf4\xca\xe7\x43\x0f\x72\xc9\x60\xc3\xda\x51\xb7\xcd\x06\x0f\x71\x93\x06\x76\xca\x48\x47\xfd\x5f\x70\x9e\x7a\x3c\x86\x0e\x20\x00\x6d\x54\xda\x64\xa4\x21\xed\x61\x61\xcc\xa7\x97\xe1\x6a\x2d\xee\x86\x02\x7b\x7b\x5d\x5d\xc3\x6f\x3c\x3c\x46\xc4\x70\xd0\x41\xb8\xe1\x5c\x39\x4c\x07\xc4\x12\x83\x30\x07\x96\xc2\xca\xb1\x73\xe5\x7d\x57\x07\xb6\x57\x4d\xcb\xf1\x79\x81\x20\x3c\x41\x72\x11\x58\x48\x61\x3a\xea\x05\xae\xde\xb9\xe5\xad\xbd\xee\x86\x1a\xf4\x9e\x21\xc3\xec\x46\x29\x01\x85\x0c\xbb\xc3\x91\xba\xef\x7c\x43\x7d\xb3\x18\x77\xb4\x61\x06\xf2\x20\x5c\xd1\x84\x11\xcd\x3f\x4f\xf9\xef\xad\x67\x2d\x86\x1c\x73\xd8\x71\x06\xf6\x53\x58\x71\x44\xf7\xbd\x7f\x1f\x3d\xd6\x52\xe7\xec\xe6\xf1\x85\xd3\x8e\x45\x13\x4c\xb0\xaf\xba\xfb\xc0\xc7\x0f\xc7\x5e\xd8\x83\x82\x13\xd6\x77\x3a\xe7\xb5\x8f\x75\xd2\x13\xdf\x1d\xca\x20\x06\xfc\xd4\xcf\x28\x57\x28\x82\x10\xa0\xa0\x3f\xe8\xf5\xef\x64\x61\xb9\x03\xf6\x88\x30\xc0\x0a\x2a\x40\x2d\x6c\xb9\xe0\xd4\x52\xf6\x26\x10\x92\x25\x7c\x4a\x8b\xd9\xcc\x3e\xe8\x17\x11\xe6\x6c\x67\x26\xec\x1f\xd0\xa2\x85\x26\x37\x10\xcd\x68\x31\x44\xe1\xd2\x9a\x06\xc3\x1
  91. )
  92. func TestParsePackageArchiveName(t *testing.T) {
  93. var tests = []struct {
  94. Archive string
  95. Name string
  96. Version version.Version
  97. Arch string
  98. Ext string
  99. }{
  100. {"zsh-5.4.2-1-x86_64.pkg.tar.bz2", "zsh", version.Parse("5.4.2-1"), "x86_64", ".pkg.tar.bz2"},
  101. {"pacman-mirrorlist-20170907-1-any.pkg.tar.xz", "pacman-mirrorlist", version.Parse("20170907-1"), "any", ".pkg.tar.xz"},
  102. }
  103. for _, test := range tests {
  104. t.Run(test.Archive, func(t *testing.T) {
  105. name, v, arch, ext, err := ParsePackageArchiveName(test.Archive)
  106. if err != nil {
  107. t.Fatal(err)
  108. }
  109. if name != test.Name {
  110. t.Fatalf(`expected name %q, got %q`, test.Name, name)
  111. }
  112. if version.Compare(v, test.Version) != 0 {
  113. t.Fatalf(`expected version %q, got %q`, test.Version, v)
  114. }
  115. if arch != test.Arch {
  116. t.Fatalf(`expected arch %q, got %q`, test.Arch, arch)
  117. }
  118. if ext != test.Ext {
  119. t.Fatalf(`expected ext %q, got %q`, test.Ext, ext)
  120. }
  121. })
  122. }
  123. }
  124. func TestParsePackageArchiveNameError(t *testing.T) {
  125. var tests = []string{
  126. "zsh-5.4.2-1-x86_64.tar.bz2", // Wrong extension
  127. "zsh-5.4.2-1.pkg.tar.bz2", // No arch
  128. "zsh-5.4.2-x86_64.pkg.tar.bz2", // No release
  129. "zsh-x86_64.pkg.tar.bz2", // No version
  130. "zsh.pkg.tar.bz2", // No version nor arch
  131. }
  132. for _, test := range tests {
  133. t.Run(test, func(t *testing.T) {
  134. if _, _, _, _, err := ParsePackageArchiveName(test); err == nil {
  135. t.Fatal(`wrong package name accepted`)
  136. }
  137. })
  138. }
  139. }
  140. func TestParsePackageName(t *testing.T) {
  141. var tests = []struct {
  142. Package string
  143. Name string
  144. Version version.Version
  145. }{
  146. {"orc-0.4.26+2+g249c709-1", "orc", version.Parse("0.4.26+2+g249c709-1")},
  147. {"openbsd-netcat-1.178_3-1", "openbsd-netcat", version.Parse("1.178_3-1")},
  148. }
  149. for _, test := range tests {
  150. t.Run(test.Package, func(t *testing.T) {
  151. name, v, err := ParsePackageName(test.Package)
  152. if err != nil {
  153. t.Fatal(err)
  154. }
  155. if name != test.Name {
  156. t.Fatalf(`expected name %q, got %q`, test.Name, name)
  157. }
  158. if version.Compare(v, test.Version) != 0 {
  159. t.Fatalf(`expected version %q, got %q`, test.Version, v)
  160. }
  161. })
  162. }
  163. }
  164. func TestParsePackageNameError(t *testing.T) {
  165. var tests = []string{
  166. "orc-0.4.26+2+g249c709", // No release
  167. "orc", // No version
  168. }
  169. for _, test := range tests {
  170. t.Run(test, func(t *testing.T) {
  171. if _, _, err := ParsePackageName(test); err == nil {
  172. t.Fatal(`wrong package name accepted`)
  173. }
  174. })
  175. }
  176. }