-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: alternative error checking implementation
- Loading branch information
1 parent
2c006a3
commit d964ee6
Showing
3 changed files
with
14 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,20 @@ func TestGitRemoteParser(t *testing.T) { | |
}{ | ||
{"origin [email protected]:coopnorge/helloworld.git (fetch)", "https://github.com/coopnorge/helloworld", nil}, | ||
{"origin https://github.com/coopnorge/helloworld.git (fetch)", "https://github.com/coopnorge/helloworld", nil}, | ||
{"origin http://github.com/coopnorge/helloworld.git (fetch)", "", NewErrUnableToParseRemoteURL("http://github.com/coopnorge/helloworld.git")}, | ||
{"origin http://github.com/coopnorge/helloworld.git (fetch)", "", fmt.Errorf(unableToParseRemoteErr, "http://github.com/coopnorge/helloworld.git")}, | ||
} | ||
for _, tt := range tests { | ||
testname := fmt.Sprintf("%s,%s", tt.remote, tt.want) | ||
t.Run(testname, func(t *testing.T) { | ||
got, err := gitRemoteParser(tt.remote) | ||
if got != tt.want || !errors.Is(err, tt.err) { | ||
t.Errorf("\n got: %s,%v \nwant: %s,%v", got, err, tt.want, tt.err) | ||
if got == tt.want && | ||
(errors.Is(err, tt.err) || // This is to compare if the error is of the same type, which | ||
// happen when both errors are nil, | ||
// The line below is to compare if the error message is the same as string | ||
err.Error() == tt.err.Error()) { | ||
return | ||
} | ||
t.Errorf("\n got: %s,%v \nwant: %s,%v", got, err, tt.want, tt.err) | ||
}) | ||
} | ||
} |