github.com/bigcommerce/nomad@v0.9.3-bc/nomad/plan_endpoint_test.go (about)

     1  package nomad
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	msgpackrpc "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  	t.Parallel()
    15  	s1 := TestServer(t, func(c *Config) {
    16  		c.NumSchedulers = 0
    17  	})
    18  	defer s1.Shutdown()
    19  	codec := rpcClient(t, s1)
    20  	testutil.WaitForLeader(t, s1.RPC)
    21  
    22  	// Create the register request
    23  	eval1 := mock.Eval()
    24  	s1.evalBroker.Enqueue(eval1)
    25  
    26  	evalOut, token, err := s1.evalBroker.Dequeue([]string{eval1.Type}, time.Second)
    27  	if err != nil {
    28  		t.Fatalf("err: %v", err)
    29  	}
    30  	if evalOut != eval1 {
    31  		t.Fatalf("Bad eval")
    32  	}
    33  
    34  	// Submit a plan
    35  	plan := mock.Plan()
    36  	plan.EvalID = eval1.ID
    37  	plan.EvalToken = token
    38  	plan.Job = mock.Job()
    39  	req := &structs.PlanRequest{
    40  		Plan:         plan,
    41  		WriteRequest: structs.WriteRequest{Region: "global"},
    42  	}
    43  	var resp structs.PlanResponse
    44  	if err := msgpackrpc.CallWithCodec(codec, "Plan.Submit", req, &resp); err != nil {
    45  		t.Fatalf("err: %v", err)
    46  	}
    47  	if resp.Result == nil {
    48  		t.Fatalf("missing result")
    49  	}
    50  }