Add rendering test of template based web endpoints (#5188)

Signed-off-by: Minh-Long  Do <minhlong.langos@gmail.com>
This commit is contained in:
Minh-Long Do 2019-02-08 10:17:47 +00:00 committed by Brian Brazil
parent fc10f6d814
commit b26b5c9e96
1 changed files with 85 additions and 2 deletions

View File

@ -25,6 +25,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/notifier"
"github.com/prometheus/prometheus/rules"
"github.com/prometheus/prometheus/scrape"
"github.com/prometheus/prometheus/storage/tsdb" "github.com/prometheus/prometheus/storage/tsdb"
"github.com/prometheus/prometheus/util/testutil" "github.com/prometheus/prometheus/util/testutil"
libtsdb "github.com/prometheus/tsdb" libtsdb "github.com/prometheus/tsdb"
@ -101,8 +105,8 @@ func TestReadyAndHealthy(t *testing.T) {
Context: nil, Context: nil,
Storage: &tsdb.ReadyStorage{}, Storage: &tsdb.ReadyStorage{},
QueryEngine: nil, QueryEngine: nil,
ScrapeManager: nil, ScrapeManager: &scrape.Manager{},
RuleManager: nil, RuleManager: &rules.Manager{},
Notifier: nil, Notifier: nil,
RoutePrefix: "/", RoutePrefix: "/",
EnableAdminAPI: true, EnableAdminAPI: true,
@ -118,6 +122,10 @@ func TestReadyAndHealthy(t *testing.T) {
opts.Flags = map[string]string{} opts.Flags = map[string]string{}
webHandler := New(nil, opts) webHandler := New(nil, opts)
webHandler.config = &config.Config{}
webHandler.notifier = &notifier.Manager{}
go func() { go func() {
err := webHandler.Run(context.Background()) err := webHandler.Run(context.Background())
if err != nil { if err != nil {
@ -159,6 +167,46 @@ func TestReadyAndHealthy(t *testing.T) {
testutil.Ok(t, err) testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode) testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/graph")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/alerts")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/flags")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/rules")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/service-discovery")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/targets")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/config")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/status")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusServiceUnavailable, resp.StatusCode)
// Set to ready. // Set to ready.
webHandler.Ready() webHandler.Ready()
@ -191,6 +239,41 @@ func TestReadyAndHealthy(t *testing.T) {
testutil.Ok(t, err) testutil.Ok(t, err)
testutil.Equals(t, http.StatusOK, resp.StatusCode) testutil.Equals(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/alerts")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/flags")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/rules")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/service-discovery")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/targets")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/config")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusOK, resp.StatusCode)
resp, err = http.Get("http://localhost:9090/status")
testutil.Ok(t, err)
testutil.Equals(t, http.StatusOK, resp.StatusCode)
} }
func TestRoutePrefix(t *testing.T) { func TestRoutePrefix(t *testing.T) {