github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/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  }
    58  
    59  func testNamespace() *Namespace {
    60  	return &Namespace{
    61  		Name:        "test-namespace",
    62  		Description: "Testing namespaces",
    63  	}
    64  }
    65  
    66  func testQuotaSpec() *QuotaSpec {
    67  	return &QuotaSpec{
    68  		Name:        "test-namespace",
    69  		Description: "Testing namespaces",
    70  		Limits: []*QuotaLimit{
    71  			{
    72  				Region: "global",
    73  				RegionLimit: &Resources{
    74  					CPU:      helper.IntToPtr(2000),
    75  					MemoryMB: helper.IntToPtr(2000),
    76  				},
    77  			},
    78  		},
    79  	}
    80  }