mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Update vcs_test.go for new vcs method
This commit is contained in:
parent
80c59a74cc
commit
fc72bdfcd0
2 changed files with 54 additions and 19 deletions
6
vcs.go
6
vcs.go
|
@ -38,14 +38,14 @@ func parseSource(source string) (url string, branch string, protocols []string)
|
||||||
if !(strings.Contains(source, "git://") ||
|
if !(strings.Contains(source, "git://") ||
|
||||||
strings.Contains(source, ".git") ||
|
strings.Contains(source, ".git") ||
|
||||||
strings.Contains(source, "git+https://")) {
|
strings.Contains(source, "git+https://")) {
|
||||||
return
|
return "", "", nil
|
||||||
}
|
}
|
||||||
split := strings.Split(source, "::")
|
split := strings.Split(source, "::")
|
||||||
source = split[len(split)-1]
|
source = split[len(split)-1]
|
||||||
split = strings.SplitN(source, "://", 2)
|
split = strings.SplitN(source, "://", 2)
|
||||||
|
|
||||||
if len(split) != 2 {
|
if len(split) != 2 {
|
||||||
return
|
return "", "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
protocols = strings.Split(split[0], "+")
|
protocols = strings.Split(split[0], "+")
|
||||||
|
@ -55,7 +55,7 @@ func parseSource(source string) (url string, branch string, protocols []string)
|
||||||
if secondSplit[0] != "branch" {
|
if secondSplit[0] != "branch" {
|
||||||
//source has #commit= or #tag= which makes them not vcs
|
//source has #commit= or #tag= which makes them not vcs
|
||||||
//packages because they reference a specific point
|
//packages because they reference a specific point
|
||||||
return
|
return "", "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(secondSplit) == 2 {
|
if len(secondSplit) == 2 {
|
||||||
|
|
67
vcs_test.go
67
vcs_test.go
|
@ -4,29 +4,64 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func isEqual(a, b []string) bool {
|
||||||
|
|
||||||
|
if a == nil && b == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if a == nil || b == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range a {
|
||||||
|
if a[i] != b[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func TestParsing(t *testing.T) {
|
func TestParsing(t *testing.T) {
|
||||||
type source struct {
|
type source struct {
|
||||||
sourceurl string
|
URL string
|
||||||
owner string
|
Branch string
|
||||||
repo string
|
Protocols []string
|
||||||
}
|
}
|
||||||
|
|
||||||
neovim := source{sourceurl: "git+https://github.com/neovim/neovim.git"}
|
urls := []string{
|
||||||
neovim.owner, neovim.repo = parseSource(neovim.sourceurl)
|
"git+https://github.com/neovim/neovim.git",
|
||||||
|
"git://github.com/jguer/yay.git#branch=master",
|
||||||
if neovim.owner != "neovim" || neovim.repo != "neovim" {
|
"git://github.com/davidgiven/ack",
|
||||||
t.Fatalf("Expected to find neovim/neovim, found %+v/%+v", neovim.owner, neovim.repo)
|
"git://github.com/jguer/yay.git#tag=v3.440",
|
||||||
|
"git://github.com/jguer/yay.git#commit=e5470c88c6e2f9e0f97deb4728659ffa70ef5d0c",
|
||||||
|
"a+b+c+d+e+f://github.com/jguer/yay.git#branch=foo",
|
||||||
}
|
}
|
||||||
|
|
||||||
yay := source{sourceurl: "git://github.com/jguer/yay.git#branch=master"}
|
sources := []source{
|
||||||
yay.owner, yay.repo = parseSource(yay.sourceurl)
|
{"github.com/neovim/neovim.git", "HEAD", []string{"git", "https"}},
|
||||||
if yay.owner != "jguer" || yay.repo != "yay" {
|
{"github.com/jguer/yay.git", "master", []string{"git"}},
|
||||||
t.Fatalf("Expected to find jguer/yay, found %+v/%+v", yay.owner, yay.repo)
|
{"github.com/davidgiven/ack", "HEAD", []string{"git"}},
|
||||||
|
{"", "", nil},
|
||||||
|
{"", "", nil},
|
||||||
|
{"github.com/jguer/yay.git", "foo", []string{"a", "b", "c", "d", "e", "f"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
ack := source{sourceurl: "git://github.com/davidgiven/ack"}
|
for n, url := range urls {
|
||||||
ack.owner, ack.repo = parseSource(ack.sourceurl)
|
url, branch, protocols := parseSource(url)
|
||||||
if ack.owner != "davidgiven" || ack.repo != "ack" {
|
compare := sources[n]
|
||||||
t.Fatalf("Expected to find davidgiven/ack, found %+v/%+v", ack.owner, ack.repo)
|
|
||||||
|
if url != compare.URL ||
|
||||||
|
branch != compare.Branch ||
|
||||||
|
!isEqual(protocols, compare.Protocols) {
|
||||||
|
|
||||||
|
t.Fatalf("Expected url=%+v branch=%+v protocols=%+v\ngot url=%+v branch=%+v protocols=%+v", url, branch, protocols, compare.URL, compare.Branch, compare.Protocols)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue