api: remove MockJob from exported functions

`api.MockJob` is a test utility, that's only used by `command/agent`
package.  This moves it to the package and removes it from the public
API.
This commit is contained in:
Mahmood Ali 2019-01-18 13:00:28 -05:00
parent 253532ec00
commit 6bdb9864de
2 changed files with 22 additions and 21 deletions

View file

@ -130,7 +130,7 @@ func TestHTTP_JobsRegister(t *testing.T) {
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
// Create the job
job := api.MockJob()
job := MockJob()
args := api.JobRegisterRequest{
Job: job,
WriteRequest: api.WriteRequest{Region: "global"},
@ -185,7 +185,7 @@ func TestHTTP_JobsRegister_ACL(t *testing.T) {
t.Parallel()
httpACLTest(t, nil, func(s *TestAgent) {
// Create the job
job := api.MockJob()
job := MockJob()
args := api.JobRegisterRequest{
Job: job,
WriteRequest: api.WriteRequest{
@ -215,7 +215,7 @@ func TestHTTP_JobsRegister_Defaulting(t *testing.T) {
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
// Create the job
job := api.MockJob()
job := MockJob()
// Do not set its priority
job.Priority = nil
@ -411,7 +411,7 @@ func TestHTTP_JobUpdate(t *testing.T) {
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
// Create the job
job := api.MockJob()
job := MockJob()
args := api.JobRegisterRequest{
Job: job,
WriteRequest: api.WriteRequest{
@ -985,7 +985,7 @@ func TestHTTP_JobPlan(t *testing.T) {
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
// Create the job
job := api.MockJob()
job := MockJob()
args := api.JobPlanRequest{
Job: job,
Diff: true,

View file

@ -1,14 +1,15 @@
package api
package agent
import (
"time"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/uuid"
)
func MockJob() *Job {
job := &Job{
func MockJob() *api.Job {
job := &api.Job{
Region: helper.StringToPtr("global"),
ID: helper.StringToPtr(uuid.Generate()),
Name: helper.StringToPtr("my-job"),
@ -16,27 +17,27 @@ func MockJob() *Job {
Priority: helper.IntToPtr(50),
AllAtOnce: helper.BoolToPtr(false),
Datacenters: []string{"dc1"},
Constraints: []*Constraint{
Constraints: []*api.Constraint{
{
LTarget: "${attr.kernel.name}",
RTarget: "linux",
Operand: "=",
},
},
TaskGroups: []*TaskGroup{
TaskGroups: []*api.TaskGroup{
{
Name: helper.StringToPtr("web"),
Count: helper.IntToPtr(10),
EphemeralDisk: &EphemeralDisk{
EphemeralDisk: &api.EphemeralDisk{
SizeMB: helper.IntToPtr(150),
},
RestartPolicy: &RestartPolicy{
RestartPolicy: &api.RestartPolicy{
Attempts: helper.IntToPtr(3),
Interval: helper.TimeToPtr(10 * time.Minute),
Delay: helper.TimeToPtr(1 * time.Minute),
Mode: helper.StringToPtr("delay"),
},
Tasks: []*Task{
Tasks: []*api.Task{
{
Name: "web",
Driver: "exec",
@ -46,12 +47,12 @@ func MockJob() *Job {
Env: map[string]string{
"FOO": "bar",
},
Services: []*Service{
Services: []*api.Service{
{
Name: "${TASK}-frontend",
PortLabel: "http",
Tags: []string{"pci:${meta.pci-dss}", "datacenter:${node.datacenter}"},
Checks: []ServiceCheck{
Checks: []api.ServiceCheck{
{
Name: "check-table",
Type: "script",
@ -67,14 +68,14 @@ func MockJob() *Job {
PortLabel: "admin",
},
},
LogConfig: DefaultLogConfig(),
Resources: &Resources{
LogConfig: api.DefaultLogConfig(),
Resources: &api.Resources{
CPU: helper.IntToPtr(500),
MemoryMB: helper.IntToPtr(256),
Networks: []*NetworkResource{
Networks: []*api.NetworkResource{
{
MBits: helper.IntToPtr(50),
DynamicPorts: []Port{{Label: "http"}, {Label: "admin"}},
DynamicPorts: []api.Port{{Label: "http"}, {Label: "admin"}},
},
},
},
@ -98,10 +99,10 @@ func MockJob() *Job {
return job
}
func MockPeriodicJob() *Job {
func MockPeriodicJob() *api.Job {
j := MockJob()
j.Type = helper.StringToPtr("batch")
j.Periodic = &PeriodicConfig{
j.Periodic = &api.PeriodicConfig{
Enabled: helper.BoolToPtr(true),
SpecType: helper.StringToPtr("cron"),
Spec: helper.StringToPtr("*/30 * * * *"),