mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 15:39:46 +00:00
Update dump tests to better follow table-driven pattern
This commit is contained in:
@@ -6,50 +6,52 @@ import (
|
||||
|
||||
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,
|
||||
},
|
||||
{
|
||||
line: "https://github.com/grdl/git-get refs/tags/v1.0.0",
|
||||
wantBranch: "refs/tags/v1.0.0",
|
||||
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 i, test := range tests {
|
||||
got, err := parseLine(test.line)
|
||||
if err != nil && test.wantErr == nil {
|
||||
t.Fatalf("Test case %d should not return an error", i)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
if err != nil && test.wantErr != nil {
|
||||
continue
|
||||
}
|
||||
// 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("Failed test case %d, got: %s; wantBranch: %s", i, got.branch, test.wantBranch)
|
||||
}
|
||||
if got.branch != test.wantBranch {
|
||||
t.Errorf("expected %q; got %q", test.wantBranch, got.branch)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user