Skip to content

Commit

Permalink
Create TNB jbang script
Browse files Browse the repository at this point in the history
  • Loading branch information
mmuzikar authored and avano committed May 24, 2023
1 parent 003c7a4 commit 8925a67
Show file tree
Hide file tree
Showing 8 changed files with 1,026 additions and 100 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ TNB is a collection of JUnit 5 extensions designed for testing with external ser

For testing Camel based applications see [fuse-products](./fuse-products/README.md) README file.

For using System-X services from your terminal see [jbang integration](./jbang/README.md) README file.

---

There are two categories of System-X services: `Remote` and `Self-hosted`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class TestConfiguration extends Configuration {
public static final String PRODUCT = "test.product";
public static final String CREDENTIALS_FILE = "test.credentials.file";
public static final String CREDENTIALS = "test.credentials";
public static final String USE_VAULT = "test.credentials.use.vault";
public static final String VAULT_TOKEN = "test.credentials.vault.token";
private static final String VAULT_SECRET_ID = "test.credentials.vault.secret.id";
private static final String VAULT_ROLE_ID = "test.credentials.vault.role.id";
Expand Down Expand Up @@ -52,10 +51,6 @@ public static ProductType product() {
() -> new IllegalArgumentException(String.format("Unable to find enum for system property %s = %s", PRODUCT, getProperty(PRODUCT))));
}

public static boolean useVault() {
return getBoolean(USE_VAULT, false);
}

public static String vaultToken() {
return getProperty(VAULT_TOKEN);
}
Expand All @@ -77,11 +72,7 @@ public static String vaultAddress() {
}

public static String credentialsFile() {
final String credentials = getProperty(CREDENTIALS_FILE);
if (credentials == null) {
throw new IllegalArgumentException("No credentials file specified!");
}
return credentials;
return getProperty(CREDENTIALS_FILE);
}

public static String credentials() {
Expand Down
38 changes: 38 additions & 0 deletions jbang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# TNB CLI

If you want to use System-X services from your terminal without writing a test case you can use the `tnb` script.

## Installation
You'll need `jbang` installed and TNB build locally. Use command
`jbang app install jbang/tnb.java` to register the `tnb` command globally.

## Usage
The `tnb` CLI uses groovy shell, so any groovy language features should be valid.

You can see it in action in this demo:

[![demo](demo.gif)](https://asciinema.org/a/585241)

### Deploying System-X services
To deploy a System-X service you can use the `deploy <System-X Classname>` command.
By default the services are deployed locally, you can use the `--openshift` flag to deploy on OCP cluster you are currently logged in.

Or use commands `setOpenshift` and `setLocal` to use OCP or local installation always.

### Using deployed services
After deploying the service you'll be prompted with the service name to use in shell.
You can then use this name to use it as a normal System-X service. `<name>.validation().[TAB]` will help you.

Services are undeployed by default after you close the `tnb` session, or use the `undeploy` command.

### Configuration
The CLI uses `~/.tnb` directory for its configuration. `~/.tnb/init.groovy` file is executed on startup. You can use this to setup any properties, for example:

```groovy
System.setProperty('test.credentials.file', '~/credentials.yaml')
System.setProperty('openshift.kubeconfig', '~/kubeconfig.yaml')
```

#### Credentials
In a case where a service needs credentials that can't be found then you'll be asked to provide the credentials.
These credentials are then stored in `~/.tnb/credentials/<id>.properties` and will be used for later use.
Binary file added jbang/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8925a67

Please sign in to comment.