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

Divest api/ package of deps elsewhere in the nomad repo. #5488

Merged
merged 4 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion api/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sort"
"testing"

"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/nomad/api/testutil"
"github.com/stretchr/testify/assert"
)

Expand Down
16 changes: 12 additions & 4 deletions api/allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"time"

"github.com/hashicorp/nomad/helper/uuid"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up PR, I'll nuke helper/uuid for hashicorp/go-uuid? Given that we already depend on go-uuid (as showed by vendor file), it doesn't make sense to have our own helper package.

"github.com/hashicorp/go-uuid"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -146,12 +146,20 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
}
job.Canonicalize()

uuidGen := func() string {
ret, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
return ret
}

alloc := &Allocation{
ID: uuid.Generate(),
ID: uuidGen(),
Namespace: DefaultNamespace,
EvalID: uuid.Generate(),
EvalID: uuidGen(),
Name: "foo-bar[1]",
NodeID: uuid.Generate(),
NodeID: uuidGen(),
TaskGroup: *job.TaskGroups[0].Name,
JobID: *job.ID,
Job: job,
Expand Down
16 changes: 12 additions & 4 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"testing"
"time"

"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/nomad/api/testutil"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -316,16 +316,24 @@ func TestQueryString(t *testing.T) {
func TestClient_NodeClient(t *testing.T) {
http := "testdomain:4646"
tlsNode := func(string, *QueryOptions) (*Node, *QueryMeta, error) {
uu, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
return &Node{
ID: uuid.Generate(),
ID: uu,
Status: "ready",
HTTPAddr: http,
TLSEnabled: true,
}, nil, nil
}
noTlsNode := func(string, *QueryOptions) (*Node, *QueryMeta, error) {
uu, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
return &Node{
ID: uuid.Generate(),
ID: uu,
Status: "ready",
HTTPAddr: http,
TLSEnabled: false,
Expand Down
2 changes: 1 addition & 1 deletion api/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

units "github.com/docker/go-units"
"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/nomad/api/testutil"
"github.com/kr/pretty"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
80 changes: 1 addition & 79 deletions api/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"testing"
"time"

"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/nomad/api/testutil"
"github.com/kr/pretty"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -46,43 +44,6 @@ func TestJobs_Register(t *testing.T) {
}
}

func TestJobs_Parse(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to call it out for future reviews, this and many removed tests were moved to apitests/

t.Parallel()
c, s := makeClient(t, nil, nil)
defer s.Stop()

jobs := c.Jobs()

checkJob := func(job *Job, expectedRegion string) {
if job == nil {
t.Fatal("job should not be nil")
}

region := job.Region

if region == nil {
if expectedRegion != "" {
t.Fatalf("expected job region to be '%s' but was unset", expectedRegion)
}
} else {
if expectedRegion != *region {
t.Fatalf("expected job region '%s', but got '%s'", expectedRegion, *region)
}
}
}
job, err := jobs.ParseHCL(mock.HCL(), true)
if err != nil {
t.Fatalf("err: %s", err)
}
checkJob(job, "global")

job, err = jobs.ParseHCL(mock.HCL(), false)
if err != nil {
t.Fatalf("err: %s", err)
}
checkJob(job, "")
}

func TestJobs_Validate(t *testing.T) {
t.Parallel()
c, s := makeClient(t, nil, nil)
Expand Down Expand Up @@ -1435,42 +1396,3 @@ func TestJobs_AddSpread(t *testing.T) {
t.Fatalf("expect: %#v, got: %#v", expect, job.Spreads)
}
}

func TestJobs_Summary_WithACL(t *testing.T) {
t.Parallel()
assert := assert.New(t)

c, s, root := makeACLClient(t, nil, nil)
defer s.Stop()
jobs := c.Jobs()

invalidToken := mock.ACLToken()

// Registering with an invalid token should fail
c.SetSecretID(invalidToken.SecretID)
job := testJob()
_, _, err := jobs.Register(job, nil)
assert.NotNil(err)

// Register with token should succeed
c.SetSecretID(root.SecretID)
resp2, wm, err := jobs.Register(job, nil)
assert.Nil(err)
assert.NotNil(resp2)
assert.NotEqual("", resp2.EvalID)
assertWriteMeta(t, wm)

// Query the job summary with an invalid token should fail
c.SetSecretID(invalidToken.SecretID)
result, _, err := jobs.Summary(*job.ID, nil)
assert.NotNil(err)

// Query the job summary with a valid token should succeed
c.SetSecretID(root.SecretID)
result, qm, err := jobs.Summary(*job.ID, nil)
assert.Nil(err)
assertQueryMeta(t, qm)

// Check that the result is what we expect
assert.Equal(*job.ID, result.JobID)
}
28 changes: 1 addition & 27 deletions api/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"testing"
"time"

"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/nomad/api/testutil"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -353,30 +351,6 @@ func TestNodes_Sort(t *testing.T) {
}
}

func TestNodes_GC(t *testing.T) {
t.Parallel()
require := require.New(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()
nodes := c.Nodes()

err := nodes.GC(uuid.Generate(), nil)
require.NotNil(err)
require.True(structs.IsErrUnknownNode(err))
}

func TestNodes_GcAlloc(t *testing.T) {
t.Parallel()
require := require.New(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()
nodes := c.Nodes()

err := nodes.GcAlloc(uuid.Generate(), nil)
require.NotNil(err)
require.True(structs.IsErrUnknownAllocation(err))
}

// Unittest monitorDrainMultiplex when an error occurs
func TestNodes_MonitorDrain_Multiplex_Bad(t *testing.T) {
t.Parallel()
Expand Down
70 changes: 0 additions & 70 deletions api/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package api
import (
"strings"
"testing"

"github.com/hashicorp/consul/testutil/retry"
"github.com/stretchr/testify/require"
)

func TestOperator_RaftGetConfiguration(t *testing.T) {
Expand Down Expand Up @@ -54,70 +51,3 @@ func TestOperator_RaftRemovePeerByID(t *testing.T) {
t.Fatalf("err: %v", err)
}
}

func TestAPI_OperatorSchedulerGetSetConfiguration(t *testing.T) {
t.Parallel()
require := require.New(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()

operator := c.Operator()
var config *SchedulerConfigurationResponse
retry.Run(t, func(r *retry.R) {
var err error
config, _, err = operator.SchedulerGetConfiguration(nil)
r.Check(err)
})
require.True(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)

// Change a config setting
newConf := &SchedulerConfiguration{PreemptionConfig: PreemptionConfig{SystemSchedulerEnabled: false}}
resp, wm, err := operator.SchedulerSetConfiguration(newConf, nil)
require.Nil(err)
require.NotZero(wm.LastIndex)
require.False(resp.Updated)

config, _, err = operator.SchedulerGetConfiguration(nil)
require.Nil(err)
require.False(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)
}

func TestAPI_OperatorSchedulerCASConfiguration(t *testing.T) {
t.Parallel()
require := require.New(t)
c, s := makeClient(t, nil, nil)
defer s.Stop()

operator := c.Operator()
var config *SchedulerConfigurationResponse
retry.Run(t, func(r *retry.R) {
var err error
config, _, err = operator.SchedulerGetConfiguration(nil)
r.Check(err)
})
require.True(config.SchedulerConfig.PreemptionConfig.SystemSchedulerEnabled)

// Pass an invalid ModifyIndex
{
newConf := &SchedulerConfiguration{
PreemptionConfig: PreemptionConfig{SystemSchedulerEnabled: false},
ModifyIndex: config.SchedulerConfig.ModifyIndex - 1,
}
resp, wm, err := operator.SchedulerCASConfiguration(newConf, nil)
require.Nil(err)
require.NotZero(wm.LastIndex)
require.False(resp.Updated)
}

// Pass a valid ModifyIndex
{
newConf := &SchedulerConfiguration{
PreemptionConfig: PreemptionConfig{SystemSchedulerEnabled: false},
ModifyIndex: config.SchedulerConfig.ModifyIndex,
}
resp, wm, err := operator.SchedulerCASConfiguration(newConf, nil)
require.Nil(err)
require.NotZero(wm.LastIndex)
require.True(resp.Updated)
}
}
2 changes: 1 addition & 1 deletion api/regions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/nomad/api/testutil"
)

func TestRegionsList(t *testing.T) {
Expand Down
Loading