4
4
"reflect"
5
5
"testing"
6
6
7
+ "github.com/cli/go-gh/pkg/config"
7
8
"github.com/cli/go-gh/pkg/repository"
8
9
"github.com/stretchr/testify/assert"
9
10
"gopkg.in/h2non/gock.v1"
@@ -22,7 +23,7 @@ func Test_createHook(t *testing.T) {
22
23
repo : MockRepo {
23
24
host : "github.com" ,
24
25
name : "test-repo" ,
25
- owner : "lucasmelin " ,
26
+ owner : "user1 " ,
26
27
},
27
28
data : Hook {
28
29
Id : 12345678 ,
@@ -37,7 +38,7 @@ func Test_createHook(t *testing.T) {
37
38
},
38
39
httpMocks : func () {
39
40
gock .New ("https://api.github.com" ).
40
- Post ("repos/lucasmelin /test-repo/hooks" ).
41
+ Post ("repos/user1 /test-repo/hooks" ).
41
42
BodyString (`{
42
43
"id":12345678,
43
44
"name":"web",
@@ -69,10 +70,10 @@ func Test_createHook(t *testing.T) {
69
70
},
70
71
"updated_at": "2019-06-03T00:57:16Z",
71
72
"created_at": "2019-06-03T00:57:16Z",
72
- "url": "https://api.github.com/repos/octocat/Hello-World /hooks/12345678",
73
- "test_url": "https://api.github.com/repos/octocat/Hello-World /hooks/12345678/test",
74
- "ping_url": "https://api.github.com/repos/octocat/Hello-World /hooks/12345678/pings",
75
- "deliveries_url": "https://api.github.com/repos/octocat/Hello-World /hooks/12345678/deliveries",
73
+ "url": "https://api.github.com/repos/user1/test-repo /hooks/12345678",
74
+ "test_url": "https://api.github.com/repos/user1/test-repo /hooks/12345678/test",
75
+ "ping_url": "https://api.github.com/repos/user1/test-repo /hooks/12345678/pings",
76
+ "deliveries_url": "https://api.github.com/repos/user1/test-repo /hooks/12345678/deliveries",
76
77
"last_response": {
77
78
"code": null,
78
79
"status": "unused",
@@ -84,6 +85,7 @@ func Test_createHook(t *testing.T) {
84
85
}
85
86
for _ , tt := range tests {
86
87
t .Run (tt .name , func (t * testing.T ) {
88
+ stubConfig (t , testConfig ())
87
89
t .Cleanup (gock .Off )
88
90
if tt .httpMocks != nil {
89
91
tt .httpMocks ()
@@ -152,6 +154,7 @@ func Test_getEvents(t *testing.T) {
152
154
}
153
155
for _ , tt := range tests {
154
156
t .Run (tt .name , func (t * testing.T ) {
157
+ stubConfig (t , testConfig ())
155
158
t .Cleanup (gock .Off )
156
159
if tt .httpMocks != nil {
157
160
tt .httpMocks ()
@@ -167,3 +170,23 @@ func Test_getEvents(t *testing.T) {
167
170
})
168
171
}
169
172
}
173
+
174
+ func stubConfig (t * testing.T , cfgStr string ) {
175
+ t .Helper ()
176
+ old := config .Read
177
+ config .Read = func () (* config.Config , error ) {
178
+ return config .ReadFromString (cfgStr ), nil
179
+ }
180
+ t .Cleanup (func () {
181
+ config .Read = old
182
+ })
183
+ }
184
+
185
+ func testConfig () string {
186
+ return `
187
+ hosts:
188
+ github.com:
189
+ user: user1
190
+ oauth_token: abc123
191
+ `
192
+ }
0 commit comments