Skip to content

Commit

Permalink
Test dist update
Browse files Browse the repository at this point in the history
  • Loading branch information
suganyasuven committed Feb 8, 2021
1 parent 4cde2ad commit dcfd63b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Test ballerina commands.
Expand Down Expand Up @@ -71,9 +73,13 @@ public void testDistCommands() throws IOException {
Assert.assertTrue(actualOutput.contains("'1.2.3' successfully set as the active distribution"));
TestUtils.testInstallation(path, "1.2.3", "2020R1", TOOL_VERSION, "1.2.3");
// test bal dist update
Path ballerinaHome = Paths.get(TestUtils.getUserHome()).resolve(".ballerina").resolve("ballerina-version");
actualOutput = TestUtils.executeCommand(path + " dist update");
String latestPatchVersion = actualOutput.split("Downloading ")[1].split(" ")[0];
String version = TestUtils.getContent(ballerinaHome).split("-")[1].trim();
Assert.assertTrue(actualOutput.contains("Fetching the latest patch distribution for 'jballerina-1.2.3' from the remote server..."));
Assert.assertTrue(actualOutput.contains("Successfully set the latest patch distribution"));
Assert.assertEquals(version, latestPatchVersion);
actualOutput = TestUtils.executeCommand(path + " dist update");
Assert.assertTrue(actualOutput.contains("is already the active distribution"));
// test bal dist use
Expand All @@ -93,6 +99,13 @@ public void testDistCommands() throws IOException {
Assert.assertTrue(actualOutput.contains("Distribution '" + SHORT_VERSION + "' successfully removed"));
actualOutput = TestUtils.executeCommand(path + " dist use " + SHORT_VERSION);
Assert.assertTrue(actualOutput.contains("Distribution '" + SHORT_VERSION + "' not found"));
actualOutput = TestUtils.executeCommand(path + " dist update");
latestPatchVersion = actualOutput.split("Downloading ")[1].split(" ")[0];
version = TestUtils.getContent(ballerinaHome).split("-")[1].trim();
Assert.assertTrue(actualOutput.contains("Fetching the latest patch distribution for 'ballerina-slp7' from the remote server..."));
Assert.assertTrue(actualOutput.contains("Successfully set the latest patch distribution"));
Assert.assertEquals(version, latestPatchVersion);

// test bal dist remove -a
actualOutput = TestUtils.executeCommand(path + " dist remove -a");
Assert.assertTrue(actualOutput.contains("All non-active distributions are successfully removed"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public static void testInstallation(String path, String jBallerinaVersion, Strin

/**
* Get version output for version command.
* @param jBallerinaVersion Installed jBallerina version
* @param jBallerinaVersion Installed jBallerina version
* @param specVersion Installed language specification
* @param toolVersion Installed tool version
* @param versionDisplayText display text for installed jBallerina version
Expand Down Expand Up @@ -323,4 +323,14 @@ public static boolean isSupportedRelease(String version) {
String[] versions = version.split("\\.");
return !(versions[0].equals("1") && versions[1].equals("0"));
}

/**
* Get the content of the file.
* @param filePath Path to the file
* @return content of the file
* @throws IOException
*/
public static String getContent(Path filePath) throws IOException {
return Files.readString(filePath);
}
}

0 comments on commit dcfd63b

Please sign in to comment.