Skip to content

Commit 3784d13

Browse files
Fix index template conflict between integration tests (#11507) (#11526)
(cherry picked from commit cfa14fa) Co-authored-by: Mikołaj Świątek <[email protected]>
1 parent 0676425 commit 3784d13

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

testing/integration/ess/beat_receivers_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,9 +1531,8 @@ func setStrictMapping(client *elasticsearch.Client, index string) error {
15311531
defer cancel()
15321532

15331533
// Build request
1534-
req, err := http.NewRequestWithContext(ctx, http.MethodPut,
1535-
esEndpoint+"/_index_template/no-dynamic-template",
1536-
bytes.NewReader(jsonData))
1534+
url := fmt.Sprintf("%s/_index_template/%s", esEndpoint, index)
1535+
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, bytes.NewReader(jsonData))
15371536
if err != nil {
15381537
return fmt.Errorf("could not create http request to ES server: %v", err)
15391538
}
@@ -1545,8 +1544,15 @@ func setStrictMapping(client *elasticsearch.Client, index string) error {
15451544
if err != nil {
15461545
return fmt.Errorf("error performing request: %v", err)
15471546
}
1547+
defer func() {
1548+
_ = resp.Body.Close()
1549+
}()
15481550
if resp.StatusCode != http.StatusOK {
1549-
return fmt.Errorf("incorrect response code: %v", err)
1551+
responseBody, readErr := io.ReadAll(resp.Body)
1552+
if readErr != nil {
1553+
return fmt.Errorf("unexpected status code: %d, error reading response body: %w", resp.StatusCode, readErr)
1554+
}
1555+
return fmt.Errorf("unexpected status code: %d, response body: %s", resp.StatusCode, responseBody)
15501556
}
15511557
return nil
15521558
}

0 commit comments

Comments
 (0)