use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.
the class OverrideNodeVersionCommandTests method testOverwritesIfTooOld.
public void testOverwritesIfTooOld() throws Exception {
final Version nodeVersion = NodeMetadataTests.tooOldVersion();
PersistedClusterStateService.overrideVersion(nodeVersion, nodePaths);
final MockTerminal mockTerminal = new MockTerminal();
mockTerminal.addTextInput(randomFrom("y", "Y"));
new OverrideNodeVersionCommand().processNodePaths(mockTerminal, nodePaths, 0, noOptions, environment);
assertThat(mockTerminal.getOutput(), allOf(containsString("too old"), containsString("data loss"), containsString("You should not use this tool"), containsString(Version.CURRENT.toString()), containsString(nodeVersion.toString()), containsString(OverrideNodeVersionCommand.SUCCESS_MESSAGE)));
expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
final NodeMetadata nodeMetadata = PersistedClusterStateService.nodeMetadata(nodePaths);
assertThat(nodeMetadata.nodeVersion(), equalTo(Version.CURRENT));
}
use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.
the class OverrideNodeVersionCommandTests method testFailsOnEmptyPath.
public void testFailsOnEmptyPath() {
final Path emptyPath = createTempDir();
final MockTerminal mockTerminal = new MockTerminal();
final OpenSearchException openSearchException = expectThrows(OpenSearchException.class, () -> new OverrideNodeVersionCommand().processNodePaths(mockTerminal, new Path[] { emptyPath }, 0, noOptions, environment));
assertThat(openSearchException.getMessage(), equalTo(OverrideNodeVersionCommand.NO_METADATA_MESSAGE));
expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
}
use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.
the class OverrideNodeVersionCommandTests method testWarnsIfTooNew.
public void testWarnsIfTooNew() throws Exception {
final Version nodeVersion = NodeMetadataTests.tooNewVersion();
PersistedClusterStateService.overrideVersion(nodeVersion, nodePaths);
final MockTerminal mockTerminal = new MockTerminal();
mockTerminal.addTextInput(randomFrom("yy", "Yy", "n", "yes", "true", "N", "no"));
final OpenSearchException openSearchException = expectThrows(OpenSearchException.class, () -> new OverrideNodeVersionCommand().processNodePaths(mockTerminal, nodePaths, 0, noOptions, environment));
assertThat(openSearchException.getMessage(), equalTo("aborted by user"));
assertThat(mockTerminal.getOutput(), allOf(containsString("data loss"), containsString("You should not use this tool"), containsString(Version.CURRENT.toString()), containsString(nodeVersion.toString())));
expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
final NodeMetadata nodeMetadata = PersistedClusterStateService.nodeMetadata(nodePaths);
assertThat(nodeMetadata.nodeVersion(), equalTo(nodeVersion));
}
use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.
the class OverrideNodeVersionCommandTests method testWarnsIfTooOld.
public void testWarnsIfTooOld() throws Exception {
final Version nodeVersion = NodeMetadataTests.tooOldVersion();
PersistedClusterStateService.overrideVersion(nodeVersion, nodePaths);
final MockTerminal mockTerminal = new MockTerminal();
mockTerminal.addTextInput("n\n");
final OpenSearchException openSearchException = expectThrows(OpenSearchException.class, () -> new OverrideNodeVersionCommand().processNodePaths(mockTerminal, nodePaths, 0, noOptions, environment));
assertThat(openSearchException.getMessage(), equalTo("aborted by user"));
assertThat(mockTerminal.getOutput(), allOf(containsString("too old"), containsString("data loss"), containsString("You should not use this tool"), containsString(Version.CURRENT.toString()), containsString(nodeVersion.toString())));
expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
final NodeMetadata nodeMetadata = PersistedClusterStateService.nodeMetadata(nodePaths);
assertThat(nodeMetadata.nodeVersion(), equalTo(nodeVersion));
}
use of org.opensearch.cli.MockTerminal in project OpenSearch by opensearch-project.
the class OverrideNodeVersionCommandTests method testFailsIfUnnecessary.
public void testFailsIfUnnecessary() throws IOException {
final Version nodeVersion = Version.fromId(between(Version.CURRENT.minimumIndexCompatibilityVersion().id, Version.CURRENT.id));
PersistedClusterStateService.overrideVersion(nodeVersion, nodePaths);
final MockTerminal mockTerminal = new MockTerminal();
final OpenSearchException openSearchException = expectThrows(OpenSearchException.class, () -> new OverrideNodeVersionCommand().processNodePaths(mockTerminal, nodePaths, 0, noOptions, environment));
assertThat(openSearchException.getMessage(), allOf(containsString("compatible with current version"), containsString(Version.CURRENT.toString()), containsString(nodeVersion.toString())));
expectThrows(IllegalStateException.class, () -> mockTerminal.readText(""));
}
Aggregations