coder/codersdk/pagination_test.go
Mathias Fredriksson 2d3dc436a8 feat: Implement unified pagination and add template versions support (#1308)
* feat: Implement pagination for template versions

* feat: Use unified pagination between users and template versions

* Sync codepaths between users and template versions

* Create requestOption type in codersdk and add test

* Fix created_at edge case for pagination cursor in queries

* feat: Add support for json omitempty and embedded structs in apitypings (#1318)

* Add scripts/apitypings/main.go to Makefile
2022-05-10 07:44:09 +00:00

61 lines
1.1 KiB
Go

//nolint:testpackage
package codersdk
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func TestPagination_asRequestOption(t *testing.T) {
t.Parallel()
uuid1 := uuid.New()
type fields struct {
AfterID uuid.UUID
Limit int
Offset int
}
tests := []struct {
name string
fields fields
want url.Values
}{
{
name: "Test AfterID is set",
fields: fields{AfterID: uuid1},
want: url.Values{"after_id": []string{uuid1.String()}},
},
{
name: "Test Limit is set",
fields: fields{Limit: 10},
want: url.Values{"limit": []string{"10"}},
},
{
name: "Test Offset is set",
fields: fields{Offset: 10},
want: url.Values{"offset": []string{"10"}},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
p := Pagination{
AfterID: tt.fields.AfterID,
Limit: tt.fields.Limit,
Offset: tt.fields.Offset,
}
req := httptest.NewRequest(http.MethodGet, "/", nil)
p.asRequestOption()(req)
got := req.URL.Query()
assert.Equal(t, tt.want, got)
})
}
}