|
|
@ -67,8 +67,12 @@ var (
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func newTritonDiscovery(c SDConfig) (*Discovery, error) {
|
|
|
|
|
|
|
|
return New(nil, &c)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestTritonSDNew(t *testing.T) {
|
|
|
|
func TestTritonSDNew(t *testing.T) {
|
|
|
|
td, err := New(nil, &conf)
|
|
|
|
td, err := newTritonDiscovery(conf)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Assert(t, td != nil, "")
|
|
|
|
testutil.Assert(t, td != nil, "")
|
|
|
|
testutil.Assert(t, td.client != nil, "")
|
|
|
|
testutil.Assert(t, td.client != nil, "")
|
|
|
@ -81,13 +85,13 @@ func TestTritonSDNew(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestTritonSDNewBadConfig(t *testing.T) {
|
|
|
|
func TestTritonSDNewBadConfig(t *testing.T) {
|
|
|
|
td, err := New(nil, &badconf)
|
|
|
|
td, err := newTritonDiscovery(badconf)
|
|
|
|
testutil.NotOk(t, err, "")
|
|
|
|
testutil.NotOk(t, err, "")
|
|
|
|
testutil.Assert(t, td == nil, "")
|
|
|
|
testutil.Assert(t, td == nil, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestTritonSDNewGroupsConfig(t *testing.T) {
|
|
|
|
func TestTritonSDNewGroupsConfig(t *testing.T) {
|
|
|
|
td, err := New(nil, &groupsconf)
|
|
|
|
td, err := newTritonDiscovery(groupsconf)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Assert(t, td != nil, "")
|
|
|
|
testutil.Assert(t, td != nil, "")
|
|
|
|
testutil.Assert(t, td.client != nil, "")
|
|
|
|
testutil.Assert(t, td.client != nil, "")
|
|
|
@ -102,14 +106,11 @@ func TestTritonSDNewGroupsConfig(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestTritonSDRun(t *testing.T) {
|
|
|
|
func TestTritonSDRun(t *testing.T) {
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
td, err = New(nil, &conf)
|
|
|
|
td, _ = newTritonDiscovery(conf)
|
|
|
|
ch = make(chan []*targetgroup.Group)
|
|
|
|
ch = make(chan []*targetgroup.Group)
|
|
|
|
ctx, cancel = context.WithCancel(context.Background())
|
|
|
|
ctx, cancel = context.WithCancel(context.Background())
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
|
|
|
|
testutil.Assert(t, td != nil, "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wait := make(chan struct{})
|
|
|
|
wait := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
go func() {
|
|
|
|
td.Run(ctx, ch)
|
|
|
|
td.Run(ctx, ch)
|
|
|
@ -160,47 +161,52 @@ func TestTritonSDRefreshMultipleTargets(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestTritonSDRefreshNoServer(t *testing.T) {
|
|
|
|
func TestTritonSDRefreshNoServer(t *testing.T) {
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
td, err = New(nil, &conf)
|
|
|
|
td, _ = newTritonDiscovery(conf)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
|
|
|
|
testutil.Assert(t, td != nil, "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tg, rerr := td.refresh()
|
|
|
|
_, err := td.refresh(context.Background())
|
|
|
|
testutil.NotOk(t, rerr, "")
|
|
|
|
testutil.NotOk(t, err, "")
|
|
|
|
testutil.Equals(t, strings.Contains(rerr.Error(), "an error occurred when requesting targets from the discovery endpoint."), true)
|
|
|
|
testutil.Equals(t, strings.Contains(err.Error(), "an error occurred when requesting targets from the discovery endpoint"), true)
|
|
|
|
testutil.Assert(t, tg != nil, "")
|
|
|
|
}
|
|
|
|
testutil.Assert(t, tg.Targets == nil, "")
|
|
|
|
|
|
|
|
|
|
|
|
func TestTritonSDRefreshCancelled(t *testing.T) {
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
td, _ = newTritonDiscovery(conf)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
_, err := td.refresh(ctx)
|
|
|
|
|
|
|
|
testutil.NotOk(t, err, "")
|
|
|
|
|
|
|
|
testutil.Equals(t, strings.Contains(err.Error(), context.Canceled.Error()), true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func testTritonSDRefresh(t *testing.T, dstr string) []model.LabelSet {
|
|
|
|
func testTritonSDRefresh(t *testing.T, dstr string) []model.LabelSet {
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
td, err = New(nil, &conf)
|
|
|
|
td, _ = newTritonDiscovery(conf)
|
|
|
|
s = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintln(w, dstr)
|
|
|
|
fmt.Fprintln(w, dstr)
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
defer s.Close()
|
|
|
|
defer s.Close()
|
|
|
|
|
|
|
|
|
|
|
|
u, uperr := url.Parse(s.URL)
|
|
|
|
u, err := url.Parse(s.URL)
|
|
|
|
testutil.Ok(t, uperr)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Assert(t, u != nil, "")
|
|
|
|
testutil.Assert(t, u != nil, "")
|
|
|
|
|
|
|
|
|
|
|
|
host, strport, sherr := net.SplitHostPort(u.Host)
|
|
|
|
host, strport, err := net.SplitHostPort(u.Host)
|
|
|
|
testutil.Ok(t, sherr)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Assert(t, host != "", "")
|
|
|
|
testutil.Assert(t, host != "", "")
|
|
|
|
testutil.Assert(t, strport != "", "")
|
|
|
|
testutil.Assert(t, strport != "", "")
|
|
|
|
|
|
|
|
|
|
|
|
port, atoierr := strconv.Atoi(strport)
|
|
|
|
port, err := strconv.Atoi(strport)
|
|
|
|
testutil.Ok(t, atoierr)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Assert(t, port != 0, "")
|
|
|
|
testutil.Assert(t, port != 0, "")
|
|
|
|
|
|
|
|
|
|
|
|
td.sdConfig.Port = port
|
|
|
|
td.sdConfig.Port = port
|
|
|
|
|
|
|
|
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
tg, err := td.refresh(context.Background())
|
|
|
|
testutil.Assert(t, td != nil, "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tg, err := td.refresh()
|
|
|
|
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Ok(t, err)
|
|
|
|
testutil.Assert(t, tg != nil, "")
|
|
|
|
testutil.Assert(t, tg != nil, "")
|
|
|
|
|
|
|
|
|
|
|
|