Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slimmer /api package #5213

Merged
merged 5 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions api/allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"time"

"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -35,9 +34,9 @@ func TestAllocations_List(t *testing.T) {
return

//job := &Job{
//ID: helper.StringToPtr("job1"),
//Name: helper.StringToPtr("Job #1"),
//Type: helper.StringToPtr(JobTypeService),
//ID: stringToPtr("job1"),
//Name: stringToPtr("Job #1"),
//Type: stringToPtr(JobTypeService),
//}
//eval, _, err := c.Jobs().Register(job, nil)
//if err != nil {
Expand Down Expand Up @@ -82,9 +81,9 @@ func TestAllocations_PrefixList(t *testing.T) {
return

//job := &Job{
//ID: helper.StringToPtr("job1"),
//Name: helper.StringToPtr("Job #1"),
//Type: helper.StringToPtr(JobTypeService),
//ID: stringToPtr("job1"),
//Name: stringToPtr("Job #1"),
//Type: stringToPtr(JobTypeService),
//}

//eval, _, err := c.Jobs().Register(job, nil)
Expand Down Expand Up @@ -130,13 +129,13 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
t.Parallel()
// Create a job, task group and alloc
job := &Job{
Name: helper.StringToPtr("foo"),
Namespace: helper.StringToPtr(DefaultNamespace),
ID: helper.StringToPtr("bar"),
ParentID: helper.StringToPtr("lol"),
Name: stringToPtr("foo"),
Namespace: stringToPtr(DefaultNamespace),
ID: stringToPtr("bar"),
ParentID: stringToPtr("lol"),
TaskGroups: []*TaskGroup{
{
Name: helper.StringToPtr("bar"),
Name: stringToPtr("bar"),
Tasks: []*Task{
{
Name: "task1",
Expand Down Expand Up @@ -176,17 +175,17 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
{
desc: "no reschedule events",
reschedulePolicy: &ReschedulePolicy{
Attempts: helper.IntToPtr(3),
Interval: helper.TimeToPtr(15 * time.Minute),
Attempts: intToPtr(3),
Interval: timeToPtr(15 * time.Minute),
},
expAttempted: 0,
expTotal: 3,
},
{
desc: "all reschedule events within interval",
reschedulePolicy: &ReschedulePolicy{
Attempts: helper.IntToPtr(3),
Interval: helper.TimeToPtr(15 * time.Minute),
Attempts: intToPtr(3),
Interval: timeToPtr(15 * time.Minute),
},
time: time.Now(),
rescheduleTracker: &RescheduleTracker{
Expand All @@ -202,8 +201,8 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
{
desc: "some reschedule events outside interval",
reschedulePolicy: &ReschedulePolicy{
Attempts: helper.IntToPtr(3),
Interval: helper.TimeToPtr(15 * time.Minute),
Attempts: intToPtr(3),
Interval: timeToPtr(15 * time.Minute),
},
time: time.Now(),
rescheduleTracker: &RescheduleTracker{
Expand Down Expand Up @@ -242,7 +241,7 @@ func TestAllocations_RescheduleInfo(t *testing.T) {

func TestAllocations_ShouldMigrate(t *testing.T) {
t.Parallel()
require.True(t, DesiredTransition{Migrate: helper.BoolToPtr(true)}.ShouldMigrate())
require.True(t, DesiredTransition{Migrate: boolToPtr(true)}.ShouldMigrate())
require.False(t, DesiredTransition{}.ShouldMigrate())
require.False(t, DesiredTransition{Migrate: helper.BoolToPtr(false)}.ShouldMigrate())
require.False(t, DesiredTransition{Migrate: boolToPtr(false)}.ShouldMigrate())
}
34 changes: 16 additions & 18 deletions api/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package api
import (
"reflect"
"testing"

"github.com/hashicorp/nomad/helper"
)

func TestCompose(t *testing.T) {
Expand All @@ -15,13 +13,13 @@ func TestCompose(t *testing.T) {
SetMeta("foo", "bar").
Constrain(NewConstraint("kernel.name", "=", "linux")).
Require(&Resources{
CPU: helper.IntToPtr(1250),
MemoryMB: helper.IntToPtr(1024),
DiskMB: helper.IntToPtr(2048),
CPU: intToPtr(1250),
MemoryMB: intToPtr(1024),
DiskMB: intToPtr(2048),
Networks: []*NetworkResource{
{
CIDR: "0.0.0.0/0",
MBits: helper.IntToPtr(100),
MBits: intToPtr(100),
ReservedPorts: []Port{{"", 80}, {"", 443}},
},
},
Expand All @@ -47,11 +45,11 @@ func TestCompose(t *testing.T) {

// Check that the composed result looks correct
expect := &Job{
Region: helper.StringToPtr("region1"),
ID: helper.StringToPtr("job1"),
Name: helper.StringToPtr("myjob"),
Type: helper.StringToPtr(JobTypeService),
Priority: helper.IntToPtr(2),
Region: stringToPtr("region1"),
ID: stringToPtr("job1"),
Name: stringToPtr("myjob"),
Type: stringToPtr(JobTypeService),
Priority: intToPtr(2),
Datacenters: []string{
"dc1",
},
Expand All @@ -67,8 +65,8 @@ func TestCompose(t *testing.T) {
},
TaskGroups: []*TaskGroup{
{
Name: helper.StringToPtr("grp1"),
Count: helper.IntToPtr(2),
Name: stringToPtr("grp1"),
Count: intToPtr(2),
Constraints: []*Constraint{
{
LTarget: "kernel.name",
Expand All @@ -87,7 +85,7 @@ func TestCompose(t *testing.T) {
Spreads: []*Spread{
{
Attribute: "${node.datacenter}",
Weight: helper.IntToPtr(30),
Weight: intToPtr(30),
SpreadTarget: []*SpreadTarget{
{
Value: "dc1",
Expand All @@ -105,13 +103,13 @@ func TestCompose(t *testing.T) {
Name: "task1",
Driver: "exec",
Resources: &Resources{
CPU: helper.IntToPtr(1250),
MemoryMB: helper.IntToPtr(1024),
DiskMB: helper.IntToPtr(2048),
CPU: intToPtr(1250),
MemoryMB: intToPtr(1024),
DiskMB: intToPtr(2048),
Networks: []*NetworkResource{
{
CIDR: "0.0.0.0/0",
MBits: helper.IntToPtr(100),
MBits: intToPtr(100),
ReservedPorts: []Port{
{"", 80},
{"", 443},
Expand Down
9 changes: 4 additions & 5 deletions api/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

units "github.com/docker/go-units"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/testutil"
"github.com/kr/pretty"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -62,13 +61,13 @@ func TestFS_Logs(t *testing.T) {
}

job := &Job{
ID: helper.StringToPtr("TestFS_Logs"),
Region: helper.StringToPtr("global"),
ID: stringToPtr("TestFS_Logs"),
Region: stringToPtr("global"),
Datacenters: []string{"dc1"},
Type: helper.StringToPtr("batch"),
Type: stringToPtr("batch"),
TaskGroups: []*TaskGroup{
{
Name: helper.StringToPtr("TestFS_LogsGroup"),
Name: stringToPtr("TestFS_LogsGroup"),
Tasks: []*Task{
{
Name: "logger",
Expand Down
Loading