Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the disabled stack templates yaml test with java rest test #99978

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.