github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/nomad/plan_endpoint_test.go (about) 1 package nomad 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/hashicorp/net-rpc-msgpackrpc" 8 "github.com/hashicorp/nomad/nomad/mock" 9 "github.com/hashicorp/nomad/nomad/structs" 10 "github.com/hashicorp/nomad/testutil" 11 ) 12 13 func TestPlanEndpoint_Submit(t *testing.T) { 14 s1 := testServer(t, func(c *Config) { 15 c.NumSchedulers = 0 16 }) 17 defer s1.Shutdown() 18 codec := rpcClient(t, s1) 19 testutil.WaitForLeader(t, s1.RPC) 20 21 // Create the register request 22 eval1 := mock.Eval() 23 s1.evalBroker.Enqueue(eval1) 24 25 evalOut, token, err := s1.evalBroker.Dequeue([]string{eval1.Type}, time.Second) 26 if err != nil { 27 t.Fatalf("err: %v", err) 28 } 29 if evalOut != eval1 { 30 t.Fatalf("Bad eval") 31 } 32 33 // Submit a plan 34 plan := mock.Plan() 35 plan.EvalID = eval1.ID 36 plan.EvalToken = token 37 req := &structs.PlanRequest{ 38 Plan: plan, 39 WriteRequest: structs.WriteRequest{Region: "global"}, 40 } 41 var resp structs.PlanResponse 42 if err := msgpackrpc.CallWithCodec(codec, "Plan.Submit", req, &resp); err != nil { 43 t.Fatalf("err: %v", err) 44 } 45 if resp.Result == nil { 46 t.Fatalf("missing result") 47 } 48 }