github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/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 testutil.WaitForResult(func() (bool, error) { 24 err := s1.evalBroker.Enqueue(eval1) 25 return err == nil, err 26 }, func(err error) { 27 t.Fatalf("err: %v", err) 28 }) 29 evalOut, token, err := s1.evalBroker.Dequeue([]string{eval1.Type}, time.Second) 30 if err != nil { 31 t.Fatalf("err: %v", err) 32 } 33 if evalOut != eval1 { 34 t.Fatalf("Bad eval") 35 } 36 37 // Submit a plan 38 plan := mock.Plan() 39 plan.EvalID = eval1.ID 40 plan.EvalToken = token 41 req := &structs.PlanRequest{ 42 Plan: plan, 43 WriteRequest: structs.WriteRequest{Region: "global"}, 44 } 45 var resp structs.PlanResponse 46 if err := msgpackrpc.CallWithCodec(codec, "Plan.Submit", req, &resp); err != nil { 47 t.Fatalf("err: %v", err) 48 } 49 if resp.Result == nil { 50 t.Fatalf("missing result") 51 } 52 }