Skip to content

Commit

Permalink
Merge pull request #9 from e19166/tests
Browse files Browse the repository at this point in the history
Add tests with mock server & test documentation
  • Loading branch information
NipunaRanasinghe authored Aug 14, 2024
2 parents 8938302 + e269cc5 commit c9479f5
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
distribution = "2201.9.2"
distribution = "2201.9.3"
org = "ballerinax"
name = "openai.audio"
version = "1.0.5"
Expand Down
28 changes: 5 additions & 23 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.2"
distribution-version = "2201.9.3"

[[package]]
org = "ballerina"
name = "auth"
version = "2.11.1"
version = "2.11.2"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -96,14 +96,11 @@ modules = [
[[package]]
org = "ballerina"
name = "io"
version = "1.6.0"
version = "1.6.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
]
modules = [
{org = "ballerina", packageName = "io", moduleName = "io"}
]

[[package]]
org = "ballerina"
Expand Down Expand Up @@ -315,34 +312,19 @@ modules = [
{org = "ballerinai", packageName = "observe", moduleName = "observe"}
]

[[package]]
org = "ballerinax"
name = "openai.audio"
version = "1.0.5"
dependencies = [
{org = "ballerina", name = "http"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "url"},
{org = "ballerinai", name = "observe"}
]
modules = [
{org = "ballerinax", packageName = "openai.audio", moduleName = "openai.audio"}
]

[[package]]
org = "wishulaj"
name = "Audio"
version = "0.1.0"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "http"},
{org = "ballerina", name = "io"},
{org = "ballerina", name = "mime"},
{org = "ballerina", name = "test"},
{org = "ballerina", name = "url"},
{org = "ballerinai", name = "observe"},
{org = "ballerinax", name = "openai.audio"}
{org = "ballerinai", name = "observe"}
]
modules = [
{org = "wishulaj", packageName = "Audio", moduleName = "Audio"}
]

89 changes: 89 additions & 0 deletions ballerina/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Running Tests

## Prerequisites

You need an API key from OpenAI.

To obtain this, refer to the [Ballerina OpenAI Audio Connector](https:/ballerina-platform/module-ballerinax-openai.audio/blob/main/ballerina/Module.md).

## Test Environments

There are two test environments for running the `openai.audio` connector tests. The default environment is a mock server for the OpenAI API. The other environment is the actual OpenAI 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 OpenAI API (Default Environment) |
| live_tests | OpenAI API |

## Running Tests in the Mock Server

To execute the tests on the mock server, ensure that the `isLiveServer` environment variable is either set to `false` or left 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 environment variable.

### Using a `Config.toml` File

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

```toml
isLiveServer = false
```

### Using Environment Variables

Alternatively, you can set the environment variable directly.

For Linux or macOS:

```bash
export isLiveServer=false
```

For Windows:

```bash
setx isLiveServer false
```

Then, run the following command to execute the tests:

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

## Running Tests Against the OpenAI Live API

### Using a `Config.toml` File

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

```toml
isLiveServer = true
apiKey = "<your-openAI-api-key>"
```

### Using Environment Variables

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

For Linux or macOS:

```bash
export isLiveServer=true
export apiKey="<your-openAI-api-key>"
```

For Windows:

```bash
setx isLiveServer true
setx apiKey <your-openAI-api-key>
```

Then, run the following command to execute the tests:

```bash
./gradlew clean test
```
64 changes: 64 additions & 0 deletions ballerina/tests/mock_service.bal

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions ballerina/tests/tests.bal

Large diffs are not rendered by default.

0 comments on commit c9479f5

Please sign in to comment.