VictoriaMetrics/lib/promscrape/discovery/http/api_test.go
Nikolay e03a3d3a36 adds http_sd (#1399)
* adds http_sd

* adds X-Prometheus-Refresh-Interval-Seconds header

* Update lib/promscrape/discovery/http/api.go

Co-authored-by: Aliaksandr Valialkin <valyala@gmail.com>
2021-06-22 13:42:09 +03:00

49 lines
1 KiB
Go

package http
import (
"reflect"
"testing"
)
func Test_parseAPIResponse(t *testing.T) {
type args struct {
data []byte
path string
}
tests := []struct {
name string
args args
want []httpGroupTarget
wantErr bool
}{
{
name: "parse ok",
args: args{
path: "/ok",
data: []byte(`[
{"targets": ["http://target-1:9100","http://target-2:9150"],
"labels": {"label-1":"value-1"} }
]`),
},
want: []httpGroupTarget{
{
Labels: map[string]string{"label-1": "value-1"},
Targets: []string{"http://target-1:9100", "http://target-2:9150"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseAPIResponse(tt.args.data, tt.args.path)
if (err != nil) != tt.wantErr {
t.Errorf("parseAPIResponse() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseAPIResponse() got = %v, want %v", got, tt.want)
}
})
}
}