Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cleanup] remove deprecated PagedResponse types from fake_linode_test #237

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,3 @@ linters:
- musttag
- exhaustive
- nilnil

issues:
exclude-rules:
- path: cloud/linode/fake_linode_test.go
text: 'SA1019: (.+).(NodeBalancersPagedResponse|NodeBalancerConfigsPagedResponse|NodeBalancerNodesPagedResponse|FirewallDevicesPagedResponse) is deprecated: (NodeBalancersPagedResponse|NodeBalancerConfigsPagedResponse|NodeBalancerNodesPagedResponse|FirewallDevicesPagedResponse) exists for historical compatibility and should not be used.'
51 changes: 26 additions & 25 deletions cloud/linode/fake_linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ func (f *fakeAPI) didRequestOccur(method, path, body string) bool {
return ok
}

// paginatedResponse represents a single response from a paginated
// endpoint.
type paginatedResponse[T any] struct {
Page int `json:"page" url:"page,omitempty"`
Pages int `json:"pages" url:"pages,omitempty"`
Results int `json:"results" url:"results,omitempty"`
Data []T `json:"data"`
}

func (f *fakeAPI) setupRoutes() {
f.mux.HandleFunc("GET /v4/nodebalancers", func(w http.ResponseWriter, r *http.Request) {
res := 0
Expand All @@ -97,13 +106,12 @@ func (f *fakeAPI) setupRoutes() {
}
}
}
resp := linodego.NodeBalancersPagedResponse{
PageOptions: &linodego.PageOptions{
Page: 1,
Pages: 1,
Results: res,
},
Data: data,

resp := paginatedResponse[linodego.NodeBalancer]{
Page: 1,
Pages: 1,
Results: res,
Data: data,
}
rr, _ := json.Marshal(resp)
_, _ = w.Write(rr)
Expand Down Expand Up @@ -178,13 +186,11 @@ func (f *fakeAPI) setupRoutes() {
}
}
}
resp := linodego.NodeBalancerConfigsPagedResponse{
PageOptions: &linodego.PageOptions{
Page: 1,
Pages: 1,
Results: res,
},
Data: data,
resp := paginatedResponse[linodego.NodeBalancerConfig]{
Page: 1,
Pages: 1,
Results: res,
Data: data,
}
rr, err := json.Marshal(resp)
if err != nil {
Expand All @@ -208,13 +214,11 @@ func (f *fakeAPI) setupRoutes() {
}
}

resp := linodego.NodeBalancerNodesPagedResponse{
PageOptions: &linodego.PageOptions{
Page: 1,
Pages: 1,
Results: res,
},
Data: data,
resp := paginatedResponse[linodego.NodeBalancerNode]{
Page: 1,
Pages: 1,
Results: res,
Data: data,
}
rr, _ := json.Marshal(resp)
_, _ = w.Write(rr)
Expand Down Expand Up @@ -243,10 +247,7 @@ func (f *fakeAPI) setupRoutes() {
for i := range firewallDevices {
firewallDeviceList = append(firewallDeviceList, *firewallDevices[i])
}
rr, _ := json.Marshal(linodego.FirewallDevicesPagedResponse{
PageOptions: &linodego.PageOptions{Page: 1, Pages: 1, Results: len(firewallDeviceList)},
Data: firewallDeviceList,
})
rr, _ := json.Marshal(paginatedResponse[linodego.FirewallDevice]{Page: 1, Pages: 1, Results: len(firewallDeviceList), Data: firewallDeviceList})
_, _ = w.Write(rr)
})

Expand Down
Loading