Skip to content

Commit

Permalink
enhance(workers): add list filters for GetAll (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Jan 10, 2024
1 parent 23e6a2e commit 4a16c92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion vela/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import (
// the server methods of the Vela API.
type WorkerService service

// WorkerListOptions specifies the optional parameters to the
// Worker.GetAll method.
type WorkerListOptions struct {
Active string `url:"active,omitempty"`
CheckedInBefore int64 `url:"checked_in_before,omitempty"`
CheckedInAfter int64 `url:"checked_in_after,omitempty"`
}

// Get returns the provided worker.
func (svc *WorkerService) Get(hostname string) (*library.Worker, *Response, error) {
// set the API endpoint path we send the request to
Expand All @@ -27,10 +35,16 @@ func (svc *WorkerService) Get(hostname string) (*library.Worker, *Response, erro
}

// GetAll returns a list of all workers.
func (svc *WorkerService) GetAll() (*[]library.Worker, *Response, error) {
func (svc *WorkerService) GetAll(opt *WorkerListOptions) (*[]library.Worker, *Response, error) {
// set the API endpoint path we send the request to
u := "/api/v1/workers"

// add optional arguments if supplied
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}

// slice library Worker type we want to return
v := new([]library.Worker)

Expand Down
4 changes: 2 additions & 2 deletions vela/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestWorker_GetAll_200(t *testing.T) {
_ = json.Unmarshal(data, &want)

// run test
got, resp, err := c.Worker.GetAll()
got, resp, err := c.Worker.GetAll(nil)

if err != nil {
t.Errorf("Worker get all returned err: %v", err)
Expand Down Expand Up @@ -312,7 +312,7 @@ func ExampleWorkerService_GetAll() {
c.Authentication.SetPersonalAccessTokenAuth("token")

// Get all the workers from the server
workers, resp, err := c.Worker.GetAll()
workers, resp, err := c.Worker.GetAll(nil)
if err != nil {
fmt.Println(err)
}
Expand Down

0 comments on commit 4a16c92

Please sign in to comment.