-
Notifications
You must be signed in to change notification settings - Fork 3
/
helper_test.go
59 lines (53 loc) · 1.54 KB
/
helper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"testing"
)
func TestGetOwnerAndRepo(t *testing.T) {
testCases := []struct {
input string
expectedOwner string
expectedRepo string
expectedError error
}{
{
input: "owner/repo",
expectedOwner: "owner",
expectedRepo: "repo",
expectedError: nil,
},
{
input: "invalid-repo",
expectedOwner: "",
expectedRepo: "",
expectedError: fmt.Errorf("invalid-repo is not a valid repo name for this tool. It should be in the form of Owner/Reponame, like Jmainguy/ghreport"),
},
{
input: "owner/",
expectedOwner: "",
expectedRepo: "",
expectedError: fmt.Errorf("owner/ is not a valid repo name for this tool. It should be in the form of Owner/Reponame, like Jmainguy/ghreport"),
},
{
input: "",
expectedOwner: "",
expectedRepo: "",
expectedError: fmt.Errorf(" is not a valid repo name for this tool. It should be in the form of Owner/Reponame, like Jmainguy/ghreport"),
},
}
for _, testCase := range testCases {
owner, repo, err := getOwnerAndRepo(testCase.input)
// Verify the expected owner
if owner != testCase.expectedOwner {
t.Errorf("Expected owner: %s, but got: %s", testCase.expectedOwner, owner)
}
// Verify the expected repo
if repo != testCase.expectedRepo {
t.Errorf("Expected repo: %s, but got: %s", testCase.expectedRepo, repo)
}
// Verify the expected error
if fmt.Sprint(err) != fmt.Sprint(testCase.expectedError) {
t.Errorf("Expected error: %v, but got: %v", testCase.expectedError, err)
}
}
}