github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/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/helper" 8 "github.com/hashicorp/nomad/testutil" 9 ) 10 11 // seen is used to track which tests we have already 12 // marked as parallel. Marking twice causes panic. 13 var seen map[*testing.T]struct{} 14 15 func init() { 16 seen = make(map[*testing.T]struct{}) 17 } 18 19 func testServer( 20 t *testing.T, 21 cb testutil.ServerConfigCallback) (*testutil.TestServer, *api.Client, string) { 22 23 // Always run these tests in parallel. 24 if _, ok := seen[t]; !ok { 25 seen[t] = struct{}{} 26 t.Parallel() 27 } 28 29 // Make a new test server 30 srv := testutil.NewTestServer(t, cb) 31 32 // Make a client 33 clientConf := api.DefaultConfig() 34 clientConf.Address = "http://" + srv.HTTPAddr 35 client, err := api.NewClient(clientConf) 36 if err != nil { 37 t.Fatalf("err: %s", err) 38 } 39 return srv, client, clientConf.Address 40 } 41 42 func testJob(jobID string) *api.Job { 43 task := api.NewTask("task1", "mock_driver"). 44 SetConfig("kill_after", "1s"). 45 SetConfig("run_for", "5s"). 46 SetConfig("exit_code", 0). 47 Require(&api.Resources{ 48 MemoryMB: helper.IntToPtr(256), 49 CPU: helper.IntToPtr(100), 50 }). 51 SetLogConfig(&api.LogConfig{ 52 MaxFiles: helper.IntToPtr(1), 53 MaxFileSizeMB: helper.IntToPtr(2), 54 }) 55 56 group := api.NewTaskGroup("group1", 1). 57 AddTask(task). 58 RequireDisk(&api.EphemeralDisk{ 59 SizeMB: helper.IntToPtr(20), 60 }) 61 62 job := api.NewBatchJob(jobID, jobID, "region1", 1). 63 AddDatacenter("dc1"). 64 AddTaskGroup(group) 65 66 return job 67 }