github.com/huiliang/nomad@v0.2.1-0.20151124023127-7a8b664699ff/command/util_test.go (about) 1 package command 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/api" 7 "github.com/hashicorp/nomad/testutil" 8 ) 9 10 // seen is used to track which tests we have already 11 // marked as parallel. Marking twice causes panic. 12 var seen map[*testing.T]struct{} 13 14 func init() { 15 seen = make(map[*testing.T]struct{}) 16 } 17 18 func testServer( 19 t *testing.T, 20 cb testutil.ServerConfigCallback) (*testutil.TestServer, *api.Client, string) { 21 22 // Always run these tests in parallel. 23 if _, ok := seen[t]; !ok { 24 seen[t] = struct{}{} 25 t.Parallel() 26 } 27 28 // Make a new test server 29 srv := testutil.NewTestServer(t, cb) 30 31 // Make a client 32 clientConf := api.DefaultConfig() 33 clientConf.Address = "http://" + srv.HTTPAddr 34 client, err := api.NewClient(clientConf) 35 if err != nil { 36 t.Fatalf("err: %s", err) 37 } 38 return srv, client, clientConf.Address 39 } 40 41 func testJob(jobID string) *api.Job { 42 task := api.NewTask("task1", "exec"). 43 Require(&api.Resources{MemoryMB: 256}) 44 45 group := api.NewTaskGroup("group1", 1). 46 AddTask(task) 47 48 job := api.NewBatchJob(jobID, jobID, "region1", 1). 49 AddDatacenter("dc1"). 50 AddTaskGroup(group) 51 52 return job 53 }