github.com/thomasobenaus/nomad@v0.11.1/command/agent/testingutils_test.go (about) 1 package agent 2 3 import ( 4 "time" 5 6 "github.com/hashicorp/nomad/api" 7 "github.com/hashicorp/nomad/helper" 8 "github.com/hashicorp/nomad/helper/uuid" 9 ) 10 11 func MockJob() *api.Job { 12 job := &api.Job{ 13 Region: helper.StringToPtr("global"), 14 ID: helper.StringToPtr(uuid.Generate()), 15 Name: helper.StringToPtr("my-job"), 16 Type: helper.StringToPtr("service"), 17 Priority: helper.IntToPtr(50), 18 AllAtOnce: helper.BoolToPtr(false), 19 Datacenters: []string{"dc1"}, 20 Constraints: []*api.Constraint{ 21 { 22 LTarget: "${attr.kernel.name}", 23 RTarget: "linux", 24 Operand: "=", 25 }, 26 }, 27 TaskGroups: []*api.TaskGroup{ 28 { 29 Name: helper.StringToPtr("web"), 30 Count: helper.IntToPtr(10), 31 EphemeralDisk: &api.EphemeralDisk{ 32 SizeMB: helper.IntToPtr(150), 33 }, 34 RestartPolicy: &api.RestartPolicy{ 35 Attempts: helper.IntToPtr(3), 36 Interval: helper.TimeToPtr(10 * time.Minute), 37 Delay: helper.TimeToPtr(1 * time.Minute), 38 Mode: helper.StringToPtr("delay"), 39 }, 40 Tasks: []*api.Task{ 41 { 42 Name: "web", 43 Driver: "exec", 44 Config: map[string]interface{}{ 45 "command": "/bin/date", 46 }, 47 Env: map[string]string{ 48 "FOO": "bar", 49 }, 50 Services: []*api.Service{ 51 { 52 Name: "${TASK}-frontend", 53 PortLabel: "http", 54 Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"}, 55 Checks: []api.ServiceCheck{ 56 { 57 Name: "check-table", 58 Type: "script", 59 Command: "/usr/local/check-table-${meta.database}", 60 Args: []string{"${meta.version}"}, 61 Interval: 30 * time.Second, 62 Timeout: 5 * time.Second, 63 }, 64 }, 65 }, 66 { 67 Name: "${TASK}-admin", 68 PortLabel: "admin", 69 }, 70 }, 71 LogConfig: api.DefaultLogConfig(), 72 Resources: &api.Resources{ 73 CPU: helper.IntToPtr(500), 74 MemoryMB: helper.IntToPtr(256), 75 Networks: []*api.NetworkResource{ 76 { 77 MBits: helper.IntToPtr(50), 78 DynamicPorts: []api.Port{{Label: "http"}, {Label: "admin"}}, 79 }, 80 }, 81 }, 82 Meta: map[string]string{ 83 "foo": "bar", 84 }, 85 }, 86 }, 87 Meta: map[string]string{ 88 "elb_check_type": "http", 89 "elb_check_interval": "30s", 90 "elb_check_min": "3", 91 }, 92 }, 93 }, 94 Meta: map[string]string{ 95 "owner": "armon", 96 }, 97 } 98 job.Canonicalize() 99 return job 100 } 101 102 func MockRegionalJob() *api.Job { 103 j := MockJob() 104 j.Region = helper.StringToPtr("north-america") 105 return j 106 }