yay/aur/aur_test.go

90 lines
1.8 KiB
Go
Raw Normal View History

2016-11-30 18:55:21 +01:00
package aur
import (
"os"
2016-11-30 18:55:21 +01:00
"reflect"
"testing"
)
func TestSearch(t *testing.T) {
2016-11-30 18:55:21 +01:00
eN := "yay"
2016-12-02 13:19:03 +01:00
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
2016-11-30 18:55:21 +01:00
result, _, err := Search("yay", true)
if err != nil {
t.Fatalf("Expected err to be nil but it was %s", err)
}
// t.Logf("Got struct: %+v", result)
found := false
for _, v := range result {
if v.Name == eN && v.Description == eD {
found = true
}
}
if !found {
t.Fatalf("Expected to find yay, found %+v", result)
}
}
func benchmarkSearch(search string, sort bool, b *testing.B) {
2016-11-30 18:55:21 +01:00
for n := 0; n < b.N; n++ {
Search(search, sort)
}
}
func BenchmarkSearchSimpleNoSort(b *testing.B) { benchmarkSearch("yay", false, b) }
func BenchmarkSearchComplexNoSort(b *testing.B) { benchmarkSearch("linux", false, b) }
func BenchmarkSearchSimpleSorted(b *testing.B) { benchmarkSearch("yay", true, b) }
func BenchmarkSearchComplexSorted(b *testing.B) { benchmarkSearch("linux", true, b) }
func TestInfo(t *testing.T) {
2016-11-30 18:55:21 +01:00
eN := "yay"
2016-12-02 13:19:03 +01:00
eD := "Yet another yogurt. Pacman wrapper with AUR support written in go."
2016-11-30 18:55:21 +01:00
eM := []string{"go", "git"}
result, _, err := Info("yay")
if err != nil {
t.Fatalf("Expected err to be nil but it was %s", err)
}
// t.Logf("Got struct: %+v", result)
found := false
for _, v := range result {
if v.Name == eN && v.Description == eD && reflect.DeepEqual(v.MakeDepends, eM) {
found = true
}
}
if !found {
t.Fatalf("Expected to find yay, found %+v", result)
}
}
func TestUpgrade(t *testing.T) {
old := os.Stdout
_, w, _ := os.Pipe()
os.Stdout = w
err := Upgrade([]string{})
2016-11-30 18:55:21 +01:00
if err != nil {
t.Fatalf("Expected err to be nil but it was %s", err)
}
os.Stdout = old
2016-11-30 18:55:21 +01:00
}
func BenchmarkUpgrade(b *testing.B) {
old := os.Stdout
_, w, _ := os.Pipe()
os.Stdout = w
for n := 0; n < b.N; n++ {
Upgrade([]string{})
}
os.Stdout = old
}