Skip to content

Commit 0b6bb05

Browse files
committed
Improve test coverage
1 parent 6f83310 commit 0b6bb05

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

github/repos_codeowners_test.go

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

@@ -75,6 +75,68 @@ func TestRepositoriesService_GetCodeownersErrors(t *testing.T) {
7575
})
7676
}
7777

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+
fmt.Fprint(w, `{
86+
"errors": [
87+
{
88+
"line": 1,
89+
"column": 1,
90+
"kind": "Invalid pattern",
91+
"source": "***/*.rb @monalisa",
92+
"suggestion": "Did you mean **/*.rb?",
93+
"message": "Invalid pattern on line 3: Did you mean **/*.rb?\n\n ***/*.rb @monalisa\n ^",
94+
"path": ".github/CODEOWNERS"
95+
}
96+
]
97+
}
98+
`)
99+
})
100+
101+
opts := &GetCodeownersErrorsOptions{Ref: "mybranch"}
102+
ctx := context.Background()
103+
codeownersErrors, _, err := client.Repositories.GetCodeownersErrors(ctx, "o", "r", opts)
104+
if err != nil {
105+
t.Errorf("Repositories.GetCodeownersErrors returned error: %v", err)
106+
}
107+
108+
want := &CodeownersErrors{
109+
Errors: []*CodeownersError{
110+
{
111+
Line: 1,
112+
Column: 1,
113+
Kind: "Invalid pattern",
114+
Source: "***/*.rb @monalisa",
115+
Suggestion: String("Did you mean **/*.rb?"),
116+
Message: "Invalid pattern on line 3: Did you mean **/*.rb?\n\n ***/*.rb @monalisa\n ^",
117+
Path: ".github/CODEOWNERS",
118+
},
119+
},
120+
}
121+
if !cmp.Equal(codeownersErrors, want) {
122+
t.Errorf("Repositories.GetCodeownersErrors returned %+v, want %+v", codeownersErrors, want)
123+
}
124+
125+
const methodName = "GetCodeownersErrors"
126+
testBadOptions(t, methodName, func() (err error) {
127+
_, _, err = client.Repositories.GetCodeownersErrors(ctx, "\n", "\n", opts)
128+
return err
129+
})
130+
131+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
132+
got, resp, err := client.Repositories.GetCodeownersErrors(ctx, "o", "r", opts)
133+
if got != nil {
134+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
135+
}
136+
return resp, err
137+
})
138+
}
139+
78140
func TestCodeownersErrors_Marshal(t *testing.T) {
79141
testJSONMarshal(t, &CodeownersErrors{}, "{}")
80142

0 commit comments

Comments
 (0)