6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-12 10:13:30 +00:00

Update dump tests to better follow table-driven pattern

This commit is contained in:
Grzegorz Dlugoszewski
2020-06-25 09:50:12 +02:00
parent fe07ab3c8a
commit da8849d7f5

View File

@@ -6,50 +6,52 @@ import (
func TestParsingRefs(t *testing.T) { func TestParsingRefs(t *testing.T) {
var tests = []struct { var tests = []struct {
name string
line string line string
wantBranch string wantBranch string
wantErr error wantErr error
}{ }{
{ {
name: "url without branch",
line: "https://github.com/grdl/git-get", line: "https://github.com/grdl/git-get",
wantBranch: "", wantBranch: "",
wantErr: nil, wantErr: nil,
}, },
{ {
name: "url with branch",
line: "https://github.com/grdl/git-get master", line: "https://github.com/grdl/git-get master",
wantBranch: "master", wantBranch: "master",
wantErr: nil, wantErr: nil,
}, },
{ {
line: "https://github.com/grdl/git-get refs/tags/v1.0.0", name: "url with multiple branches",
wantBranch: "refs/tags/v1.0.0",
wantErr: nil,
},
{
line: "https://github.com/grdl/git-get master branch", line: "https://github.com/grdl/git-get master branch",
wantBranch: "", wantBranch: "",
wantErr: errInvalidNumberOfElements, wantErr: errInvalidNumberOfElements,
}, },
{ {
name: "url without path",
line: "https://github.com", line: "https://github.com",
wantBranch: "", wantBranch: "",
wantErr: errEmptyURLPath, wantErr: errEmptyURLPath,
}, },
} }
for i, test := range tests { for _, test := range tests {
got, err := parseLine(test.line) t.Run(test.name, func(t *testing.T) {
if err != nil && test.wantErr == nil { got, err := parseLine(test.line)
t.Fatalf("Test case %d should not return an error", i) if err != nil && test.wantErr == nil {
} t.Fatalf("got error %q", err)
}
if err != nil && test.wantErr != nil { // TODO: this should check if we actually got the error we expected
continue if err != nil && test.wantErr != nil {
} return
}
if got.branch != test.wantBranch { if got.branch != test.wantBranch {
t.Errorf("Failed test case %d, got: %s; wantBranch: %s", i, got.branch, test.wantBranch) t.Errorf("expected %q; got %q", test.wantBranch, got.branch)
} }
})
} }
} }