aur_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package aur
  2. import (
  3. "os"
  4. "reflect"
  5. "testing"
  6. )
  7. func TestSearch(t *testing.T) {
  8. eN := "yay"
  9. result, _, err := Search([]string{"yay"}, true)
  10. if err != nil {
  11. t.Fatalf("Expected err to be nil but it was %s", err)
  12. }
  13. // t.Logf("Got struct: %+v", result)
  14. found := false
  15. for _, v := range result {
  16. if v.Name == eN {
  17. found = true
  18. }
  19. }
  20. if !found {
  21. t.Fatalf("Expected to find yay, found %+v", result)
  22. }
  23. }
  24. func benchmarkSearch(search string, sort bool, b *testing.B) {
  25. for n := 0; n < b.N; n++ {
  26. Search([]string{search}, sort)
  27. }
  28. }
  29. func BenchmarkSearchSimpleNoSort(b *testing.B) { benchmarkSearch("yay", false, b) }
  30. func BenchmarkSearchComplexNoSort(b *testing.B) { benchmarkSearch("linux", false, b) }
  31. func BenchmarkSearchSimpleSorted(b *testing.B) { benchmarkSearch("yay", true, b) }
  32. func BenchmarkSearchComplexSorted(b *testing.B) { benchmarkSearch("linux", true, b) }
  33. func TestInfo(t *testing.T) {
  34. eN := "yay"
  35. eM := []string{"go", "git"}
  36. result, _, err := Info("yay")
  37. if err != nil {
  38. t.Fatalf("Expected err to be nil but it was %s", err)
  39. }
  40. // t.Logf("Got struct: %+v", result)
  41. found := false
  42. for _, v := range result {
  43. if v.Name == eN && reflect.DeepEqual(v.MakeDepends, eM) {
  44. found = true
  45. }
  46. }
  47. if !found {
  48. t.Fatalf("Expected to find yay, found %+v", result)
  49. }
  50. }
  51. func TestUpgrade(t *testing.T) {
  52. old := os.Stdout
  53. _, w, _ := os.Pipe()
  54. os.Stdout = w
  55. err := Upgrade([]string{})
  56. if err != nil {
  57. t.Fatalf("Expected err to be nil but it was %s", err)
  58. }
  59. os.Stdout = old
  60. }
  61. func BenchmarkUpgrade(b *testing.B) {
  62. old := os.Stdout
  63. _, w, _ := os.Pipe()
  64. os.Stdout = w
  65. for n := 0; n < b.N; n++ {
  66. Upgrade([]string{})
  67. }
  68. os.Stdout = old
  69. }