-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow lookups based on short identifiers #575
Changes from 15 commits
7ae975e
cec0170
91075e1
bdf4347
5d3bd1b
23bfbbf
7d2f1c6
dcecac1
2a809b9
1af7c57
e89b5af
9057422
db82564
8218442
a73aaf1
c65fdc3
6295108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,52 @@ func TestNodes_List(t *testing.T) { | |
assertQueryMeta(t, qm) | ||
} | ||
|
||
func TestNodes_PrefixList(t *testing.T) { | ||
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) { | ||
c.DevMode = true | ||
}) | ||
defer s.Stop() | ||
nodes := c.Nodes() | ||
|
||
var qm *QueryMeta | ||
var out []*NodeListStub | ||
var err error | ||
|
||
// Get the node ID | ||
var nodeID, dc string | ||
testutil.WaitForResult(func() (bool, error) { | ||
out, _, err := nodes.List(nil) | ||
if err != nil { | ||
return false, err | ||
} | ||
if n := len(out); n != 1 { | ||
return false, fmt.Errorf("expected 1 node, got: %d", n) | ||
} | ||
nodeID = out[0].ID | ||
dc = out[0].Datacenter | ||
return true, nil | ||
}, func(err error) { | ||
t.Fatalf("err: %s", err) | ||
}) | ||
|
||
// Find node based on four character prefix | ||
testutil.WaitForResult(func() (bool, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this have to be wrapped in a WaitForResult? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's an oversight on my part, fixed. |
||
out, qm, err = nodes.PrefixList(nodeID[:4]) | ||
if err != nil { | ||
return false, err | ||
} | ||
if n := len(out); n != 1 { | ||
return false, fmt.Errorf("expected 1 node, got: %d ", n) | ||
} | ||
return true, nil | ||
}, func(err error) { | ||
t.Fatalf("err: %s", err) | ||
}) | ||
|
||
// Check that we got valid QueryMeta. | ||
assertQueryMeta(t, qm) | ||
} | ||
|
||
func TestNodes_Info(t *testing.T) { | ||
c, s := makeClient(t, nil, func(c *testutil.TestServerConfig) { | ||
c.DevMode = true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,52 @@ func TestHTTP_AllocsList(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestHTTP_AllocsPrefixList(t *testing.T) { | ||
httpTest(t, nil, func(s *TestServer) { | ||
// Directly manipulate the state | ||
state := s.Agent.server.State() | ||
alloc1 := mock.Alloc() | ||
alloc1.ID = "aaaaaaaa-e8f7-fd38-c855-ab94ceb89706" | ||
alloc2 := mock.Alloc() | ||
alloc2.ID = "aaabbbbb-e8f7-fd38-c855-ab94ceb89706" | ||
err := state.UpsertAllocs(1000, | ||
[]*structs.Allocation{alloc1, alloc2}) | ||
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
|
||
// Make the HTTP request | ||
req, err := http.NewRequest("GET", "/v1/allocations?prefix=aaab", nil) | ||
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
respW := httptest.NewRecorder() | ||
|
||
// Make the request | ||
obj, err := s.Server.AllocsRequest(respW, req) | ||
if err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
|
||
// Check for the index | ||
if respW.HeaderMap.Get("X-Nomad-Index") == "" { | ||
t.Fatalf("missing index") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-KnownLeader") != "true" { | ||
t.Fatalf("missing known leader") | ||
} | ||
if respW.HeaderMap.Get("X-Nomad-LastContact") == "" { | ||
t.Fatalf("missing last contact") | ||
} | ||
|
||
// Check the job | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check the alloc |
||
n := obj.([]*structs.AllocListStub) | ||
if len(n) != 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also test that you get the right ID |
||
t.Fatalf("bad: %#v", n) | ||
} | ||
}) | ||
} | ||
|
||
func TestHTTP_AllocQuery(t *testing.T) { | ||
httpTest(t, nil, func(s *TestServer) { | ||
// Directly manipulate the state | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is also added in the structs. Once this PR is done I will take a look at removing the api specific structs and using those in the structs package as specified in issue #329 .