using contexts constants in replace of string contexts

fix up endpoints
This commit is contained in:
Chelsea Holland Komlo
2017-08-11 14:44:46 +00:00
parent 01b3338b71
commit 4edc38d5c2
8 changed files with 88 additions and 107 deletions

View File

@@ -1,11 +1,12 @@
package contexts
// Context is a type which is searchable via a unique identifier.
type Context string
const (
Alloc Context = "allocs"
Eval Context = "evals"
Job Context = "jobs"
Node Context = "nodes"
All Context = ""
Allocs Context = "allocs"
Evals Context = "evals"
Jobs Context = "jobs"
Nodes Context = "nodes"
All Context = ""
)

View File

@@ -18,7 +18,7 @@ func (c *Client) Search() *Search {
// context is not specified, matches for all contexts are returned.
func (s *Search) PrefixSearch(prefix string, context c.Context) (*structs.SearchResponse, error) {
var resp structs.SearchResponse
req := &structs.SearchRequest{Prefix: prefix, Context: string(context)}
req := &structs.SearchRequest{Prefix: prefix, Context: context}
_, err := s.client.write("/v1/search", req, &resp, nil)
if err != nil {

View File

@@ -25,7 +25,7 @@ func TestSearch_List(t *testing.T) {
assert.Nil(err)
assert.NotEqual(0, resp.Index)
jobMatches := resp.Matches[contexts.jobs]
jobMatches := resp.Matches[contexts.Jobs]
assert.Equal(1, len(jobMatches))
assert.Equal(id, jobMatches[0])
}