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
  • Loading branch information
onprem committed Jun 24, 2020
1 parent fb86080 commit a2f811e
Showing 1 changed file with 32 additions and 27 deletions.
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 a2f811e

Please sign in to comment.