Skip to content

Commit 55028d2

Browse files
committed
codersdk: Add test for Pagination.asRequestOption
1 parent 8a67746 commit 55028d2

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

codersdk/pagination_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package codersdk
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"net/url"
7+
"testing"
8+
9+
"github.com/google/uuid"
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestPagination_asRequestOption(t *testing.T) {
14+
uuid1 := uuid.New()
15+
type fields struct {
16+
AfterID uuid.UUID
17+
Limit int
18+
Offset int
19+
}
20+
tests := []struct {
21+
name string
22+
fields fields
23+
want url.Values
24+
}{
25+
{
26+
name: "Test AfterID is set",
27+
fields: fields{AfterID: uuid1},
28+
want: url.Values{"after_id": []string{uuid1.String()}},
29+
},
30+
{
31+
name: "Test Limit is set",
32+
fields: fields{Limit: 10},
33+
want: url.Values{"limit": []string{"10"}},
34+
},
35+
{
36+
name: "Test Offset is set",
37+
fields: fields{Offset: 10},
38+
want: url.Values{"offset": []string{"10"}},
39+
},
40+
}
41+
for _, tt := range tests {
42+
t.Run(tt.name, func(t *testing.T) {
43+
p := Pagination{
44+
AfterID: tt.fields.AfterID,
45+
Limit: tt.fields.Limit,
46+
Offset: tt.fields.Offset,
47+
}
48+
req := httptest.NewRequest(http.MethodGet, "/", nil)
49+
p.asRequestOption()(req)
50+
got := req.URL.Query()
51+
assert.Equal(t, tt.want, got)
52+
})
53+
}
54+
}

0 commit comments

Comments
 (0)