github.com/djenriquez/nomad-1@v0.8.1/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  	t.Helper()
    11  	if qm.LastIndex == 0 {
    12  		t.Fatalf("bad index: %d", qm.LastIndex)
    13  	}
    14  	if !qm.KnownLeader {
    15  		t.Fatalf("expected known leader, got none")
    16  	}
    17  }
    18  
    19  func assertWriteMeta(t *testing.T, wm *WriteMeta) {
    20  	t.Helper()
    21  	if wm.LastIndex == 0 {
    22  		t.Fatalf("bad index: %d", wm.LastIndex)
    23  	}
    24  }
    25  
    26  func testJob() *Job {
    27  	task := NewTask("task1", "exec").
    28  		SetConfig("command", "/bin/sleep").
    29  		Require(&Resources{
    30  			CPU:      helper.IntToPtr(100),
    31  			MemoryMB: helper.IntToPtr(256),
    32  			IOPS:     helper.IntToPtr(10),
    33  		}).
    34  		SetLogConfig(&LogConfig{
    35  			MaxFiles:      helper.IntToPtr(1),
    36  			MaxFileSizeMB: helper.IntToPtr(2),
    37  		})
    38  
    39  	group := NewTaskGroup("group1", 1).
    40  		AddTask(task).
    41  		RequireDisk(&EphemeralDisk{
    42  			SizeMB: helper.IntToPtr(25),
    43  		})
    44  
    45  	job := NewBatchJob("job1", "redis", "region1", 1).
    46  		AddDatacenter("dc1").
    47  		AddTaskGroup(group)
    48  
    49  	return job
    50  }
    51  
    52  func testPeriodicJob() *Job {
    53  	job := testJob().AddPeriodicConfig(&PeriodicConfig{
    54  		Enabled:  helper.BoolToPtr(true),
    55  		Spec:     helper.StringToPtr("*/30 * * * *"),
    56  		SpecType: helper.StringToPtr("cron"),
    57  	})
    58  	return job
    59  }
    60  
    61  func testNamespace() *Namespace {
    62  	return &Namespace{
    63  		Name:        "test-namespace",
    64  		Description: "Testing namespaces",
    65  	}
    66  }
    67  
    68  func testQuotaSpec() *QuotaSpec {
    69  	return &QuotaSpec{
    70  		Name:        "test-namespace",
    71  		Description: "Testing namespaces",
    72  		Limits: []*QuotaLimit{
    73  			{
    74  				Region: "global",
    75  				RegionLimit: &Resources{
    76  					CPU:      helper.IntToPtr(2000),
    77  					MemoryMB: helper.IntToPtr(2000),
    78  				},
    79  			},
    80  		},
    81  	}
    82  }