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

remove accidental project leakage in api/ package #6685

Merged
merged 4 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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 GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ check: ## Lint the source code
@if (git status | grep -q .pb.go); then echo the following proto files are out of sync; git status |grep .pb.go; exit 1; fi

@echo "==> Check API package is isolated from rest"
@! go list -f '{{ join .Deps "\n" }}' ./api | grep github.com/hashicorp/nomad/ | grep -v -e /vendor/ -e /nomad/api/
@! go list --test -f '{{ join .Deps "\n" }}' ./api | grep github.com/hashicorp/nomad/ | grep -v -e /vendor/ -e /nomad/api/ -e nomad/api.test

.PHONY: checkscripts
checkscripts: ## Lint shell scripts
Expand Down
13 changes: 6 additions & 7 deletions api/allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"time"

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

Expand Down Expand Up @@ -150,11 +149,11 @@ func TestAllocations_RescheduleInfo(t *testing.T) {
job.Canonicalize()

alloc := &Allocation{
ID: uuid.Generate(),
ID: generateUUID(),
Namespace: DefaultNamespace,
EvalID: uuid.Generate(),
EvalID: generateUUID(),
Name: "foo-bar[1]",
NodeID: uuid.Generate(),
NodeID: generateUUID(),
TaskGroup: *job.TaskGroups[0].Name,
JobID: *job.ID,
Job: job,
Expand Down Expand Up @@ -266,14 +265,14 @@ func TestAllocations_ExecErrors(t *testing.T) {
}
job.Canonicalize()

allocID := uuid.Generate()
allocID := generateUUID()

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

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/nomad/api/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -318,24 +317,16 @@ 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: uu,
ID: generateUUID(),
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: uu,
ID: generateUUID(),
Status: "ready",
HTTPAddr: http,
TLSEnabled: false,
Expand Down
1 change: 0 additions & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/gorilla/websocket v1.4.1
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/go-rootcerts v1.0.0
github.com/hashicorp/go-uuid v1.0.1
github.com/kr/pretty v0.1.0
github.com/mitchellh/go-testing-interface v1.0.0
github.com/stretchr/testify v1.3.0
Expand Down
2 changes: 0 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVo
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-rootcerts v1.0.0 h1:Rqb66Oo1X/eSV1x66xbDccZjhJigjg0+e82kpwzSwCI=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
17 changes: 17 additions & 0 deletions api/util_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import (
crand "crypto/rand"
"fmt"
"testing"
)

Expand Down Expand Up @@ -90,3 +92,18 @@ func int64ToPtr(i int64) *int64 {
func float64ToPtr(f float64) *float64 {
return &f
}

// generateUUID generates a uuid useful for testing only
func generateUUID() string {
buf := make([]byte, 16)
if _, err := crand.Read(buf); err != nil {
panic(fmt.Errorf("failed to read random bytes: %v", err))
}

return fmt.Sprintf("%08x-%04x-%04x-%04x-%12x",
buf[0:4],
buf[4:6],
buf[6:8],
buf[8:10],
buf[10:16])
}