Skip to content

Commit

Permalink
Introduce bal tool distribution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gayaldassanayake committed Jan 5, 2024
1 parent 976ddde commit b125563
Show file tree
Hide file tree
Showing 30 changed files with 1,048 additions and 0 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.ballerina.projectapi;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import static org.ballerina.projectapi.TestUtils.executePackCommand;
import static org.ballerina.projectapi.TestUtils.executePushCommand;
import static org.ballerina.projectapi.TestUtils.executeSearchCommand;
import static org.ballerina.projectapi.TestUtils.executeToolCommand;

/**
* Utility class for central tests.
Expand Down Expand Up @@ -261,6 +262,22 @@ static boolean isPkgAvailableInCentral(String pkg, Path tempWorkspaceDirectory,
return !buildOutput.contains("no modules found");
}

/**
* Check if a tool is already available on central.
*
* @param toolId tool id
* @param tempWorkspaceDirectory Path to workspace
* @param envVariables Environmental variables
* @return whether the package is available on central
* @throws IOException
* @throws InterruptedException
*/
static boolean isToolAvailableInCentral(String toolId, Path tempWorkspaceDirectory,
Map<String, String> envVariables) throws IOException, InterruptedException {
String buildOutput = searchToolDetails(toolId, tempWorkspaceDirectory, envVariables);
return !buildOutput.contains("no tools found");
}

/**
* Returns true if the provided version is available on central.
*
Expand Down Expand Up @@ -302,6 +319,30 @@ private static String searchPackageDetails(String pkg, Path tempWorkspaceDirecto
return getString(search.getInputStream());
}

/**
* Search for the given package on Central.
*
* @param toolId tool id
* @param tempWorkspaceDirectory Path to workspace
* @param envVariables Environmental variables
* @return
* @throws IOException
* @throws InterruptedException
*/
private static String searchToolDetails(String toolId, Path tempWorkspaceDirectory,
Map<String, String> envVariables)
throws IOException, InterruptedException {
Process search = executeToolCommand(DISTRIBUTION_FILE_NAME,
tempWorkspaceDirectory,
new ArrayList<>(Arrays.asList("search", toolId)),
envVariables);
String buildErrors = getString(search.getErrorStream());
if (!buildErrors.isEmpty()) {
Assert.fail(OUTPUT_CONTAIN_ERRORS + buildErrors);
}
return getString(search.getInputStream());
}

/**
* Build bala for a package.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ public static Process executeSearchCommand(String distributionName, Path sourceD
return executeCommand("search", distributionName, sourceDirectory, args, envProperties);
}

public static Process executeToolCommand(String distributionName, Path sourceDirectory,
List<String> args, Map<String, String> envProperties) throws IOException, InterruptedException {
return executeCommand("tool", distributionName, sourceDirectory, args, envProperties);
}

public static Process executeHelpCommand(String distributionName, Path sourceDirectory,
List<String> args, Map<String, String> envProperties) throws IOException, InterruptedException {
return executeCommand("help", distributionName, sourceDirectory, args, envProperties);
}

/**
* Clean and setup the distribution.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
NAME
The build system and package manager of Ballerina

SYNOPSIS
bal <command> [args]
bal [OPTIONS]


OPTIONS
-v, --version
Print version information.

-h, --help
Print the usage details of a command.


COMMANDS
The available subcommands are:

Core Commands:
build Compile the current package
run Compile and run the current package
test Run package tests
doc Generate current package's documentation
pack Create distribution format of the current package

Package Commands:
new Create a new Ballerina package
add Add a new Ballerina module to the current package
pull Pull a package from Ballerina Central
push Publish a package to Ballerina Central
search Search Ballerina Central for packages
semver Show SemVer compatibility and local package changes against
published packages in Ballerina Central
graph Print the dependency graph in the console
deprecate Deprecate a package in Ballerina Central

Other Commands:
clean Clean the artifacts generated during the build
format Format Ballerina source files
grpc Generate the Ballerina sources for a given Protocol
Buffer definition
graphql Generate the Ballerina client sources for a GraphQL config file,
generate the GraphQL schema for a Ballerina GraphQL service, and
generate the Ballerina GraphQL service for a GraphQL schema
openapi Generate the Ballerina sources for a given OpenAPI
definition and vice versa
asyncapi Generate the Ballerina sources for a given AsyncAPI definition
persist Manage data persistence
bindgen Generate the Ballerina bindings for Java APIs
shell Run Ballerina interactive REPL [Experimental]
tool Manage Ballerina CLI tools
version Print the Ballerina version
profile Start Ballerina Profiler [Experimental]

Tool Commands:
disttest The tool implementation for ballerina distribution tool tests

Update Commands:
dist Manage Ballerina distributions
update Update the Ballerina tool

Use 'bal help <command>' for more information on a specific command.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Sample tool used for testing the bal tools in ballerina distribution tests.
bal disttest <arg1>

--args--
<arg1>
The argument to be printed.

version: 1.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist test command 1.1.0 is executing with args arg1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
|TOOL ID |VERSION |
|----------------------|----------------|
|disttest | 1.1.0 |
|disttest |* 1.0.0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no tools found locally.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tool 'disttest:1.0.0' is already available locally.
tool 'disttest:1.0.0' is already active.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tool 'disttest:1.1.0' is already available locally.
tool 'disttest:1.1.0' is already active.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ballerina: tool 'disttest:1.0.4' is not compatible with the current Ballerina distribution
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unexpected error occurred while pulling tool:error: tool not found for: disttest:1.0.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tool 'disttest:1.0.0' pulled successfully.
tool 'disttest:1.0.0' successfully set as the active version.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tool 'disttest:1.1.0' pulled successfully.
tool 'disttest:1.1.0' successfully set as the active version.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ballerina: cannot remove active tool 'disttest:1.1.0'.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool 'disttest' successfully removed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ballerina: tool 'disttest2' not found.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ballerina: tool 'disttest:1.0.3' not found.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool 'disttest:1.0.0' successfully removed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ballerina: tool 'disttest:1.0.4' is not compatible with the current Ballerina distribution
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Ballerina Central
=================

|ID |PACKAGE |DESCRIPTION |DATE |VERSION |
|------------|-------------|-------------|----------------|-------------|
|disttest |bctestorg... |Sample to... |2023-09-12-Tue |1.1.0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ballerina: tool 'disttest2' is not installed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bctestorg/disttest:1.1.0 pulled from central successfully
tool 'disttest:1.1.0' pulled successfully.
tool 'disttest:1.1.0' successfully set as the active version.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool 'disttest' is already up-to-date.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool 'disttest:1.0.0' is the current active version.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool 'disttest:1.1.0' successfully set as the active version.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool 'disttest:1.0.3' is not found. Run 'bal tool pull disttest:1.0.3' to fetch and set as the active version.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tool 'disttest:1.0.0' successfully set as the active version.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ballerina: tool 'disttest:1.0.4' is not compatible with the current Ballerina distribution

0 comments on commit b125563

Please sign in to comment.