From a5d60fd31c35a189dff3c5139107d1b9691bf20f Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 18 Jan 2019 13:00:28 -0500 Subject: [PATCH] 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. --- command/agent/job_endpoint_test.go | 10 +++--- .../agent/testingutils_test.go | 33 ++++++++++--------- 2 files changed, 22 insertions(+), 21 deletions(-) rename api/jobs_testing.go => command/agent/testingutils_test.go (79%) diff --git a/command/agent/job_endpoint_test.go b/command/agent/job_endpoint_test.go index 2d79baecf..87ef38fd8 100644 --- a/command/agent/job_endpoint_test.go +++ b/command/agent/job_endpoint_test.go @@ -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, diff --git a/api/jobs_testing.go b/command/agent/testingutils_test.go similarity index 79% rename from api/jobs_testing.go rename to command/agent/testingutils_test.go index 1bd47496c..63fc2603f 100644 --- a/api/jobs_testing.go +++ b/command/agent/testingutils_test.go @@ -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 * * * *"),