Skip to content

Commit

Permalink
Merge pull request #11 from SanduniU/testing
Browse files Browse the repository at this point in the history
Change the token configuration
  • Loading branch information
NipunaRanasinghe authored Aug 16, 2024
2 parents 5793257 + 2e44421 commit 2ac7256
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
16 changes: 8 additions & 8 deletions ballerina/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You can run the tests in either of these environments, and each has its own comp

## 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.
To execute the tests on the mock server, ensure that the `IS_LIVE_SERVER` 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.

Expand All @@ -38,13 +38,13 @@ Alternatively, you can set the environment variable directly.
For Linux or macOS:

```bash
export isLiveServer=false
export IS_LIVE_SERVER=false
```

For Windows:

```bash
setx isLiveServer false
setx IS_LIVE_SERVER false
```

Then, run the following command to execute the tests:
Expand All @@ -61,7 +61,7 @@ Create a `Config.toml` file in the `tests` directory and add your authentication

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

### Using Environment Variables
Expand All @@ -71,15 +71,15 @@ Alternatively, you can set your authentication credentials as environment variab
For Linux or macOS:

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

For Windows:

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

Then, run the following command to execute the tests:
Expand Down
17 changes: 2 additions & 15 deletions ballerina/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import ballerina/io;
import ballerina/os;
import ballerina/test;

configurable boolean isLiveServer = os:getEnv("isLiveServer") == "true";
configurable string token = ?;
configurable boolean isLiveServer = os:getEnv("IS_LIVE_SERVER") == "true";
configurable string token = isLiveServer ? os:getEnv("OPENAI_API_KEY") : "test";
configurable string serviceUrl = isLiveServer ? "https://api.openai.com/v1" : "http://localhost:9090";

ConnectionConfig config = {
Expand Down Expand Up @@ -51,7 +51,6 @@ function testDeleteMessage() returns error? {
DeleteMessageResponse res = check openAIAssistant->/threads/[threadId]/messages/[messageId].delete(headers);
io:println("Message deleted successfully: ", res);
test:assertTrue(res.deleted == true, msg = "Failed to delete message");

}

@test:Config {
Expand All @@ -66,7 +65,6 @@ function testGetMessage() returns error? {
MessageObject res = check openAIAssistant->/threads/[threadId]/messages/[messageId].get(headers);
io:println("Message Details: ", res);
test:assertEquals(res.id, messageId, msg = "Retrieved message ID does not match the requested ID");

}

@test:Config {
Expand All @@ -87,7 +85,6 @@ function testCreateMessage() returns error? {
io:println("Created Message: ", res);
test:assertNotEquals(res.id, "");
messageId = res.id;

}

@test:Config {
Expand Down Expand Up @@ -133,7 +130,6 @@ function testListRuns() returns error? {
ListRunsResponse res = check openAIAssistant->/threads/[threadId]/runs.get(headers);
io:println("Runs in Thread: ", res.data);
test:assertNotEquals(res.data.length(), 0, msg = "No runs found in the thread");

}

@test:Config {
Expand All @@ -154,7 +150,6 @@ function testCreateThreadAndRun() returns error? {
// RunObject resp = check openAIAssistant->/threads/runs.post(createThreadAndRunReq, headers);
// io:println("Created Thread and Run: ", resp);
// test:assertNotEquals(resp.id, "", msg = "Thread and Run creation failed: No Run ID returned");

}

@test:Config {
Expand All @@ -169,7 +164,6 @@ function testCreateThread() returns error? {
io:println("Thread ID: ", response.id);
threadId = response.id;
test:assertNotEquals(response.id, "");

}

@test:Config {
Expand All @@ -184,7 +178,6 @@ function testDeleteAssistant() returns error? {
DeleteAssistantResponse res = check openAIAssistant->/assistants/[assistantId].delete(headers);
io:println("Assistant deleted successfully: ", res);
test:assertTrue(res.deleted == true, msg = "Failed to delete assistant");

}

@test:Config {
Expand All @@ -199,7 +192,6 @@ function testGetAssistant() returns error? {
AssistantObject res = check openAIAssistant->/assistants/[assistantId].get(headers);
io:println("Assistant Details: ", res);
test:assertEquals(res.id, assistantId);

}

@test:Config {
Expand Down Expand Up @@ -233,7 +225,6 @@ function testCreateAssistant() returns error? {
io:println("Assistant ID: ", res.id);
assistantId = res.id;
test:assertNotEquals(res.id, "");

}

@test:Config {
Expand All @@ -249,7 +240,6 @@ function testListAssistants() returns error? {
ListAssistantsResponse res = check openAIAssistant->/assistants.get(headers, query);
io:println("Assistant List: ", res.data);
test:assertTrue(res is ListAssistantsResponse);

}

@test:Config {
Expand All @@ -265,7 +255,6 @@ function testGetRunStep() returns error? {
io:println("Run Step Details: ", res);
test:assertEquals(res.id, stepId, msg = "Retrieved step ID does not match the requested ID");
}

}

@test:Config {
Expand Down Expand Up @@ -294,7 +283,6 @@ function testGetThread() returns error? {
ThreadObject res = check openAIAssistant->/threads/[threadId].get(headers);
io:println("Thread Details: ", res);
test:assertEquals(res.id, threadId);

}

@test:Config {
Expand All @@ -305,5 +293,4 @@ function testGetRun() returns error? {
RunObject res = check openAIAssistant->/threads/[threadId]/runs/[runId].get(headers);
io:println("Run Details: ", res);
test:assertEquals(res.id, runId, msg = "Retrieved run ID does not match the requested ID");

}

0 comments on commit 2ac7256

Please sign in to comment.