valepakh commented on code in PR #7356: URL: https://github.com/apache/ignite-3/pull/7356#discussion_r2685715085
########## modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/unit/ItNodeUnitStructureCommandTest.java: ########## @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.unit; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertAll; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import org.apache.ignite.internal.cli.CliIntegrationTest; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/** Integration test for node unit structure command. */ +public class ItNodeUnitStructureCommandTest extends CliIntegrationTest { + private static String testFile; + + private static Path testDirectory; + + @BeforeAll + static void beforeAll() throws IOException { + testDirectory = Files.createDirectory(WORK_DIR.resolve("test-structure")); + testFile = Files.createFile(testDirectory.resolve("test.txt")).toString(); + Files.createFile(testDirectory.resolve("test2.txt")); + Files.createFile(testDirectory.resolve("test3.txt")); + } + + @Test + @DisplayName("Should display unit structure with tree view") + void structureTreeView() { + // Given deployed unit + String id = "test.structure.unit.1"; + execute("cluster", "unit", "deploy", id, "--version", "1.0.0", "--path", testDirectory.toString()); + + await().untilAsserted(() -> { + execute("cluster", "unit", "list", "--plain", id); + assertExitCodeIsZero(); + }); + + // When get structure + execute("node", "unit", "structure", id, "--version", "1.0.0"); + + // Then + assertAll( + this::assertExitCodeIsZero, + this::assertErrOutputIsEmpty, + () -> assertOutputContains(id), + () -> assertOutputContains("test.txt"), + () -> assertOutputContains("test2.txt"), + () -> assertOutputContains("test3.txt"), + () -> assertOutputContains(" B)") // File size display + ); + } + + @Test + @DisplayName("Should display unit structure with plain view") + void structurePlainView() { + // Given deployed unit + String id = "test.structure.unit.2"; + execute("cluster", "unit", "deploy", id, "--version", "1.0.0", "--path", testDirectory.toString()); + + await().untilAsserted(() -> { + execute("cluster", "unit", "list", "--plain", id); + assertExitCodeIsZero(); + }); + + // When get structure with plain option + execute("node", "unit", "structure", id, "--version", "1.0.0", "--plain"); + + // Then + assertAll( + this::assertExitCodeIsZero, + this::assertErrOutputIsEmpty, + () -> assertOutputContains("test.txt"), Review Comment: Can we test the exact output at least in the plain case? ########## modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/unit/ItNodeUnitStructureCommandTest.java: ########## @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.commands.unit; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertAll; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import org.apache.ignite.internal.cli.CliIntegrationTest; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +/** Integration test for node unit structure command. */ +public class ItNodeUnitStructureCommandTest extends CliIntegrationTest { + private static String testFile; + + private static Path testDirectory; + + @BeforeAll + static void beforeAll() throws IOException { + testDirectory = Files.createDirectory(WORK_DIR.resolve("test-structure")); + testFile = Files.createFile(testDirectory.resolve("test.txt")).toString(); + Files.createFile(testDirectory.resolve("test2.txt")); + Files.createFile(testDirectory.resolve("test3.txt")); + } + + @Test + @DisplayName("Should display unit structure with tree view") + void structureTreeView() { + // Given deployed unit + String id = "test.structure.unit.1"; + execute("cluster", "unit", "deploy", id, "--version", "1.0.0", "--path", testDirectory.toString()); + + await().untilAsserted(() -> { + execute("cluster", "unit", "list", "--plain", id); + assertExitCodeIsZero(); + }); + + // When get structure + execute("node", "unit", "structure", id, "--version", "1.0.0"); + + // Then + assertAll( + this::assertExitCodeIsZero, + this::assertErrOutputIsEmpty, + () -> assertOutputContains(id), + () -> assertOutputContains("test.txt"), + () -> assertOutputContains("test2.txt"), + () -> assertOutputContains("test3.txt"), + () -> assertOutputContains(" B)") // File size display + ); + } + + @Test + @DisplayName("Should display unit structure with plain view") + void structurePlainView() { + // Given deployed unit + String id = "test.structure.unit.2"; + execute("cluster", "unit", "deploy", id, "--version", "1.0.0", "--path", testDirectory.toString()); + + await().untilAsserted(() -> { + execute("cluster", "unit", "list", "--plain", id); + assertExitCodeIsZero(); + }); + + // When get structure with plain option + execute("node", "unit", "structure", id, "--version", "1.0.0", "--plain"); + + // Then + assertAll( + this::assertExitCodeIsZero, + this::assertErrOutputIsEmpty, + () -> assertOutputContains("test.txt"), + () -> assertOutputContains("test2.txt"), + () -> assertOutputContains("test3.txt") + ); + } + + @Test + @DisplayName("Should display error when version is missing") + void structureVersionIsMandatory() { + // When get structure without version + execute("node", "unit", "structure", "test.unit.id"); + + // Then + assertAll( + () -> assertExitCodeIs(2), + () -> assertErrOutputContains("Missing required option: '--version=<version>'"), + this::assertOutputIsEmpty + ); + } + + @Test + @DisplayName("Should display error when unit does not exist") + void structureUnitNotFound() { + // When get structure of non-existing unit + execute("node", "unit", "structure", "non.existing.unit", "--version", "1.0.0"); + + // Then + assertAll( + this::assertExitCodeIsError, + () -> assertErrOutputContains("not found") Review Comment: Again, can we verify the exact error output? ########## modules/cli/src/test/java/org/apache/ignite/internal/cli/decorators/UnitStructureDecoratorTest.java: ########## @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cli.decorators; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; + +import java.util.List; +import org.apache.ignite.rest.client.model.UnitEntry; +import org.apache.ignite.rest.client.model.UnitFile; +import org.apache.ignite.rest.client.model.UnitFolder; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class UnitStructureDecoratorTest { + + @Test + @DisplayName("Tree view should display folder with files") + void treeViewWithFiles() { + // Given + UnitFolder folder = createFolderWithFiles("test-unit", + createFile("file1.txt", 100), + createFile("file2.txt", 200)); + + UnitStructureDecorator decorator = new UnitStructureDecorator(false); + + // When + String output = decorator.decorate(folder).toTerminalString(); + + // Then + assertThat(output, containsString("test-unit")); Review Comment: Let's verify exact output here as well -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
