Skip to content

Commit cfa14fa

Browse files
authored
Fix index template conflict between integration tests (#11507)
1 parent 2b05ddf commit cfa14fa

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

15231523
// Build request
1524-
req, err := http.NewRequestWithContext(ctx, http.MethodPut,
1525-
esEndpoint+"/_index_template/no-dynamic-template",
1526-
bytes.NewReader(jsonData))
1524+
url := fmt.Sprintf("%s/_index_template/%s", esEndpoint, index)
1525+
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, bytes.NewReader(jsonData))
15271526
if err != nil {
15281527
return fmt.Errorf("could not create http request to ES server: %v", err)
15291528
}
@@ -1535,8 +1534,15 @@ func setStrictMapping(client *elasticsearch.Client, index string) error {
15351534
if err != nil {
15361535
return fmt.Errorf("error performing request: %v", err)
15371536
}
1537+
defer func() {
1538+
_ = resp.Body.Close()
1539+
}()
15381540
if resp.StatusCode != http.StatusOK {
1539-
return fmt.Errorf("incorrect response code: %v", err)
1541+
responseBody, readErr := io.ReadAll(resp.Body)
1542+
if readErr != nil {
1543+
return fmt.Errorf("unexpected status code: %d, error reading response body: %w", resp.StatusCode, readErr)
1544+
}
1545+
return fmt.Errorf("unexpected status code: %d, response body: %s", resp.StatusCode, responseBody)
15401546
}
15411547
return nil
15421548
}

0 commit comments

Comments
 (0)