From e14b279bc073e4cfbb52b3e98913f7b2acae2204 Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Wed, 2 Aug 2017 19:26:50 +0000 Subject: [PATCH] add truncation boolean to response --- command/agent/resources_endpoint_test.go | 2 ++ nomad/resources_endpoint.go | 10 ++++++++++ nomad/resources_endpoint_test.go | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/command/agent/resources_endpoint_test.go b/command/agent/resources_endpoint_test.go index b0652e6db..a150011c1 100644 --- a/command/agent/resources_endpoint_test.go +++ b/command/agent/resources_endpoint_test.go @@ -69,6 +69,7 @@ func TestHTTP_ResourcesWithSingleJob(t *testing.T) { } assert.Equal(t, j[0], testJob) + assert.Equal(t, res.Truncations["job"], false) }) } @@ -152,6 +153,7 @@ func TestHTTP_ResoucesListForEvaluations(t *testing.T) { assert.Contains(t, j, eval1.ID) assert.NotContains(t, j, eval2.ID) + assert.Equal(t, res.Truncations["eval"], false) }) } diff --git a/nomad/resources_endpoint.go b/nomad/resources_endpoint.go index 7414fe9aa..c7d1e1cec 100644 --- a/nomad/resources_endpoint.go +++ b/nomad/resources_endpoint.go @@ -28,6 +28,7 @@ func (r *Resources) List(args *structs.ResourcesRequest, // return jobs matching given prefix var err error var iter memdb.ResultIterator + truncations := make(map[string]bool) if args.Context == "job" { iter, err = state.JobsByIDPrefix(ws, args.Prefix) @@ -46,6 +47,10 @@ func (r *Resources) List(args *structs.ResourcesRequest, jobs = append(jobs, job.ID) } + if iter.Next() != nil { + truncations["job"] = true + } + matches["job"] = jobs } @@ -66,10 +71,15 @@ func (r *Resources) List(args *structs.ResourcesRequest, evals = append(evals, eval.ID) } + if iter.Next() != nil { + truncations["eval"] = true + } + matches["eval"] = evals } reply.Matches = matches + reply.Truncations = truncations return nil }} diff --git a/nomad/resources_endpoint_test.go b/nomad/resources_endpoint_test.go index 5e64c0156..fa97a9ed6 100644 --- a/nomad/resources_endpoint_test.go +++ b/nomad/resources_endpoint_test.go @@ -86,6 +86,8 @@ func TestResourcesEndpoint_List_ShouldTruncateResultsToUnder20(t *testing.T) { if num_matches != 20 { t.Fatalf(fmt.Sprintf("err: the number of jobs expected %d does not match the number of jobs returned %d", 20, num_matches)) } + + assert.Equal(t, resp.Truncations["job"], true) } func TestResourcesEndpoint_List_ShouldReturnEvals(t *testing.T) { @@ -122,4 +124,6 @@ func TestResourcesEndpoint_List_ShouldReturnEvals(t *testing.T) { if recEval != eval1.ID { t.Fatalf(fmt.Sprintf("err: expected %s evaluation but received %s", eval1.ID, recEval)) } + + assert.Equal(t, resp.Truncations["job"], false) }