Skip to content

Commit

Permalink
Add README along with corrected the userid as a configurable variable
Browse files Browse the repository at this point in the history
  • Loading branch information
HussainLatiff committed Jul 5, 2024
1 parent 0c56865 commit 4711566
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
68 changes: 68 additions & 0 deletions ballerina/tests/READMEmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Running Tests

There are two test environments for running the Discord connector tests. The default test environment is the mock server for Discord API. The other test environment is the actual Discord API.

You can run the tests in either of these environments and each has its own compatible set of tests.

Test Groups | Environment
-------------|---------------------------------------------------
mock_tests | Mock server for Discord API (Defualt Environment)
live_tests | Discord API

## Running Tests in the Mock Server

To execute the tests on the mock server, ensure that the `IS_LIVE_SERVER` environment variable is either set to `false` or unset before initiating the tests.

This environment variable can be configured within the `Config.toml` file located in the tests directory or specified as an environmental variable.

#### Using a Config.toml File

Create a `Config.toml` file in the tests directory and the following content:

```toml
isLiveServer = false
```

#### Using Environment Variables

Alternatively, you can set your authentication credentials as environment variables:

```bash
export IS_LIVE_SERVER=false
```

Then, run the following command to run the tests:

```bash
./gradlew clean test
```

## Running Tests Against Discord Live API

#### Using a Config.toml File

Create a `Config.toml` file in the tests directory and add your authentication credentials a

```toml
isTestOnLiveServer = true
token = "<your-discord-bearer-token>"
userId = "<your-discord-user-id>"
serviceUrl = "<your-discord-subdomain-service-url>"
```

#### Using Environment Variables

Alternatively, you can set your authentication credentials as environment variables:

```bash
export IS_LIVE_SERVER=true
export TOKEN="<your-discord-bearer-token>"
export DISCORD_USER_ID="<your-discord-user-id>"
export DISCORD_URL="<your-discord-subdomain-service-url>"
```

Then, run the following command to run the tests:

```bash
./gradlew clean test -Pgroups="live_tests"
```
2 changes: 1 addition & 1 deletion ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import ballerina/test;
configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true";
configurable string token = isLiveServer ? os:getEnv("TOKEN") : "z4HhmDy5ghijpIRL1YFzhCeVFabcdef";
configurable string serviceUrl = isLiveServer ? os:getEnv("DISCORD_URL") : "http://localhost:9090";
configurable string userId = isLiveServer ? os:getEnv("DISCORD_USER_ID") :"688069266636800112";

configurable string userId = "688069266636800112";
string voiceChannelId = "1160951610135019725";
string channelId = "893493941398294611";

Expand Down

0 comments on commit 4711566

Please sign in to comment.