From b7c2e009fd68d69e16e19b4f2fc4555f5fadea53 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Tue, 8 Sep 2015 16:45:16 -0700 Subject: [PATCH] api: return query meta/write meta --- api/allocs.go | 10 ++++------ api/allocs_test.go | 5 ++++- api/job.go | 8 ++++---- api/job_test.go | 15 ++++++++++++--- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/api/allocs.go b/api/allocs.go index 7928b92bd..02ebfb9e4 100644 --- a/api/allocs.go +++ b/api/allocs.go @@ -11,13 +11,13 @@ func (c *Client) Allocs() *Allocs { } // List returns a list of all of the allocations. -func (a *Allocs) List() ([]*Alloc, error) { +func (a *Allocs) List() ([]*Alloc, *QueryMeta, error) { var resp []*Alloc - _, err := a.client.query("/v1/allocations", &resp, nil) + qm, err := a.client.query("/v1/allocations", &resp, nil) if err != nil { - return nil, err + return nil, nil, err } - return resp, nil + return resp, qm, nil } // Alloc is used for serialization of allocations. @@ -32,6 +32,4 @@ type Alloc struct { DesiredDescription string ClientStatus string ClientDescription string - CreateIndex uint64 - ModifyIndex uint64 } diff --git a/api/allocs_test.go b/api/allocs_test.go index 95561042f..6063dfd1a 100644 --- a/api/allocs_test.go +++ b/api/allocs_test.go @@ -10,10 +10,13 @@ func TestAllocs_List(t *testing.T) { a := c.Allocs() // Querying when no allocs exist returns nothing - allocs, err := a.List() + allocs, qm, err := a.List() if err != nil { t.Fatalf("err: %s", err) } + if qm.LastIndex != 0 { + t.Fatalf("bad index: %d", qm.LastIndex) + } if n := len(allocs); n != 0 { t.Fatalf("expected 0 allocs, got: %d", n) } diff --git a/api/job.go b/api/job.go index beec9910b..01ecbb908 100644 --- a/api/job.go +++ b/api/job.go @@ -24,13 +24,13 @@ func (j *Jobs) Register(job *Job, q *WriteOptions) (string, *WriteMeta, error) { } // List is used to list all of the existing jobs. -func (j *Jobs) List() ([]*Job, error) { +func (j *Jobs) List() ([]*Job, *QueryMeta, error) { var resp []*Job - _, err := j.client.query("/v1/jobs", &resp, nil) + qm, err := j.client.query("/v1/jobs", &resp, nil) if err != nil { - return nil, err + return nil, qm, err } - return resp, nil + return resp, qm, nil } // Job is used to serialize a job. diff --git a/api/job_test.go b/api/job_test.go index bf9c38d40..832ad56ed 100644 --- a/api/job_test.go +++ b/api/job_test.go @@ -11,10 +11,13 @@ func TestJobs_Register(t *testing.T) { jobs := c.Jobs() // Listing jobs before registering returns nothing - resp, err := jobs.List() + resp, qm, err := jobs.List() if err != nil { t.Fatalf("err: %s", err) } + if qm.LastIndex != 0 { + t.Fatalf("bad index: %d", qm.LastIndex) + } if n := len(resp); n != 0 { t.Fatalf("expected 0 jobs, got: %d", n) } @@ -26,19 +29,25 @@ func TestJobs_Register(t *testing.T) { Type: "service", Priority: 1, } - eval, _, err := jobs.Register(job, nil) + eval, wm, err := jobs.Register(job, nil) if err != nil { t.Fatalf("err: %s", err) } if eval == "" { t.Fatalf("missing eval id") } + if wm.LastIndex == 0 { + t.Fatalf("bad index: %d", wm.LastIndex) + } // Query the jobs back out again - resp, err = jobs.List() + resp, qm, err = jobs.List() if err != nil { t.Fatalf("err: %s", err) } + if qm.LastIndex == 0 { + t.Fatalf("bad index: %d", qm.LastIndex) + } // Check that we got the expected response expect := []*Job{job}