From 4711566d660ebe94d3bd3f46d1fd8390ba347ce2 Mon Sep 17 00:00:00 2001 From: HussainLatiff Date: Fri, 5 Jul 2024 09:56:06 +0530 Subject: [PATCH] Add README along with corrected the userid as a configurable variable --- ballerina/tests/READMEmd | 68 +++++++++++++++++++++++++++++++++++++++ ballerina/tests/tests.bal | 2 +- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 ballerina/tests/READMEmd diff --git a/ballerina/tests/READMEmd b/ballerina/tests/READMEmd new file mode 100644 index 0000000..1bc542e --- /dev/null +++ b/ballerina/tests/READMEmd @@ -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 = "" +userId = "" +serviceUrl = "" +``` + +#### Using Environment Variables + +Alternatively, you can set your authentication credentials as environment variables: + +```bash +export IS_LIVE_SERVER=true +export TOKEN="" +export DISCORD_USER_ID="" +export DISCORD_URL="" +``` + +Then, run the following command to run the tests: + +```bash + ./gradlew clean test -Pgroups="live_tests" +``` \ No newline at end of file diff --git a/ballerina/tests/tests.bal b/ballerina/tests/tests.bal index f2f0baa..1368b2e 100644 --- a/ballerina/tests/tests.bal +++ b/ballerina/tests/tests.bal @@ -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";