Skip to content

Commit

Permalink
Replace the disabled stack templates yaml test with java rest test (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarouli authored Sep 28, 2023
1 parent 0ef8232 commit d106fec
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.core;

import org.elasticsearch.client.Request;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase;

import static org.hamcrest.Matchers.is;

public class StackTemplatesRestIT extends ESRestTestCase {

private static final String BASIC_AUTH_VALUE = basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password"));

@Override
protected Settings restClientSettings() {
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", BASIC_AUTH_VALUE).build();
}

public void testTemplatesCanBeDisabled() throws Exception {
RestClient client = client();
// Ensure the logs template has been added
assertBusy(() -> {
try {
Request request = new Request("GET", "_index_template/logs");
assertOK(client.performRequest(request));
} catch (ResponseException e) {
fail(e.getMessage());
}
});
// Disable the stack templates
{
Request request = new Request("PUT", "_cluster/settings");
request.setJsonEntity("""
{
"persistent": {
"stack.templates.enabled": false
}
}
""");
assertOK(client.performRequest(request));
}
Request getRequest = new Request("GET", "_index_template/logs");
assertOK(client.performRequest(getRequest));

Request deleteRequest = new Request("DELETE", "_index_template/logs");
assertOK(client.performRequest(deleteRequest));
ResponseException exception = expectThrows(ResponseException.class, () -> client.performRequest(deleteRequest));
assertThat(exception.getResponse().getStatusLine().getStatusCode(), is(404));
}
}

This file was deleted.

0 comments on commit d106fec

Please sign in to comment.