open-nomad/command/util_test.go

68 lines
1.5 KiB
Go
Raw Normal View History

2015-09-11 18:10:20 +00:00
package command
import (
"testing"
2015-09-12 21:50:05 +00:00
"github.com/hashicorp/nomad/api"
2017-02-13 23:18:17 +00:00
"github.com/hashicorp/nomad/helper"
2015-09-12 21:50:05 +00:00
"github.com/hashicorp/nomad/testutil"
2015-09-11 18:10:20 +00:00
)
2015-09-14 21:08:50 +00:00
// seen is used to track which tests we have already
// marked as parallel. Marking twice causes panic.
var seen map[*testing.T]struct{}
func init() {
seen = make(map[*testing.T]struct{})
}
func testServer(
t *testing.T,
cb testutil.ServerConfigCallback) (*testutil.TestServer, *api.Client, string) {
2015-09-13 18:39:49 +00:00
// Always run these tests in parallel.
if _, ok := seen[t]; !ok {
seen[t] = struct{}{}
t.Parallel()
}
2015-09-13 18:39:49 +00:00
// Make a new test server
srv := testutil.NewTestServer(t, cb)
2015-09-12 21:50:05 +00:00
// Make a client
clientConf := api.DefaultConfig()
clientConf.Address = "http://" + srv.HTTPAddr
2015-09-12 21:50:05 +00:00
client, err := api.NewClient(clientConf)
if err != nil {
t.Fatalf("err: %s", err)
}
return srv, client, clientConf.Address
2015-09-11 18:10:20 +00:00
}
func testJob(jobID string) *api.Job {
2016-08-22 16:35:25 +00:00
task := api.NewTask("task1", "mock_driver").
SetConfig("kill_after", "1s").
SetConfig("run_for", "5s").
SetConfig("exit_code", 0).
2016-02-02 21:50:30 +00:00
Require(&api.Resources{
2017-02-13 23:18:17 +00:00
MemoryMB: helper.IntToPtr(256),
CPU: helper.IntToPtr(100),
2016-02-19 23:49:32 +00:00
}).
2016-02-11 18:42:56 +00:00
SetLogConfig(&api.LogConfig{
2017-02-13 23:18:17 +00:00
MaxFiles: helper.IntToPtr(1),
MaxFileSizeMB: helper.IntToPtr(2),
2016-02-19 23:49:32 +00:00
})
group := api.NewTaskGroup("group1", 1).
2016-08-26 04:05:21 +00:00
AddTask(task).
RequireDisk(&api.EphemeralDisk{
2017-02-13 23:18:17 +00:00
SizeMB: helper.IntToPtr(20),
2016-08-26 04:05:21 +00:00
})
job := api.NewBatchJob(jobID, jobID, "region1", 1).
AddDatacenter("dc1").
AddTaskGroup(group)
return job
}