diff --git a/api/compose_test.go b/api/compose_test.go index b8f6d781a..db2e1d359 100644 --- a/api/compose_test.go +++ b/api/compose_test.go @@ -32,7 +32,7 @@ func TestCompose(t *testing.T) { AddTask(task) // Compose a job - job := NewServiceJob("job1", "myjob", 2). + job := NewServiceJob("job1", "myjob", "region1", 2). SetMeta("foo", "bar"). AddDatacenter("dc1"). Constrain(HardConstraint("kernel.name", "=", "linux")). @@ -40,6 +40,7 @@ func TestCompose(t *testing.T) { // Check that the composed result looks correct expect := &Job{ + Region: "region1", ID: "job1", Name: "myjob", Type: JobTypeService, diff --git a/api/jobs.go b/api/jobs.go index 3d66c3cfd..c0003a4e5 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -126,23 +126,24 @@ type JobListStub struct { // NewServiceJob creates and returns a new service-style job // for long-lived processes using the provided name, ID, and // relative job priority. -func NewServiceJob(id, name string, pri int) *Job { - return newJob(id, name, JobTypeService, pri) +func NewServiceJob(id, name, region string, pri int) *Job { + return newJob(id, name, region, JobTypeService, pri) } // NewBatchJob creates and returns a new batch-style job for // short-lived processes using the provided name and ID along // with the relative job priority. -func NewBatchJob(id, name string, pri int) *Job { - return newJob(id, name, JobTypeBatch, pri) +func NewBatchJob(id, name, region string, pri int) *Job { + return newJob(id, name, region, JobTypeBatch, pri) } // newJob is used to create a new Job struct. -func newJob(jobID, jobName, jobType string, pri int) *Job { +func newJob(id, name, region, typ string, pri int) *Job { return &Job{ - ID: jobID, - Name: jobName, - Type: jobType, + Region: region, + ID: id, + Name: name, + Type: typ, Priority: pri, } } diff --git a/api/jobs_test.go b/api/jobs_test.go index 8f576c635..e42420db2 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -218,8 +218,9 @@ func TestJobs_ForceEvaluate(t *testing.T) { } func TestJobs_NewBatchJob(t *testing.T) { - job := NewBatchJob("job1", "myjob", 5) + job := NewBatchJob("job1", "myjob", "region1", 5) expect := &Job{ + Region: "region1", ID: "job1", Name: "myjob", Type: JobTypeBatch, @@ -231,8 +232,9 @@ func TestJobs_NewBatchJob(t *testing.T) { } func TestJobs_NewServiceJob(t *testing.T) { - job := NewServiceJob("job1", "myjob", 5) + job := NewServiceJob("job1", "myjob", "region1", 5) expect := &Job{ + Region: "region1", ID: "job1", Name: "myjob", Type: JobTypeService, diff --git a/api/util_test.go b/api/util_test.go index 102382178..a4ebc1e45 100644 --- a/api/util_test.go +++ b/api/util_test.go @@ -26,27 +26,15 @@ func assertWriteMeta(t *testing.T, wm *WriteMeta) { } func testJob() *Job { - return &Job{ - Region: "region1", - ID: "job1", - Name: "redis", - Type: JobTypeService, - Datacenters: []string{"dc1"}, - TaskGroups: []*TaskGroup{ - &TaskGroup{ - Name: "group1", - Count: 1, - Tasks: []*Task{ - &Task{ - Name: "task1", - Driver: "exec", - Resources: &Resources{ - MemoryMB: 256, - }, - }, - }, - }, - }, - Priority: 1, - } + task := NewTask("task1", "exec"). + Require(&Resources{MemoryMB: 256}) + + group := NewTaskGroup("group1", 1). + AddTask(task) + + job := NewBatchJob("job1", "redis", "region1", 1). + AddDatacenter("dc1"). + AddTaskGroup(group) + + return job }