mirror of
https://github.com/goauthentik/authentik
synced 2026-04-28 02:18:11 +02:00
* packages/client-go: init Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * format Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove mod/sum Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix translate Signed-off-by: Jens Langhammer <jens@goauthentik.io> * no go replace Signed-off-by: Jens Langhammer <jens@goauthentik.io> * update rust makefile with pwd Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix build Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix docs Signed-off-by: Jens Langhammer <jens@goauthentik.io> * don't need a version ig? Signed-off-by: Jens Langhammer <jens@goauthentik.io> * exclude go client from cspell Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix main docker build Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
86 lines
1.9 KiB
Go
86 lines
1.9 KiB
Go
package ak
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
api "goauthentik.io/packages/client-go"
|
|
)
|
|
|
|
type fakeAPIType struct{}
|
|
|
|
type fakeAPIResponse struct {
|
|
results []fakeAPIType
|
|
pagination api.Pagination
|
|
}
|
|
|
|
func (fapi *fakeAPIResponse) GetResults() []fakeAPIType { return fapi.results }
|
|
func (fapi *fakeAPIResponse) GetPagination() api.Pagination { return fapi.pagination }
|
|
|
|
type fakeAPIRequest struct {
|
|
res *fakeAPIResponse
|
|
http *http.Response
|
|
err error
|
|
}
|
|
|
|
func (fapi *fakeAPIRequest) Page(page int32) *fakeAPIRequest { return fapi }
|
|
func (fapi *fakeAPIRequest) PageSize(size int32) *fakeAPIRequest { return fapi }
|
|
func (fapi *fakeAPIRequest) Execute() (*fakeAPIResponse, *http.Response, error) {
|
|
return fapi.res, fapi.http, fapi.err
|
|
}
|
|
|
|
func Test_Simple(t *testing.T) {
|
|
req := &fakeAPIRequest{
|
|
res: &fakeAPIResponse{
|
|
results: []fakeAPIType{
|
|
{},
|
|
},
|
|
pagination: api.Pagination{
|
|
TotalPages: 1,
|
|
},
|
|
},
|
|
}
|
|
res, err := Paginator(req, PaginatorOptions{})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, res, 1)
|
|
}
|
|
|
|
func Test_BadRequest(t *testing.T) {
|
|
req := &fakeAPIRequest{
|
|
http: &http.Response{
|
|
StatusCode: 400,
|
|
},
|
|
err: errors.New("foo"),
|
|
}
|
|
res, err := Paginator(req, PaginatorOptions{})
|
|
assert.Error(t, err)
|
|
assert.Equal(t, []fakeAPIType{}, res)
|
|
}
|
|
|
|
// func Test_PaginatorCompile(t *testing.T) {
|
|
// req := api.ApiCoreUsersListRequest{}
|
|
// Paginator(req, PaginatorOptions{
|
|
// PageSize: 100,
|
|
// })
|
|
// }
|
|
|
|
// func Test_PaginatorCompileExplicit(t *testing.T) {
|
|
// req := api.ApiCoreUsersListRequest{}
|
|
// Paginator[
|
|
// api.User,
|
|
// api.ApiCoreUsersListRequest,
|
|
// *api.PaginatedUserList,
|
|
// ](req, PaginatorOptions{
|
|
// PageSize: 100,
|
|
// })
|
|
// }
|
|
|
|
// func Test_PaginatorCompileOther(t *testing.T) {
|
|
// req := api.ApiOutpostsProxyListRequest{}
|
|
// Paginator(req, PaginatorOptions{
|
|
// PageSize: 100,
|
|
// })
|
|
// }
|