-
-
Notifications
You must be signed in to change notification settings - Fork 420
Expand file tree
/
Copy pathget_ops_test.go
More file actions
75 lines (64 loc) · 1.62 KB
/
Copy pathget_ops_test.go
File metadata and controls
75 lines (64 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//go:build !integration
package main
import (
"context"
"io"
"net/http"
"strings"
"testing"
"github.com/Jguer/aur"
"github.com/stretchr/testify/require"
gock "gopkg.in/h2non/gock.v1"
"github.com/Jguer/yay/v13/pkg/db"
mockaur "github.com/Jguer/yay/v13/pkg/dep/mock"
"github.com/Jguer/yay/v13/pkg/settings/parser"
"github.com/Jguer/yay/v13/pkg/text"
)
func TestPrintPkgbuilds(t *testing.T) {
t.Parallel()
tests := []struct {
name string
targets []string
results []aur.Pkg
wantErr bool
}{
{
name: "prints pkgbuild when package exists",
targets: []string{"aur/pkg"},
results: []aur.Pkg{{Name: "pkg", PackageBase: "pkg"}},
},
{
name: "returns error when package does not exist",
targets: []string{"aur/found", "aur/missing"},
results: nil,
wantErr: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
defer gock.Off()
gock.New("https://aur.archlinux.org").
Get("/cgit/aur.git/plain/PKGBUILD").
Reply(200).
BodyString("pkgbuild")
err := printPkgbuilds(&mockDBSearcher{}, &mockaur.MockAUR{
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
return tc.results, nil
},
}, &http.Client{}, text.NewLogger(io.Discard, io.Discard, strings.NewReader(""), true, "test"),
tc.targets, parser.ModeAny, "https://aur.archlinux.org")
if tc.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})
}
}
type mockDBSearcher struct{}
func (m *mockDBSearcher) SyncPackage(string) db.IPackage {
return nil
}
func (m *mockDBSearcher) SyncPackageFromDB(string, string) db.IPackage {
return nil
}