Skip to content

Commit f4a8dba

Browse files
CopilotJoannaaKL
andcommitted
Migrate security_advisories_test.go to testify mocks
Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
1 parent 637de7a commit f4a8dba

File tree

4 files changed

+98
-145
lines changed

4 files changed

+98
-145
lines changed

pkg/github/helper_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ const (
108108
GetReposDependabotAlertsByOwnerByRepoByAlertNumber = "GET /repos/{owner}/{repo}/dependabot/alerts/{alert_number}"
109109

110110
// Security advisories endpoints
111-
GetAdvisories = "GET /advisories"
112-
GetAdvisoriesByGhsaId = "GET /advisories/{ghsa_id}"
111+
GetAdvisories = "GET /advisories"
112+
GetAdvisoriesByGhsaId = "GET /advisories/{ghsa_id}"
113+
GetReposSecurityAdvisoriesByOwnerByRepo = "GET /repos/{owner}/{repo}/security-advisories"
114+
GetOrgsSecurityAdvisoriesByOrg = "GET /orgs/{org}/security-advisories"
113115

114116
// Actions endpoints
115117
GetReposActionsWorkflowsByOwnerByRepo = "GET /repos/{owner}/{repo}/actions/workflows"

pkg/github/repositories_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func Test_GetFileContents(t *testing.T) {
9595
}),
9696
),
9797
mock.WithRequestMatchHandler(
98-
raw.GetRawReposContentsByOwnerByRepoByBranchByPath,
98+
GetRawReposContentsByOwnerByRepoByBranchByPath,
9999
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
100100
w.Header().Set("Content-Type", "text/markdown")
101101
_, _ = w.Write(mockRawContent)
@@ -140,7 +140,7 @@ func Test_GetFileContents(t *testing.T) {
140140
}),
141141
),
142142
mock.WithRequestMatchHandler(
143-
raw.GetRawReposContentsByOwnerByRepoByBranchByPath,
143+
GetRawReposContentsByOwnerByRepoByBranchByPath,
144144
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
145145
w.Header().Set("Content-Type", "image/png")
146146
_, _ = w.Write(mockRawContent)
@@ -185,7 +185,7 @@ func Test_GetFileContents(t *testing.T) {
185185
}),
186186
),
187187
mock.WithRequestMatchHandler(
188-
raw.GetRawReposContentsByOwnerByRepoByBranchByPath,
188+
GetRawReposContentsByOwnerByRepoByBranchByPath,
189189
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
190190
w.Header().Set("Content-Type", "application/pdf")
191191
_, _ = w.Write(mockRawContent)
@@ -229,7 +229,7 @@ func Test_GetFileContents(t *testing.T) {
229229
),
230230
),
231231
mock.WithRequestMatchHandler(
232-
raw.GetRawReposContentsByOwnerByRepoByPath,
232+
GetRawReposContentsByOwnerByRepoByPath,
233233
expectQueryParams(t, map[string]string{
234234
"branch": "main",
235235
}).andThen(
@@ -263,7 +263,7 @@ func Test_GetFileContents(t *testing.T) {
263263
}),
264264
),
265265
mock.WithRequestMatchHandler(
266-
raw.GetRawReposContentsByOwnerByRepoByPath,
266+
GetRawReposContentsByOwnerByRepoByPath,
267267
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
268268
w.WriteHeader(http.StatusNotFound)
269269
_, _ = w.Write([]byte(`{"message": "Not Found"}`))

pkg/github/repository_resource_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Test_repositoryResourceContents(t *testing.T) {
3636
name: "missing owner",
3737
mockedClient: mock.NewMockedHTTPClient(
3838
mock.WithRequestMatchHandler(
39-
raw.GetRawReposContentsByOwnerByRepoByPath,
39+
GetRawReposContentsByOwnerByRepoByPath,
4040
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
4141
w.Header().Set("Content-Type", "text/markdown")
4242
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository."))
@@ -55,7 +55,7 @@ func Test_repositoryResourceContents(t *testing.T) {
5555
name: "missing repo",
5656
mockedClient: mock.NewMockedHTTPClient(
5757
mock.WithRequestMatchHandler(
58-
raw.GetRawReposContentsByOwnerByRepoByBranchByPath,
58+
GetRawReposContentsByOwnerByRepoByBranchByPath,
5959
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
6060
w.Header().Set("Content-Type", "text/markdown")
6161
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository."))
@@ -74,7 +74,7 @@ func Test_repositoryResourceContents(t *testing.T) {
7474
name: "successful blob content fetch",
7575
mockedClient: mock.NewMockedHTTPClient(
7676
mock.WithRequestMatchHandler(
77-
raw.GetRawReposContentsByOwnerByRepoByPath,
77+
GetRawReposContentsByOwnerByRepoByPath,
7878
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
7979
w.Header().Set("Content-Type", "image/png")
8080
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository."))
@@ -98,7 +98,7 @@ func Test_repositoryResourceContents(t *testing.T) {
9898
name: "successful text content fetch (HEAD)",
9999
mockedClient: mock.NewMockedHTTPClient(
100100
mock.WithRequestMatchHandler(
101-
raw.GetRawReposContentsByOwnerByRepoByPath,
101+
GetRawReposContentsByOwnerByRepoByPath,
102102
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
103103
w.Header().Set("Content-Type", "text/markdown")
104104
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository."))
@@ -122,7 +122,7 @@ func Test_repositoryResourceContents(t *testing.T) {
122122
name: "successful text content fetch (HEAD)",
123123
mockedClient: mock.NewMockedHTTPClient(
124124
mock.WithRequestMatchHandler(
125-
raw.GetRawReposContentsByOwnerByRepoByPath,
125+
GetRawReposContentsByOwnerByRepoByPath,
126126
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
127127
w.Header().Set("Content-Type", "text/plain")
128128

@@ -148,7 +148,7 @@ func Test_repositoryResourceContents(t *testing.T) {
148148
name: "successful text content fetch (branch)",
149149
mockedClient: mock.NewMockedHTTPClient(
150150
mock.WithRequestMatchHandler(
151-
raw.GetRawReposContentsByOwnerByRepoByBranchByPath,
151+
GetRawReposContentsByOwnerByRepoByBranchByPath,
152152
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
153153
w.Header().Set("Content-Type", "text/markdown")
154154
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository."))
@@ -172,7 +172,7 @@ func Test_repositoryResourceContents(t *testing.T) {
172172
name: "successful text content fetch (tag)",
173173
mockedClient: mock.NewMockedHTTPClient(
174174
mock.WithRequestMatchHandler(
175-
raw.GetRawReposContentsByOwnerByRepoByTagByPath,
175+
GetRawReposContentsByOwnerByRepoByTagByPath,
176176
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
177177
w.Header().Set("Content-Type", "text/markdown")
178178
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository."))
@@ -196,7 +196,7 @@ func Test_repositoryResourceContents(t *testing.T) {
196196
name: "successful text content fetch (sha)",
197197
mockedClient: mock.NewMockedHTTPClient(
198198
mock.WithRequestMatchHandler(
199-
raw.GetRawReposContentsByOwnerByRepoBySHAByPath,
199+
GetRawReposContentsByOwnerByRepoBySHAByPath,
200200
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
201201
w.Header().Set("Content-Type", "text/markdown")
202202
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository."))
@@ -228,7 +228,7 @@ func Test_repositoryResourceContents(t *testing.T) {
228228
}),
229229
),
230230
mock.WithRequestMatchHandler(
231-
raw.GetRawReposContentsByOwnerByRepoBySHAByPath,
231+
GetRawReposContentsByOwnerByRepoBySHAByPath,
232232
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
233233
w.Header().Set("Content-Type", "text/markdown")
234234
_, err := w.Write([]byte("# Test Repository\n\nThis is a test repository."))

0 commit comments

Comments
 (0)