aboutsummaryrefslogtreecommitdiffstats
path: root/lulu.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2026-07-29 14:56:34 -0230
committerSam Anthony <sam@samanthony.xyz>2026-07-29 14:56:34 -0230
commit0594075ecc77c672f33ce9e36dbf1c1a6c89ccb7 (patch)
treeeecb7b36ecb68bd80793d426c09d0e936a70e396 /lulu.go
parent80ca94381b48d5766c5bcf7897a804d6e2443a69 (diff)
downloadlulu-0594075ecc77c672f33ce9e36dbf1c1a6c89ccb7.zip
test Jobs()
Diffstat (limited to 'lulu.go')
-rw-r--r--lulu.go40
1 files changed, 16 insertions, 24 deletions
diff --git a/lulu.go b/lulu.go
index 9228e28..8532052 100644
--- a/lulu.go
+++ b/lulu.go
@@ -255,30 +255,30 @@ func (c *Client) Jobs(queries ...PrintJobQuery) ([]PrintJob, error) {
q.apply(queries...)
qvals := q.vals()
- verify := func(v any) error {
- resp := v.(*jobsResp)
- if int(resp.Count) != len(resp.Results) {
- return fmt.Errorf("count (%d) != len(results) (%d)", resp.Count, len(resp.Results))
- } else if len(resp.Results) == 0 && resp.Next != "" {
- return fmt.Errorf("no results on this page, but server returned a next page: %s", resp.Next)
- }
- return nil
- }
-
var jobs []PrintJob
+ var cnt uint
for page := 1; ; page++ {
qvals.Set("page", fmt.Sprint(page))
var resp jobsResp
- if err := c.getQueryDecodeVerify(printJobsPath, qvals, &resp, verify); err != nil {
+ if err := c.getQueryDecode(printJobsPath, qvals, &resp); err != nil {
return jobs, pkgErr(err)
}
+
+ cnt = resp.Count
+ if len(resp.Results) == 0 && resp.Next != "" {
+ return jobs, pkgErr(fmt.Errorf("no results on this page, but server returned a next page: %s", resp.Next))
+ }
if len(resp.Results) > 0 {
jobs = append(jobs, resp.Results...)
}
if len(resp.Results) == 0 || len(resp.Next) == 0 {
- return jobs, nil
+ break
}
}
+ if uint(len(jobs)) != cnt {
+ return jobs, pkgErr(fmt.Errorf("expected %d jobs, got %d", cnt, len(jobs)))
+ }
+ return jobs, nil
}
// Job retrieves the print job with the given ID.
@@ -388,13 +388,11 @@ func (c *Client) Cancel(id uint64) error {
// getDecode sends a GET request and unmarshals the response.
func (c *Client) getDecode(path string, v any) error {
- verify := func(v any) error { return nil }
- return c.getQueryDecodeVerify(path, nil, v, verify)
+ return c.getQueryDecode(path, url.Values{}, v)
}
-// getDecodeVerify sends a GET /path/?query request and unmarshals and
-// verifies the response.
-func (c *Client) getQueryDecodeVerify(path string, query url.Values, v any, verify func(any) error) error {
+// getQueryDecode sends a GET path?query request and unmarshals the response into v.
+func (c *Client) getQueryDecode(path string, query url.Values, v any) error {
url, err := url.JoinPath(ApiUrl, path)
if err != nil {
return err
@@ -409,13 +407,7 @@ func (c *Client) getQueryDecodeVerify(path string, query url.Values, v any, veri
if resp.StatusCode != http.StatusOK {
return errRespStatus{resp}
}
- if err := decodeResponse(resp, v); err != nil {
- return err
- }
- if err := verify(v); err != nil {
- return errResp{resp, err}
- }
- return nil
+ return decodeResponse(resp, v)
}
// postDecode sends a POST request and unmarshals the response.