Skip to content

Commit

Permalink
Add a README.md for test
Browse files Browse the repository at this point in the history
  • Loading branch information
KATTA-00 committed Aug 9, 2024
1 parent 2417191 commit 95229c7
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
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 token from OpenAI.

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

## Test Environments

There are two test environments for running the `openai.finetunes` 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
token = "<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 token="<your-openAI-api-key>"
```

For Windows:

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

Then, run the following command to execute the tests:

```bash
./gradlew clean test
```
5 changes: 3 additions & 2 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import ballerina/io;
configurable boolean isLiveServer = ?;
configurable string token = ?;
configurable string serviceUrl = isLiveServer ? "https://api.openai.com/v1" : "http://localhost:9090";
final ConnectionConfig config = {auth: {token}};
configurable string apiKey = isLiveServer ? token : "";

final ConnectionConfig config = {auth: {token: apiKey}};
final Client baseClient = check new Client(config, serviceUrl);
final string fileName = "sample.jsonl";

Expand Down Expand Up @@ -246,7 +247,7 @@ isolated function testRetrieveFineTuningJob() returns error? {
FineTuningJob jobResponse = check baseClient->/fine_tuning/jobs/[jobId].get();

test:assertEquals(jobResponse.id, jobId, "Job id mismatched");
test:assertTrue(jobResponse.hasKey("object"), "Response does not have the key 'object'");
test:assertEquals(jobResponse.'object, "fine_tuning.job", "Response does not have the key 'object'");
}

@test:Config {
Expand Down

0 comments on commit 95229c7

Please sign in to comment.