mirror of https://github.com/hashicorp/consul
replace custom unique id with a UUID
parent
8f145559d8
commit
96fdbd00a6
|
@ -15,12 +15,20 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/mock"
|
"github.com/hashicorp/consul/agent/mock"
|
||||||
"github.com/hashicorp/consul/agent/unique"
|
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
"github.com/hashicorp/consul/testutil/retry"
|
"github.com/hashicorp/consul/testutil/retry"
|
||||||
"github.com/hashicorp/consul/types"
|
"github.com/hashicorp/consul/types"
|
||||||
|
uuid "github.com/hashicorp/go-uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func uniqueID() string {
|
||||||
|
id, err := uuid.GenerateUUID()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
func TestCheckMonitor_Script(t *testing.T) {
|
func TestCheckMonitor_Script(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
script, status string
|
script, status string
|
||||||
|
@ -39,7 +47,7 @@ func TestCheckMonitor_Script(t *testing.T) {
|
||||||
CheckID: types.CheckID("foo"),
|
CheckID: types.CheckID("foo"),
|
||||||
Script: tt.script,
|
Script: tt.script,
|
||||||
Interval: 25 * time.Millisecond,
|
Interval: 25 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
defer check.Stop()
|
defer check.Stop()
|
||||||
|
@ -74,7 +82,7 @@ func TestCheckMonitor_Args(t *testing.T) {
|
||||||
CheckID: types.CheckID("foo"),
|
CheckID: types.CheckID("foo"),
|
||||||
ScriptArgs: tt.args,
|
ScriptArgs: tt.args,
|
||||||
Interval: 25 * time.Millisecond,
|
Interval: 25 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
defer check.Stop()
|
defer check.Stop()
|
||||||
|
@ -99,7 +107,7 @@ func TestCheckMonitor_Timeout(t *testing.T) {
|
||||||
ScriptArgs: []string{"sh", "-c", "sleep 1 && exit 0"},
|
ScriptArgs: []string{"sh", "-c", "sleep 1 && exit 0"},
|
||||||
Interval: 50 * time.Millisecond,
|
Interval: 50 * time.Millisecond,
|
||||||
Timeout: 25 * time.Millisecond,
|
Timeout: 25 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
defer check.Stop()
|
defer check.Stop()
|
||||||
|
@ -123,7 +131,7 @@ func TestCheckMonitor_RandomStagger(t *testing.T) {
|
||||||
CheckID: types.CheckID("foo"),
|
CheckID: types.CheckID("foo"),
|
||||||
ScriptArgs: []string{"sh", "-c", "exit 0"},
|
ScriptArgs: []string{"sh", "-c", "exit 0"},
|
||||||
Interval: 25 * time.Millisecond,
|
Interval: 25 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
defer check.Stop()
|
defer check.Stop()
|
||||||
|
@ -148,7 +156,7 @@ func TestCheckMonitor_LimitOutput(t *testing.T) {
|
||||||
CheckID: types.CheckID("foo"),
|
CheckID: types.CheckID("foo"),
|
||||||
ScriptArgs: []string{"od", "-N", "81920", "/dev/urandom"},
|
ScriptArgs: []string{"od", "-N", "81920", "/dev/urandom"},
|
||||||
Interval: 25 * time.Millisecond,
|
Interval: 25 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
defer check.Stop()
|
defer check.Stop()
|
||||||
|
@ -168,7 +176,7 @@ func TestCheckTTL(t *testing.T) {
|
||||||
Notify: notif,
|
Notify: notif,
|
||||||
CheckID: types.CheckID("foo"),
|
CheckID: types.CheckID("foo"),
|
||||||
TTL: 200 * time.Millisecond,
|
TTL: 200 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
defer check.Stop()
|
defer check.Stop()
|
||||||
|
@ -292,7 +300,7 @@ func TestCheckHTTP(t *testing.T) {
|
||||||
Method: tt.method,
|
Method: tt.method,
|
||||||
Header: tt.header,
|
Header: tt.header,
|
||||||
Interval: 10 * time.Millisecond,
|
Interval: 10 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
defer check.Stop()
|
defer check.Stop()
|
||||||
|
@ -328,7 +336,7 @@ func TestCheckHTTPTimeout(t *testing.T) {
|
||||||
HTTP: server.URL,
|
HTTP: server.URL,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
Interval: 10 * time.Millisecond,
|
Interval: 10 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
|
|
||||||
check.Start()
|
check.Start()
|
||||||
|
@ -349,7 +357,7 @@ func TestCheckHTTP_disablesKeepAlives(t *testing.T) {
|
||||||
CheckID: types.CheckID("foo"),
|
CheckID: types.CheckID("foo"),
|
||||||
HTTP: "http://foo.bar/baz",
|
HTTP: "http://foo.bar/baz",
|
||||||
Interval: 10 * time.Second,
|
Interval: 10 * time.Second,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
|
|
||||||
check.Start()
|
check.Start()
|
||||||
|
@ -366,7 +374,7 @@ func TestCheckHTTP_TLSSkipVerify_defaultFalse(t *testing.T) {
|
||||||
CheckID: "foo",
|
CheckID: "foo",
|
||||||
HTTP: "https://foo.bar/baz",
|
HTTP: "https://foo.bar/baz",
|
||||||
Interval: 10 * time.Second,
|
Interval: 10 * time.Second,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
|
|
||||||
check.Start()
|
check.Start()
|
||||||
|
@ -398,7 +406,7 @@ func TestCheckHTTP_TLSSkipVerify_true_pass(t *testing.T) {
|
||||||
CheckID: types.CheckID("skipverify_true"),
|
CheckID: types.CheckID("skipverify_true"),
|
||||||
HTTP: server.URL,
|
HTTP: server.URL,
|
||||||
Interval: 25 * time.Millisecond,
|
Interval: 25 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
TLSSkipVerify: true,
|
TLSSkipVerify: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +438,7 @@ func TestCheckHTTP_TLSSkipVerify_true_fail(t *testing.T) {
|
||||||
CheckID: types.CheckID("skipverify_true"),
|
CheckID: types.CheckID("skipverify_true"),
|
||||||
HTTP: server.URL,
|
HTTP: server.URL,
|
||||||
Interval: 5 * time.Millisecond,
|
Interval: 5 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
TLSSkipVerify: true,
|
TLSSkipVerify: true,
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
|
@ -458,7 +466,7 @@ func TestCheckHTTP_TLSSkipVerify_false(t *testing.T) {
|
||||||
CheckID: types.CheckID("skipverify_false"),
|
CheckID: types.CheckID("skipverify_false"),
|
||||||
HTTP: server.URL,
|
HTTP: server.URL,
|
||||||
Interval: 100 * time.Millisecond,
|
Interval: 100 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
TLSSkipVerify: false,
|
TLSSkipVerify: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +513,7 @@ func expectTCPStatus(t *testing.T, tcp string, status string) {
|
||||||
CheckID: types.CheckID("foo"),
|
CheckID: types.CheckID("foo"),
|
||||||
TCP: tcp,
|
TCP: tcp,
|
||||||
Interval: 10 * time.Millisecond,
|
Interval: 10 * time.Millisecond,
|
||||||
Logger: log.New(ioutil.Discard, unique.ID(), log.LstdFlags),
|
Logger: log.New(ioutil.Discard, uniqueID(), log.LstdFlags),
|
||||||
}
|
}
|
||||||
check.Start()
|
check.Start()
|
||||||
defer check.Stop()
|
defer check.Stop()
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"github.com/hashicorp/consul/agent/config"
|
"github.com/hashicorp/consul/agent/config"
|
||||||
"github.com/hashicorp/consul/agent/consul"
|
"github.com/hashicorp/consul/agent/consul"
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
"github.com/hashicorp/consul/agent/unique"
|
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
"github.com/hashicorp/consul/lib/freeport"
|
"github.com/hashicorp/consul/lib/freeport"
|
||||||
"github.com/hashicorp/consul/logger"
|
"github.com/hashicorp/consul/logger"
|
||||||
|
@ -112,7 +111,7 @@ func (a *TestAgent) Start() *TestAgent {
|
||||||
}
|
}
|
||||||
hclDataDir = `data_dir = "` + d + `"`
|
hclDataDir = `data_dir = "` + d + `"`
|
||||||
}
|
}
|
||||||
id := unique.ID()
|
id := NodeID()
|
||||||
|
|
||||||
for i := 10; i >= 0; i-- {
|
for i := 10; i >= 0; i-- {
|
||||||
a.Config = TestConfig(
|
a.Config = TestConfig(
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
package unique
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rand.Seed(time.Now().UnixNano()) // seed random number generator
|
|
||||||
}
|
|
||||||
|
|
||||||
func ID() string {
|
|
||||||
id := strconv.FormatUint(rand.Uint64(), 36)
|
|
||||||
for len(id) < 16 {
|
|
||||||
id += " "
|
|
||||||
}
|
|
||||||
return id
|
|
||||||
}
|
|
Loading…
Reference in New Issue