Skip to content

Commit a729673

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

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
@@ -1488,9 +1488,8 @@ func setStrictMapping(client *elasticsearch.Client, index string) error {
14881488
defer cancel()
14891489

14901490
// Build request
1491-
req, err := http.NewRequestWithContext(ctx, http.MethodPut,
1492-
esEndpoint+"/_index_template/no-dynamic-template",
1493-
bytes.NewReader(jsonData))
1491+
url := fmt.Sprintf("%s/_index_template/%s", esEndpoint, index)
1492+
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, bytes.NewReader(jsonData))
14941493
if err != nil {
14951494
return fmt.Errorf("could not create http request to ES server: %v", err)
14961495
}
@@ -1502,8 +1501,15 @@ func setStrictMapping(client *elasticsearch.Client, index string) error {
15021501
if err != nil {
15031502
return fmt.Errorf("error performing request: %v", err)
15041503
}
1504+
defer func() {
1505+
_ = resp.Body.Close()
1506+
}()
15051507
if resp.StatusCode != http.StatusOK {
1506-
return fmt.Errorf("incorrect response code: %v", err)
1508+
responseBody, readErr := io.ReadAll(resp.Body)
1509+
if readErr != nil {
1510+
return fmt.Errorf("unexpected status code: %d, error reading response body: %w", resp.StatusCode, readErr)
1511+
}
1512+
return fmt.Errorf("unexpected status code: %d, response body: %s", resp.StatusCode, responseBody)
15071513
}
15081514
return nil
15091515
}

0 commit comments

Comments
 (0)