Skip to content

Commit 1bcfda5

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

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

11341134
// Build request
1135-
req, err := http.NewRequestWithContext(ctx, http.MethodPut,
1136-
esEndpoint+"/_index_template/no-dynamic-template",
1137-
bytes.NewReader(jsonData))
1135+
url := fmt.Sprintf("%s/_index_template/%s", esEndpoint, index)
1136+
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, bytes.NewReader(jsonData))
11381137
if err != nil {
11391138
return fmt.Errorf("could not create http request to ES server: %v", err)
11401139
}
@@ -1146,8 +1145,15 @@ func setStrictMapping(client *elasticsearch.Client, index string) error {
11461145
if err != nil {
11471146
return fmt.Errorf("error performing request: %v", err)
11481147
}
1148+
defer func() {
1149+
_ = resp.Body.Close()
1150+
}()
11491151
if resp.StatusCode != http.StatusOK {
1150-
return fmt.Errorf("incorrect response code: %v", err)
1152+
responseBody, readErr := io.ReadAll(resp.Body)
1153+
if readErr != nil {
1154+
return fmt.Errorf("unexpected status code: %d, error reading response body: %w", resp.StatusCode, readErr)
1155+
}
1156+
return fmt.Errorf("unexpected status code: %d, response body: %s", resp.StatusCode, responseBody)
11511157
}
11521158
return nil
11531159
}

0 commit comments

Comments
 (0)