6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 19:44:41 +00:00
Files
git-get/pkg/dump_test.go
2020-06-25 09:50:12 +02:00

58 lines
1.2 KiB
Go

package pkg
import (
"testing"
)
func TestParsingRefs(t *testing.T) {
var tests = []struct {
name string
line string
wantBranch string
wantErr error
}{
{
name: "url without branch",
line: "https://github.com/grdl/git-get",
wantBranch: "",
wantErr: nil,
},
{
name: "url with branch",
line: "https://github.com/grdl/git-get master",
wantBranch: "master",
wantErr: nil,
},
{
name: "url with multiple branches",
line: "https://github.com/grdl/git-get master branch",
wantBranch: "",
wantErr: errInvalidNumberOfElements,
},
{
name: "url without path",
line: "https://github.com",
wantBranch: "",
wantErr: errEmptyURLPath,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := parseLine(test.line)
if err != nil && test.wantErr == nil {
t.Fatalf("got error %q", err)
}
// TODO: this should check if we actually got the error we expected
if err != nil && test.wantErr != nil {
return
}
if got.branch != test.wantBranch {
t.Errorf("expected %q; got %q", test.wantBranch, got.branch)
}
})
}
}