Skip to content

Commit

Permalink
query: e2e: Test both routePrefix and externalPrefix used simultaneously
Browse files Browse the repository at this point in the history
Signed-off-by: Prem Kumar <prmsrswt@gmail.com>
  • Loading branch information
onprem committed Jun 24, 2020
1 parent fb86080 commit f5bff42
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions test/e2e/e2ethanos/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func singleJoiningSlash(a, b string) string {
}

// NewSingleHostReverseProxy is almost same as httputil.NewSingleHostReverseProxy
// but it performs a url path rewrite
// but it performs a url path rewrite.
func NewSingleHostReverseProxy(target *url.URL, externalPrefix string) *httputil.ReverseProxy {
targetQuery := target.RawQuery
director := func(req *http.Request) {
Expand All @@ -52,7 +52,7 @@ func NewSingleHostReverseProxy(target *url.URL, externalPrefix string) *httputil
}

if _, ok := req.Header["User-Agent"]; !ok {
// explicitly disable User-Agent so it's not set to default value
// Explicitly disable User-Agent so it's not set to default value.
req.Header.Set("User-Agent", "")
}
}
Expand Down
59 changes: 32 additions & 27 deletions test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,60 +185,65 @@ func TestQueryRoutePrefix(t *testing.T) {
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(q))

ctx, cancel := chromedp.NewContext(context.Background())
t.Cleanup(cancel)
checkNetworkRequests(t, "http://"+q.HTTPEndpoint()+"/test/graph")
}

var networkErrors []string
func TestQueryExternalPrefix(t *testing.T) {
t.Parallel()

// Listen for failed network requests and push them to an array.
chromedp.ListenTarget(ctx, func(ev interface{}) {
switch ev := ev.(type) {
case *network.EventLoadingFailed:
networkErrors = append(networkErrors, ev.ErrorText)
}
})
s, err := e2e.NewScenario("e2e_test_query_external_prefix")
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, s))

err = chromedp.Run(ctx,
network.Enable(),
chromedp.Navigate("http://"+q.HTTPEndpoint()+"/test/graph"),
chromedp.WaitVisible(`body`),
externalPrefix := "thanos"

q, err := e2ethanos.NewQuerier(
s.SharedDir(), "1",
nil,
nil,
nil,
"",
externalPrefix,
)
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(q))

err = func() error {
if len(networkErrors) > 0 {
return fmt.Errorf("some network requests failed: %s", strings.Join(networkErrors, "; "))
}
return nil
}()
querierURL := urlParse(t, "http://"+q.HTTPEndpoint())

testutil.Ok(t, err)
querierProxy := httptest.NewServer(e2ethanos.NewSingleHostReverseProxy(querierURL, externalPrefix))

checkNetworkRequests(t, querierProxy.URL+"/"+externalPrefix+"/graph")
}

func TestQueryExternalPrefix(t *testing.T) {
func TestQueryExternalPrefixAndRoutePrefix(t *testing.T) {
t.Parallel()

s, err := e2e.NewScenario("e2e_test_query_external_prefix")
s, err := e2e.NewScenario("e2e_test_query_external_prefix_and_route_prefix")
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, s))

externalPrefix := "thanos"
routePrefix := "test"

q, err := e2ethanos.NewQuerier(
s.SharedDir(), "1",
nil,
nil,
nil,
"",
routePrefix,
externalPrefix,
)
testutil.Ok(t, err)
testutil.Ok(t, s.StartAndWaitReady(q))

querierURL := urlParse(t, "http://"+q.HTTPEndpoint())
querierURL := urlParse(t, "http://"+q.HTTPEndpoint()+"/"+routePrefix)

querierProxy := httptest.NewServer(e2ethanos.NewSingleHostReverseProxy(querierURL, externalPrefix))

checkNetworkRequests(t, querierProxy.URL+"/"+externalPrefix+"/graph")
}

func checkNetworkRequests(t *testing.T, addr string) {
ctx, cancel := chromedp.NewContext(context.Background())
t.Cleanup(cancel)

Expand All @@ -252,9 +257,9 @@ func TestQueryExternalPrefix(t *testing.T) {
}
})

err = chromedp.Run(ctx,
err := chromedp.Run(ctx,
network.Enable(),
chromedp.Navigate(querierProxy.URL+"/thanos/graph"),
chromedp.Navigate(addr),
chromedp.WaitVisible(`body`),
)
testutil.Ok(t, err)
Expand Down

0 comments on commit f5bff42

Please sign in to comment.