@@ -14,7 +14,7 @@ import (
1414 "github.com/google/go-cmp/cmp"
1515)
1616
17- func TestRepositoriesService_GetCodeownersErrors (t * testing.T ) {
17+ func TestRepositoriesService_GetCodeownersErrors_noRef (t * testing.T ) {
1818 client , mux , _ , teardown := setup ()
1919 defer teardown ()
2020
@@ -38,7 +38,7 @@ func TestRepositoriesService_GetCodeownersErrors(t *testing.T) {
3838 })
3939
4040 ctx := context .Background ()
41- codeownersErrors , _ , err := client .Repositories .GetCodeownersErrors (ctx , "o" , "r" )
41+ codeownersErrors , _ , err := client .Repositories .GetCodeownersErrors (ctx , "o" , "r" , nil )
4242 if err != nil {
4343 t .Errorf ("Repositories.GetCodeownersErrors returned error: %v" , err )
4444 }
@@ -62,12 +62,75 @@ func TestRepositoriesService_GetCodeownersErrors(t *testing.T) {
6262
6363 const methodName = "GetCodeownersErrors"
6464 testBadOptions (t , methodName , func () (err error ) {
65- _ , _ , err = client .Repositories .GetCodeownersErrors (ctx , "\n " , "\n " )
65+ _ , _ , err = client .Repositories .GetCodeownersErrors (ctx , "\n " , "\n " , nil )
6666 return err
6767 })
6868
6969 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 )
71134 if got != nil {
72135 t .Errorf ("testNewRequestAndDoFailure %v = %#v, want nil" , methodName , got )
73136 }
0 commit comments