aur_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package aur
  2. import (
  3. "os"
  4. "reflect"
  5. "testing"
  6. "github.com/demizer/go-alpm"
  7. )
  8. func TestSearch(t *testing.T) {
  9. eN := "yay"
  10. eD := "Yet another pacman wrapper with AUR support"
  11. result, _, err := Search("yay", true)
  12. if err != nil {
  13. t.Fatalf("Expected err to be nil but it was %s", err)
  14. }
  15. // t.Logf("Got struct: %+v", result)
  16. found := false
  17. for _, v := range result {
  18. if v.Name == eN && v.Description == eD {
  19. found = true
  20. }
  21. }
  22. if !found {
  23. t.Fatalf("Expected to find yay, found %+v", result)
  24. }
  25. }
  26. func benchmarkSearch(search string, sort bool, b *testing.B) {
  27. for n := 0; n < b.N; n++ {
  28. Search(search, sort)
  29. }
  30. }
  31. func BenchmarkSearchSimpleNoSort(b *testing.B) { benchmarkSearch("yay", false, b) }
  32. func BenchmarkSearchComplexNoSort(b *testing.B) { benchmarkSearch("linux", false, b) }
  33. func BenchmarkSearchSimpleSorted(b *testing.B) { benchmarkSearch("yay", true, b) }
  34. func BenchmarkSearchComplexSorted(b *testing.B) { benchmarkSearch("linux", true, b) }
  35. func TestInfo(t *testing.T) {
  36. eN := "yay"
  37. eD := "Yet another pacman wrapper with AUR support"
  38. eM := []string{"go", "git"}
  39. result, _, err := Info("yay")
  40. if err != nil {
  41. t.Fatalf("Expected err to be nil but it was %s", err)
  42. }
  43. // t.Logf("Got struct: %+v", result)
  44. found := false
  45. for _, v := range result {
  46. if v.Name == eN && v.Description == eD && reflect.DeepEqual(v.MakeDepends, eM) {
  47. found = true
  48. }
  49. }
  50. if !found {
  51. t.Fatalf("Expected to find yay, found %+v", result)
  52. }
  53. }
  54. func TestUpdate(t *testing.T) {
  55. var conf alpm.PacmanConfig
  56. file, err := os.Open("/etc/pacman.conf")
  57. if err != nil {
  58. return
  59. }
  60. conf, err = alpm.ParseConfig(file)
  61. if err != nil {
  62. return
  63. }
  64. err = UpdatePackages("/tmp/yaytmp", &conf, []string{})
  65. if err != nil {
  66. t.Fatalf("Expected err to be nil but it was %s", err)
  67. }
  68. }
  69. func TestUpgrade(t *testing.T) {
  70. var conf alpm.PacmanConfig
  71. file, err := os.Open("/etc/pacman.conf")
  72. if err != nil {
  73. return
  74. }
  75. conf, err = alpm.ParseConfig(file)
  76. if err != nil {
  77. return
  78. }
  79. err = UpdatePackages("/tmp/yaytmp", &conf, []string{})
  80. if err != nil {
  81. t.Fatalf("Expected err to be nil but it was %s", err)
  82. }
  83. }