mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-25 20:00:06 +01:00
38 lines
895 B
Go
38 lines
895 B
Go
|
package notifier
|
||
|
|
||
|
import (
|
||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestInit(t *testing.T) {
|
||
|
oldAddrs := *addrs
|
||
|
defer func() { *addrs = oldAddrs }()
|
||
|
|
||
|
*addrs = flagutil.ArrayString{"127.0.0.1", "127.0.0.2"}
|
||
|
|
||
|
fn, err := Init(nil, nil, "")
|
||
|
if err != nil {
|
||
|
t.Fatalf("%s", err)
|
||
|
}
|
||
|
|
||
|
nfs := fn()
|
||
|
if len(nfs) != 2 {
|
||
|
t.Fatalf("expected to get 2 notifiers; got %d", len(nfs))
|
||
|
}
|
||
|
|
||
|
targets := GetTargets()
|
||
|
if targets == nil || targets[TargetStatic] == nil {
|
||
|
t.Fatalf("expected to get static targets in response")
|
||
|
}
|
||
|
|
||
|
nf1 := targets[TargetStatic][0]
|
||
|
if nf1.Addr() != "127.0.0.1/api/v2/alerts" {
|
||
|
t.Fatalf("expected to get \"127.0.0.1/api/v2/alerts\"; got %q instead", nf1.Addr())
|
||
|
}
|
||
|
nf2 := targets[TargetStatic][1]
|
||
|
if nf2.Addr() != "127.0.0.2/api/v2/alerts" {
|
||
|
t.Fatalf("expected to get \"127.0.0.2/api/v2/alerts\"; got %q instead", nf2.Addr())
|
||
|
}
|
||
|
}
|