mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
test resources endpoint will return matching prefixes
This commit is contained in:
@@ -46,7 +46,7 @@ func TestHTTP_ResourcesWithSingleJob(t *testing.T) {
|
||||
httpTest(t, nil, func(s *TestAgent) {
|
||||
createJobForTest(testJob, s, t)
|
||||
|
||||
endpoint := fmt.Sprintf("/v1/resources?context=job&prefix=%s", testJobPrefix)
|
||||
endpoint := fmt.Sprintf("/v1/resources?context=job&prefix=%s&context=job", testJobPrefix)
|
||||
req, err := http.NewRequest("GET", endpoint, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
@@ -72,6 +72,47 @@ func TestHTTP_ResourcesWithSingleJob(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTP_ResourcesWithMultipleJobs(t *testing.T) {
|
||||
testJobA := "aaaaaaaa-e8f7-fd38-c855-ab94ceb89706"
|
||||
testJobB := "aaaaaaaa-e8f7-fd38-c855-ab94ceb89707"
|
||||
testJobC := "bbbbbbbb-e8f7-fd38-c855-ab94ceb89707"
|
||||
|
||||
testJobPrefix := "aaaaaaaa-e8f7-fd38"
|
||||
|
||||
t.Parallel()
|
||||
httpTest(t, nil, func(s *TestAgent) {
|
||||
createJobForTest(testJobA, s, t)
|
||||
createJobForTest(testJobB, s, t)
|
||||
createJobForTest(testJobC, s, t)
|
||||
|
||||
endpoint := fmt.Sprintf("/v1/resources?context=job&prefix=%s&context=job", testJobPrefix)
|
||||
req, err := http.NewRequest("GET", endpoint, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
respW := httptest.NewRecorder()
|
||||
|
||||
resp, err := s.Server.ResourcesRequest(respW, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
res := resp.(*structs.ResourcesListStub)
|
||||
if len(res.Matches) != 1 {
|
||||
t.Fatalf("No expected key values in resources list")
|
||||
}
|
||||
|
||||
j := res.Matches["jobs"]
|
||||
if j == nil || len(j) != 2 {
|
||||
t.Fatalf("The number of jobs that were returned does not equal the number of jobs we expected (2)", j)
|
||||
}
|
||||
|
||||
assert.Contains(t, j, testJobA)
|
||||
assert.Contains(t, j, testJobB)
|
||||
assert.NotContains(t, j, testJobC)
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
//func TestHTTP_ResourcesWithNoJob(t *testing.T) {
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user