@@ -14,7 +14,7 @@ import (
14
14
"github.com/google/go-cmp/cmp"
15
15
)
16
16
17
- func TestRepositoriesService_GetCodeownersErrors (t * testing.T ) {
17
+ func TestRepositoriesService_GetCodeownersErrors_noRef (t * testing.T ) {
18
18
client , mux , _ , teardown := setup ()
19
19
defer teardown ()
20
20
@@ -38,7 +38,7 @@ func TestRepositoriesService_GetCodeownersErrors(t *testing.T) {
38
38
})
39
39
40
40
ctx := context .Background ()
41
- codeownersErrors , _ , err := client .Repositories .GetCodeownersErrors (ctx , "o" , "r" )
41
+ codeownersErrors , _ , err := client .Repositories .GetCodeownersErrors (ctx , "o" , "r" , nil )
42
42
if err != nil {
43
43
t .Errorf ("Repositories.GetCodeownersErrors returned error: %v" , err )
44
44
}
@@ -62,12 +62,75 @@ func TestRepositoriesService_GetCodeownersErrors(t *testing.T) {
62
62
63
63
const methodName = "GetCodeownersErrors"
64
64
testBadOptions (t , methodName , func () (err error ) {
65
- _ , _ , err = client .Repositories .GetCodeownersErrors (ctx , "\n " , "\n " )
65
+ _ , _ , err = client .Repositories .GetCodeownersErrors (ctx , "\n " , "\n " , nil )
66
66
return err
67
67
})
68
68
69
69
testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
70
- got , resp , err := client .Repositories .GetCodeownersErrors (ctx , "o" , "r" )
70
+ got , resp , err := client .Repositories .GetCodeownersErrors (ctx , "o" , "r" , nil )
71
+ if got != nil {
72
+ t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
73
+ }
74
+ return resp , err
75
+ })
76
+ }
77
+
78
+ func TestRepositoriesService_GetCodeownersErrors_specificRef (t * testing.T ) {
79
+ client , mux , _ , teardown := setup ()
80
+ defer teardown ()
81
+
82
+ mux .HandleFunc ("/repos/o/r/codeowners/errors" , func (w http.ResponseWriter , r * http.Request ) {
83
+ testMethod (t , r , "GET" )
84
+ testHeader (t , r , "Accept" , mediaTypeV3 )
85
+ testFormValues (t , r , values {"ref" : "mybranch" })
86
+ fmt .Fprint (w , `{
87
+ "errors": [
88
+ {
89
+ "line": 1,
90
+ "column": 1,
91
+ "kind": "Invalid pattern",
92
+ "source": "***/*.rb @monalisa",
93
+ "suggestion": "Did you mean **/*.rb?",
94
+ "message": "Invalid pattern on line 3: Did you mean **/*.rb?\n\n ***/*.rb @monalisa\n ^",
95
+ "path": ".github/CODEOWNERS"
96
+ }
97
+ ]
98
+ }
99
+ ` )
100
+ })
101
+
102
+ opts := & GetCodeownersErrorsOptions {Ref : "mybranch" }
103
+ ctx := context .Background ()
104
+ codeownersErrors , _ , err := client .Repositories .GetCodeownersErrors (ctx , "o" , "r" , opts )
105
+ if err != nil {
106
+ t .Errorf ("Repositories.GetCodeownersErrors returned error: %v" , err )
107
+ }
108
+
109
+ want := & CodeownersErrors {
110
+ Errors : []* CodeownersError {
111
+ {
112
+ Line : 1 ,
113
+ Column : 1 ,
114
+ Kind : "Invalid pattern" ,
115
+ Source : "***/*.rb @monalisa" ,
116
+ Suggestion : String ("Did you mean **/*.rb?" ),
117
+ Message : "Invalid pattern on line 3: Did you mean **/*.rb?\n \n ***/*.rb @monalisa\n ^" ,
118
+ Path : ".github/CODEOWNERS" ,
119
+ },
120
+ },
121
+ }
122
+ if ! cmp .Equal (codeownersErrors , want ) {
123
+ t .Errorf ("Repositories.GetCodeownersErrors returned %+v, want %+v" , codeownersErrors , want )
124
+ }
125
+
126
+ const methodName = "GetCodeownersErrors"
127
+ testBadOptions (t , methodName , func () (err error ) {
128
+ _ , _ , err = client .Repositories .GetCodeownersErrors (ctx , "\n " , "\n " , opts )
129
+ return err
130
+ })
131
+
132
+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
133
+ got , resp , err := client .Repositories .GetCodeownersErrors (ctx , "o" , "r" , opts )
71
134
if got != nil {
72
135
t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
73
136
}
0 commit comments