Skip to content

Commit

Permalink
one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
mieciu committed Oct 4, 2024
1 parent 3a60dee commit 37a1a74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ci/it/testcases/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,23 @@ func (tc *IntegrationTestcaseBase) getQuesmaEndpoint() string {
return "http://localhost:" + p.Port()
}

func (tc *IntegrationTestcaseBase) getElasticsearchEndpoint() string {
ctx := context.Background()
q := *tc.Containers.Elasticsearch
p, _ := q.MappedPort(ctx, "9200/tcp")
return "http://localhost:" + p.Port()
}

func (tc *IntegrationTestcaseBase) RequestToQuesma(ctx context.Context, method, uri string, body []byte) (*http.Response, error) {
endpoint := tc.getQuesmaEndpoint()
return tc.doRequest(ctx, method, endpoint+uri, body, nil)
}

func (tc *IntegrationTestcaseBase) RequestToElasticsearch(ctx context.Context, method, uri string, body []byte) (*http.Response, error) {
endpoint := tc.getElasticsearchEndpoint()
return tc.doRequest(ctx, method, endpoint+uri, body, nil)
}

func (tc *IntegrationTestcaseBase) doRequest(ctx context.Context, method, endpoint string, body []byte, headers http.Header) (*http.Response, error) {
client := &http.Client{}
req, err := http.NewRequestWithContext(ctx, method, endpoint, bytes.NewBuffer(body))
Expand Down
18 changes: 16 additions & 2 deletions ci/it/testcases/test_transparent_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (a *TransparentProxyIntegrationTestcase) RunTests(ctx context.Context, t *t
}
defer resp.Body.Close()
assert.Equal(t, 200, resp.StatusCode)

/* --------------------------- */
resp, err = a.RequestToQuesma(ctx, "GET", "/_cat/health", nil)
if err != nil {
t.Fatalf("Failed to make GET request: %s", err)
Expand All @@ -45,9 +45,23 @@ func (a *TransparentProxyIntegrationTestcase) RunTests(ctx context.Context, t *t
if err != nil {
t.Fatalf("Failed to read response body: %s", err)
}

assert.Equal(t, 200, resp.StatusCode)
assert.Equal(t, "Elasticsearch", resp.Header.Get("X-elastic-product"))
assert.Contains(t, string(bodyBytes), "green")
/* --------------------------- */
_, err = a.RequestToQuesma(ctx, "PUT", "/index_1", nil)
_, err = a.RequestToQuesma(ctx, "PUT", "/index_2", nil)

resp, err = a.RequestToElasticsearch(ctx, "GET", "/_cat/indices", nil)
if err != nil {
t.Fatalf("Failed to make GET request: %s", err)
}
defer resp.Body.Close()
bodyBytes, err = io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Failed to read response body: %s", err)
}
assert.Contains(t, string(bodyBytes), "index_1")
assert.Contains(t, string(bodyBytes), "index_2")
return nil
}

0 comments on commit 37a1a74

Please sign in to comment.