Skip to content

Commit

Permalink
[JOBS-12224] Update API test template with page tokens (#417)
Browse files Browse the repository at this point in the history
## Changes
Update API test template with page tokens added in
databricks/universe#320579

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [x] `make test` passing
- [x] `make fmt` applied
- [x] relevant integration tests applied
  • Loading branch information
oleksiidav authored Jun 7, 2023
1 parent 38fb330 commit 2da40a7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .codegen/api.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (a *{{.Service.Name}}API) {{.PascalName}}AndWait(ctx context.Context{{if .R
func (a *{{.Service.Name}}API) {{.PascalName}}All(ctx context.Context{{if .Request}}, request {{.Request.PascalName}}{{end}}) ([]{{.Pagination.Entity.PascalName}}, error) {
{{if .Pagination.MultiRequest}}var results []{{.Pagination.Entity.PascalName}}
{{ if .Pagination.Limit -}}
var totalCount {{template "type" .Pagination.Offset.Entity}} = 0
var totalCount {{template "type" .Pagination.Limit.Entity}} = 0
{{ end -}}
ctx = useragent.InContext(ctx, "sdk-feature", "pagination")
{{if .Pagination.NeedsOffsetDedupe -}}
Expand All @@ -132,7 +132,10 @@ func (a *{{.Service.Name}}API) {{.PascalName}}All(ctx context.Context{{if .Reque
{{- end}}
results = append(results, v)
}
{{ if .Pagination.Offset -}}
{{ if and .Pagination.Token .Pagination.Limit -}}
count := {{template "type" .Pagination.Limit.Entity}}(len(response.{{.Pagination.Results.PascalName}}))
totalCount += count
{{ else if .Pagination.Offset -}}
count := {{template "type" .Pagination.Offset.Entity}}(len(response.{{.Pagination.Results.PascalName}}))
totalCount += count
{{ end -}}
Expand Down

0 comments on commit 2da40a7

Please sign in to comment.