mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 17:05:43 +03:00
add endpoint tests
This commit is contained in:
@@ -914,3 +914,101 @@ func TestJobEndpoint_Evaluations(t *testing.T) {
|
||||
t.Fatalf("bad: %#v", resp2.Evaluations)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJobEndpoint_Plan_WithDiff(t *testing.T) {
|
||||
s1 := testServer(t, func(c *Config) {
|
||||
c.NumSchedulers = 0 // Prevent automatic dequeue
|
||||
})
|
||||
defer s1.Shutdown()
|
||||
codec := rpcClient(t, s1)
|
||||
testutil.WaitForLeader(t, s1.RPC)
|
||||
|
||||
// Create the register request
|
||||
job := mock.Job()
|
||||
req := &structs.JobRegisterRequest{
|
||||
Job: job,
|
||||
WriteRequest: structs.WriteRequest{Region: "global"},
|
||||
}
|
||||
|
||||
// Fetch the response
|
||||
var resp structs.JobRegisterResponse
|
||||
if err := msgpackrpc.CallWithCodec(codec, "Job.Register", req, &resp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if resp.Index == 0 {
|
||||
t.Fatalf("bad index: %d", resp.Index)
|
||||
}
|
||||
|
||||
// Create a plan request
|
||||
planReq := &structs.JobPlanRequest{
|
||||
Job: job,
|
||||
Diff: true,
|
||||
WriteRequest: structs.WriteRequest{Region: "global"},
|
||||
}
|
||||
|
||||
// Fetch the response
|
||||
var planResp structs.JobPlanResponse
|
||||
if err := msgpackrpc.CallWithCodec(codec, "Job.Plan", planReq, &planResp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Check the response
|
||||
if planResp.Cas == 0 {
|
||||
t.Fatalf("bad cas: %d", planResp.Cas)
|
||||
}
|
||||
if planResp.Plan == nil {
|
||||
t.Fatalf("no plan")
|
||||
}
|
||||
if planResp.Diff == nil {
|
||||
t.Fatalf("no diff")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJobEndpoint_Plan_NoDiff(t *testing.T) {
|
||||
s1 := testServer(t, func(c *Config) {
|
||||
c.NumSchedulers = 0 // Prevent automatic dequeue
|
||||
})
|
||||
defer s1.Shutdown()
|
||||
codec := rpcClient(t, s1)
|
||||
testutil.WaitForLeader(t, s1.RPC)
|
||||
|
||||
// Create the register request
|
||||
job := mock.Job()
|
||||
req := &structs.JobRegisterRequest{
|
||||
Job: job,
|
||||
WriteRequest: structs.WriteRequest{Region: "global"},
|
||||
}
|
||||
|
||||
// Fetch the response
|
||||
var resp structs.JobRegisterResponse
|
||||
if err := msgpackrpc.CallWithCodec(codec, "Job.Register", req, &resp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if resp.Index == 0 {
|
||||
t.Fatalf("bad index: %d", resp.Index)
|
||||
}
|
||||
|
||||
// Create a plan request
|
||||
planReq := &structs.JobPlanRequest{
|
||||
Job: job,
|
||||
Diff: false,
|
||||
WriteRequest: structs.WriteRequest{Region: "global"},
|
||||
}
|
||||
|
||||
// Fetch the response
|
||||
var planResp structs.JobPlanResponse
|
||||
if err := msgpackrpc.CallWithCodec(codec, "Job.Plan", planReq, &planResp); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Check the response
|
||||
if planResp.Cas == 0 {
|
||||
t.Fatalf("bad cas: %d", planResp.Cas)
|
||||
}
|
||||
if planResp.Plan == nil {
|
||||
t.Fatalf("no plan")
|
||||
}
|
||||
if planResp.Diff != nil {
|
||||
t.Fatalf("got diff")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user