@@ -6,14 +6,53 @@ import (
66 "github.com/stretchr/testify/assert"
77)
88
9- func TestGHRepo (t * testing.T ) {
10- ghRepo := & ghRepo {
11- Name : "REPO" ,
12- Owner : "OWNER" ,
13- }
9+ func TestNewGHRepo (t * testing.T ) {
10+ tests := []struct {
11+ name string
12+ wantName string
13+ wantOwner string
14+ wantHost string
15+ wantFullName string
16+ wantErr bool
17+ errMsg string
18+ }{
19+ {
20+ name : "foo/bar" ,
21+ wantOwner : "foo" ,
22+ wantName : "bar" ,
23+ wantFullName : "foo/bar" ,
24+ wantHost : "github.com" ,
25+ wantErr : false ,
26+ }, {
27+ name : "other-cf-workers-proxy-9e9.pages.dev/foo/bar" ,
28+ wantOwner : "foo" ,
29+ wantName : "bar" ,
30+ wantFullName : "foo/bar" ,
31+ wantHost : "other-cf-workers-proxy-9e9.pages.dev" ,
32+ wantErr : false ,
33+ }, {
34+ name : "bar" ,
35+ wantErr : true ,
36+ errMsg : "invalid repository name" ,
37+ }, {
38+ name : "" ,
39+ wantErr : true ,
40+ errMsg : "invalid repository name" ,
41+ }}
42+
43+ for _ , tt := range tests {
44+ t .Run (tt .name , func (t * testing.T ) {
45+ ghr , err := newGHRepo (tt .name )
1446
15- assert .Equal (t , "OWNER/REPO" , ghRepo .RepoFullName ())
16- assert .Equal (t , "OWNER" , ghRepo .RepoOwner ())
17- assert .Equal (t , "REPO" , ghRepo .RepoName ())
18- assert .Equal (t , "github.com" , ghRepo .RepoHost ())
47+ if tt .wantErr {
48+ assert .EqualError (t , err , tt .errMsg )
49+ } else {
50+ assert .NoError (t , err )
51+ assert .Equal (t , tt .wantFullName , ghr .RepoFullName ())
52+ assert .Equal (t , tt .wantOwner , ghr .RepoOwner ())
53+ assert .Equal (t , tt .wantName , ghr .RepoName ())
54+ assert .Equal (t , tt .wantHost , ghr .RepoHost ())
55+ }
56+ })
57+ }
1958}
0 commit comments