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.

50 lines
4.3 KiB

  1. package archlinux
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "os"
  7. "testing"
  8. )
  9. type testNamedReader struct {
  10. name string
  11. io.Reader
  12. }
  13. func (r testNamedReader) Name() string {
  14. return r.name
  15. }
  16. func ExampleReadRepositoryDB() {
  17. f, err := os.Open("/var/lib/pacman/sync/core.db")
  18. if os.IsNotExist(err) {
  19. return
  20. }
  21. repo, err := ReadRepositoryDB(f)
  22. if err != nil {
  23. fmt.Println("error reading repository:", err)
  24. return
  25. }
  26. fmt.Println("core.db has", len(repo.Packages), "packages")
  27. // Output: core.db has 250 packages
  28. }
  29. func TestReadRepositoryDB(t *testing.T) {
  30. r, err := ReadRepositoryDB(testNamedReader{"test", bytes.NewBuffer(testRepositoryDB)})
  31. if err != nil {
  32. t.Fatal(err)
  33. }
  34. if l := len(r.Packages); l != 1 {
  35. t.Fatalf(`expected 1 package, got %d`, l)
  36. }
  37. t.Log("Repository.Name =", r.Name)
  38. t.Log(r.Packages[0], r.Packages[0].Description)
  39. }
  40. var (
  41. testRepositoryDB = []byte("\x1f\x8b\x08\x00\xd0\x70\xcd\x59\x00\x03\xed\xd4\xc9\x92\xa3\x36\x18\x00\x60\x9f\xfd\x14\x5c\x7c\x72\xb5\x41\x2c\x02\x4f\x65\x52\x11\x20\xdb\x78\xc1\x0b\xed\xf5\x92\x62\x07\x1b\x90\x8d\xa1\xdb\xf6\x71\xde\x2d\xef\x15\xd9\x3d\x93\x9e\x9a\xaa\xa9\x9c\xba\x92\x54\xf4\x5d\x90\x7e\x49\x48\xf6\xff\x8b\x98\x3c\x89\x9f\x40\xa7\xfb\x04\xf8\xc6\x47\x11\x28\x55\x51\xde\x9e\xf0\xf1\x04\xaa\x22\x3c\xfa\x5f\x35\x80\x04\x14\x09\x40\x15\x00\xd0\x10\x80\x08\x14\xb9\xc1\x29\x1f\x76\xa2\xef\xd4\xe7\xca\x2d\x39\xae\xf1\x9a\xee\x0b\xb7\x08\x7e\x3a\xef\xef\xc6\xff\xa3\xe2\xf7\xfc\x07\xe1\xd9\xff\x90\x3d\xee\x09\x86\xb2\xfc\xb3\xfc\x03\x28\x4b\x3f\xe4\x5f\x12\x44\xd0\xe0\x84\x0f\x39\xcd\x0f\xfe\xe7\xf9\x6f\xf5\xac\x31\xb6\xd1\x04\xb7\x9a\xef\xa5\xf0\x74\xd1\xe0\xef\x50\xee\x1c\x0f\x71\x87\xfe\x3b\x9d\xcb\xad\xd9\x6c\x7d\x9b\x44\x9b\x3a\x72\xbe\x35\x57\x78\xe1\x58\x53\xbb\xd5\xfc\xba\x94\x86\x4c\xec\x18\xad\xa6\x41\xca\x90\xf3\x49\x7e\x4c\xb3\xb0\xe4\x2a\x42\xb2\x33\x17\x11\xda\x4a\x42\xae\x4f\xb8\x63\x49\xe2\xd2\xcd\xf3\xb4\x88\xb9\xcc\x2d\xe2\xda\x8d\x43\xba\xd6\x70\xac\x1d\x7d\xb5\x0c\x15\x00\x24\x51\xa3\x11\xeb\x2d\x22\x4a\x40\xee\x0a\x0a\x14\x68\x68\x62\x2a\xce\x72\xd2\x6a\xc2\x47\x9d\x08\x72\xe0\x01\xc1\xf3\x43\x00\x22\x55\x82\x40\xed\x4a\x81\xef\x8b\x81\x1c\xd1\xa9\xce\x00\x89\x0a\x7c\xcc\xf6\x35\x28\x85\x91\x4a\x5f\x2b\x02\x20\x7a\xb2\xe8\x45\xa1\x2f\x28\x9a\x2c\x01\x15\x7a\xb4\xfc\x5c\x2f\x0c\x44\x55\x8a\x54\x4d\xf3\x03\x25\x94\x44\x57\x83\x2a\xdd\x40\xd3\x64\x45\x96\xef\x67\x99\xf5\x67\x8e\xd5\x6f\x35\xd3\x39\xbe\xe9\x08\xe9\x06\x42\x41\x2f\xc5\x58\x13\x0f\xeb\xa4\x9b\x14\xb5\x5e\x2d\x6e\x71\xb4\xab\xdb\x73\xc9\x5f\x26\xb7\xd1\xe8\xd0\x43\x59\xbe\xd7\xbc\x03\x32\xe2\xc3\xfc\x3d\x9e\xab\x2e\x8a\xf8\xb9\x6e\x1e\x93\x9d\x9e\x24\xee\x7e\x9d\xcb\x39\x18\xa2\xa0\xbd\xc1\xc3\x68\xe9\xa4\x7a\xaf\xb2\x02\xb7\x7e\xae\x5c\x67\x68\xae\x07\xf6\xe5\x10\x12\x7b\x85\xb7\xc7\x30\x91\x88\xe5\x79\x5e\xb2\x86\x24\xb3\xfb\x06\xdf\x1d\x92\x6c\xbe\x38\xbd\x90\xf3\xc6\x56\x33\x77\x25\x4e\xf0\xae\x4a\x6f\x22\x3f\x23\xba\xdf\x3b\xe8\xf5\x66\xf3\x32\x34\x2e\x81\xa9\x62\xb2\x5c\xd4\xe5\x2e\xe0\xad\x75\x3e\x50\xf2\xd3\xce\xd8\x44\x49\xe1\xc1\x24\xef\xbd\x9e\x47\xe6\xa9\xda\x8e\x52\xa5\xad\x09\x09\x7f\xed\x1a\x57\x6d\xda\x6f\x8b\x66\xcf\x18\x5d\xf3\xf5\x4a\xb1\x15\x1d\x87\xf4\xb7\x6d\x82\xcd\x4b\x01\x8c\xc1\x65\x58\x4d\x09\x5a\xaf\xc7\xc3\x38\xf4\xbd\x69\x71\x3e\xb4\x63\x3b\x03\xdb\xed\x98\x2f\x4d\xe4\xc8\xe3\x03\xd1\xa1\x57\x47\x2f\xe3\xab\x97\x5d\x63\xf3\x3c\x42\x78\xb9\xc4\x01\xe4\x4f\x53\xa1\x5e\x90\xf2\x46\xbc\x73\x0f\xf6\xb2\x4a\x45\xc5\x2a\x7f\xdd\x5e\x56\xd2\x00\x7b\x42\xdf\x3c\xc1\xe9\xf2\x36\x19\xf5\x2f\x7b\x0b\x8e\xbb\xc3\xf9\xb4\xad\x56\x33\xfe\xe4\xb9\x3a\x48\xf6\xb8\x9a\x85\x3e\x5e\x95\x25\x4a\x21\xdc\xd0\xa2\xb8\x28\xd2\x42\xec\x27\x91\x57\xbb\xa9\x2d\x45\xe9\x15\xa3\xcf\x9f\x69\xaa\x96\x8b\x71\xab\x99\x54\xd5\xf1\x13\xcf\xc7\xe4\x5e\x61\x1d\x52\xc6\x3c\x1d\x19\x5b\x06\xb6\xef\xf5\xab\x3b\x26\xed\xa2\x85\x31\x68\x35\xdf\x0a\xfe\x5e\xda\x4b\x6b\x6c\x9a\xe8\x99\x8e\x03\x45\x90\xba\x40\x56\x05\xe9\x9e\x7a\x64\x8c\x50\x1f\x2f\xe8\x32\xb7\xac\xfe\xf8\x42\xf2\x34\xdc\x73\xb3\x94\x54\x25\x79\x3d\x1f\x52\xee\x17\xef\xf8\x57\xe7\x37\xb7\xf4\x93\x2c\x2d\xea\xcb\x7d\xd3\x5f\xef\x75\x3d\xb5\x7b\x74\xe3\x67\xe7\x71\xcd\x8e\xe9\xbd\xd6\x67\x8b\xe9\xca\xa2\x97\xe5\xbb\xd0\x04\x8d\xb0\x89\x67\xd8\x36\xef\xd1\xb4\x7a\xdc\xb1\x7f\xfa\x13\xc1\x30\x0c\xc3\x30\x0c\xc3\x30\x0c\xc3\x30\x0c\xc3\x30\x0c\xc3\x30\x0c\xc3\x30\x0c\xc3\x30\xcc\xbf\xdc\x9f\x34\x2c\x3b\xde\x00\x28\x00\x00")
  42. )