Merge pull request #669 from Morganamilo/tests-aururl

Fix tests and document --aururl
This commit is contained in:
Anna 2018-08-29 23:19:10 +01:00 committed by GitHub
commit 5e23a2fc6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 23 deletions

1
cmd.go
View file

@ -39,6 +39,7 @@ Permanent configuration options:
--save Causes the following options to be saved back to the
config file when used
--aururl <url> Set an alternative AUR URL
--builddir <dir> Directory used to download and run PKBUILDS
--editor <file> Editor to use when editing PKGBUILDs
--editorflags <flags> Pass arguments to editor

View file

@ -136,6 +136,11 @@ Causes the following options to be saved back to the config file. This
provides an easy way to change config options without directly editing the
file.
.TP
.B \-\-aururl
Set an alternative AUR URL. This is mostly useful for users in china who wish
to use https://aur.tuna.tsinghua.edu.cn/.
.TP
.B \-\-builddir <dir>
Directory to use for Building AUR Packages. This directory is also used as

View file

@ -67,7 +67,7 @@ func gitDownload(url string, path string, name string) (bool, error) {
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
_, stderr, err := capture(cmd)
if err != nil {
return false, fmt.Errorf("error cloning %s: stderr", name, stderr)
return false, fmt.Errorf("error cloning %s: %s", name, stderr)
}
return true, nil

View file

@ -146,34 +146,30 @@ func TestCheckPgpKeys(t *testing.T) {
defer server.Shutdown(context.TODO())
casetests := []struct {
pkgs []*rpc.Pkg
pkgs Base
srcinfos map[string]*gosrc.Srcinfo
bases map[string][]*rpc.Pkg
wantError bool
}{
// cower: single package, one valid key not yet in the keyring.
// 487EACC08557AD082088DABA1EB2638FF56C0C53: Dave Reisner.
{
pkgs: []*rpc.Pkg{newPkg("cower")},
pkgs: Base{newPkg("cower")},
srcinfos: map[string]*gosrc.Srcinfo{"cower": makeSrcinfo("cower", "487EACC08557AD082088DABA1EB2638FF56C0C53")},
bases: map[string][]*rpc.Pkg{"cower": {newPkg("cower")}},
wantError: false,
},
// libc++: single package, two valid keys not yet in the keyring.
// 11E521D646982372EB577A1F8F0871F202119294: Tom Stellard.
// B6C8F98282B944E3B0D5C2530FC3042E345AD05D: Hans Wennborg.
{
pkgs: []*rpc.Pkg{newPkg("libc++")},
pkgs: Base{newPkg("libc++")},
srcinfos: map[string]*gosrc.Srcinfo{"libc++": makeSrcinfo("libc++", "11E521D646982372EB577A1F8F0871F202119294", "B6C8F98282B944E3B0D5C2530FC3042E345AD05D")},
bases: map[string][]*rpc.Pkg{"libc++": {newPkg("libc++")}},
wantError: false,
},
// Two dummy packages requiring the same key.
// ABAF11C65A2970B130ABE3C479BE3E4300411886: Linus Torvalds.
{
pkgs: []*rpc.Pkg{newPkg("dummy-1"), newPkg("dummy-2")},
pkgs: Base{newPkg("dummy-1"), newPkg("dummy-2")},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-1": makeSrcinfo("dummy-1", "ABAF11C65A2970B130ABE3C479BE3E4300411886"), "dummy-2": makeSrcinfo("dummy-2", "ABAF11C65A2970B130ABE3C479BE3E4300411886")},
bases: map[string][]*rpc.Pkg{"dummy-1": {newPkg("dummy-1")}, "dummy-2": {newPkg("dummy-2")}},
wantError: false,
},
// dummy package: single package, two valid keys, one of them already
@ -181,37 +177,33 @@ func TestCheckPgpKeys(t *testing.T) {
// 11E521D646982372EB577A1F8F0871F202119294: Tom Stellard.
// C52048C0C0748FEE227D47A2702353E0F7E48EDB: Thomas Dickey.
{
pkgs: []*rpc.Pkg{newPkg("dummy-3")},
pkgs: Base{newPkg("dummy-3")},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-3": makeSrcinfo("dummy-3", "11E521D646982372EB577A1F8F0871F202119294", "C52048C0C0748FEE227D47A2702353E0F7E48EDB")},
bases: map[string][]*rpc.Pkg{"dummy-3": {newPkg("dummy-3")}},
wantError: false,
},
// Two dummy packages with existing keys.
{
pkgs: []*rpc.Pkg{newPkg("dummy-4"), newPkg("dummy-5")},
pkgs: Base{newPkg("dummy-4"), newPkg("dummy-5")},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-4": makeSrcinfo("dummy-4", "11E521D646982372EB577A1F8F0871F202119294"), "dummy-5": makeSrcinfo("dummy-5", "C52048C0C0748FEE227D47A2702353E0F7E48EDB")},
bases: map[string][]*rpc.Pkg{"dummy-4": {newPkg("dummy-4")}, "dummy-5": {newPkg("dummy-5")}},
wantError: false,
},
// Dummy package with invalid key, should fail.
{
pkgs: []*rpc.Pkg{newPkg("dummy-7")},
pkgs: Base{newPkg("dummy-7")},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-7": makeSrcinfo("dummy-7", "THIS-SHOULD-FAIL")},
bases: map[string][]*rpc.Pkg{"dummy-7": {newPkg("dummy-7")}},
wantError: true,
},
// Dummy package with both an invalid an another valid key, should fail.
// A314827C4E4250A204CE6E13284FC34C8E4B1A25: Thomas Bächler.
{
pkgs: []*rpc.Pkg{newPkg("dummy-8")},
pkgs: Base{newPkg("dummy-8")},
srcinfos: map[string]*gosrc.Srcinfo{"dummy-8": makeSrcinfo("dummy-8", "A314827C4E4250A204CE6E13284FC34C8E4B1A25", "THIS-SHOULD-FAIL")},
bases: map[string][]*rpc.Pkg{"dummy-8": {newPkg("dummy-8")}},
wantError: true,
},
}
for _, tt := range casetests {
err := checkPgpKeys(tt.pkgs, tt.bases, tt.srcinfos)
err := checkPgpKeys([]Base{tt.pkgs}, tt.srcinfos)
if !tt.wantError {
if err != nil {
t.Fatalf("Got error %q, want no error", err)

View file

@ -11,7 +11,7 @@ func benchmarkPrintSearch(search string, b *testing.B) {
os.Stdout = w
for n := 0; n < b.N; n++ {
res, _, _ := queryRepo(append([]string{}, search))
res, _ := queryRepo(append([]string{}, search))
res.printSearch()
}
os.Stdout = old

View file

@ -32,7 +32,7 @@ func TestGetVersionDiff(t *testing.T) {
}
out := []versionPair{
{"1-1", "1-1"},
{"1-1" + red(""), "1-1" + green("")},
{red("1-1"), green("2-1")},
{red("2-1"), green("1-1")},
{"1-" + red("1"), "1-" + green("2")},
@ -56,7 +56,7 @@ func TestGetVersionDiff(t *testing.T) {
o, n := getVersionDiff(pair.Old, pair.New)
if o != out[i].Old || n != out[i].New {
t.Errorf("Test %d failed for update: (%s => %s) expected (%s => %s) got (%s => %s)", i+1, in[i].Old, in[i].New, out[i].Old, out[i].New, o, n)
t.Errorf("Test %d failed for update: expected (%s => %s) got (%s => %s) %d %d %d %d", i+1, in[i].Old, in[i].New, o, n, len(in[i].Old), len(in[i].New), len(o), len(n))
}
}
}

View file

@ -49,7 +49,7 @@ func TestParsing(t *testing.T) {
{"github.com/davidgiven/ack", "HEAD", []string{"git"}},
{"", "", nil},
{"", "", nil},
{"github.com/jguer/yay.git", "foo", []string{"a", "b", "c", "d", "e", "f"}},
{"", "", nil},
}
for n, url := range urls {
@ -60,7 +60,7 @@ func TestParsing(t *testing.T) {
branch != compare.Branch ||
!isEqual(protocols, compare.Protocols) {
t.Fatalf("Test %d failed: Expected: url=%+v branch=%+v protocols=%+v\ngot url=%+v branch=%+v protocols=%+v", n+1, url, branch, protocols, compare.URL, compare.Branch, compare.Protocols)
t.Fatalf("Test %d failed: Expected: url=%+v branch=%+v protocols=%+v\ngot url=%+v branch=%+v protocols=%+v", n+1, compare.URL, compare.Branch, compare.Protocols, url, branch, protocols)
}
}