github.com/ranjib/nomad@v0.1.1-0.20160225204057-97751b02f70b/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{ 44 MemoryMB: 256, 45 DiskMB: 20, 46 CPU: 100, 47 }). 48 SetLogConfig(&api.LogConfig{ 49 MaxFiles: 1, 50 MaxFileSizeMB: 2, 51 }) 52 53 group := api.NewTaskGroup("group1", 1). 54 AddTask(task) 55 56 job := api.NewBatchJob(jobID, jobID, "region1", 1). 57 AddDatacenter("dc1"). 58 AddTaskGroup(group) 59 60 return job 61 }