add truncation boolean to response

This commit is contained in:
Chelsea Holland Komlo
2017-08-02 19:26:50 +00:00
parent dfd8c1d832
commit e14b279bc0
3 changed files with 16 additions and 0 deletions

View File

@@ -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)
})
}

View File

@@ -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
}}

View File

@@ -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)
}