github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/api/util_test.go (about)

     1  package api
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/nomad/helper"
     7  )
     8  
     9  func assertQueryMeta(t *testing.T, qm *QueryMeta) {
    10  	if qm.LastIndex == 0 {
    11  		t.Fatalf("bad index: %d", qm.LastIndex)
    12  	}
    13  	if !qm.KnownLeader {
    14  		t.Fatalf("expected known leader, got none")
    15  	}
    16  }
    17  
    18  func assertWriteMeta(t *testing.T, wm *WriteMeta) {
    19  	if wm.LastIndex == 0 {
    20  		t.Fatalf("bad index: %d", wm.LastIndex)
    21  	}
    22  }
    23  
    24  func testJob() *Job {
    25  	task := NewTask("task1", "exec").
    26  		SetConfig("command", "/bin/sleep").
    27  		Require(&Resources{
    28  			CPU:      helper.IntToPtr(100),
    29  			MemoryMB: helper.IntToPtr(256),
    30  			IOPS:     helper.IntToPtr(10),
    31  		}).
    32  		SetLogConfig(&LogConfig{
    33  			MaxFiles:      helper.IntToPtr(1),
    34  			MaxFileSizeMB: helper.IntToPtr(2),
    35  		})
    36  
    37  	group := NewTaskGroup("group1", 1).
    38  		AddTask(task).
    39  		RequireDisk(&EphemeralDisk{
    40  			SizeMB: helper.IntToPtr(25),
    41  		})
    42  
    43  	job := NewBatchJob("job1", "redis", "region1", 1).
    44  		AddDatacenter("dc1").
    45  		AddTaskGroup(group)
    46  
    47  	return job
    48  }
    49  
    50  func testPeriodicJob() *Job {
    51  	job := testJob().AddPeriodicConfig(&PeriodicConfig{
    52  		Enabled:  helper.BoolToPtr(true),
    53  		Spec:     helper.StringToPtr("*/30 * * * *"),
    54  		SpecType: helper.StringToPtr("cron"),
    55  	})
    56  	return job
    57  }