From 98d5ca5078dbce74c1186a52e6fe5e229eca09df Mon Sep 17 00:00:00 2001 From: SanduniU Date: Wed, 14 Aug 2024 14:44:55 +0530 Subject: [PATCH 1/7] Remove additional newlines --- ballerina/tests/test.bal | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 98e141c..0d01239 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -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 { @@ -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 { @@ -87,7 +85,6 @@ function testCreateMessage() returns error? { io:println("Created Message: ", res); test:assertNotEquals(res.id, ""); messageId = res.id; - } @test:Config { @@ -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 { @@ -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 { @@ -169,7 +164,6 @@ function testCreateThread() returns error? { io:println("Thread ID: ", response.id); threadId = response.id; test:assertNotEquals(response.id, ""); - } @test:Config { @@ -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 { @@ -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 { @@ -233,7 +225,6 @@ function testCreateAssistant() returns error? { io:println("Assistant ID: ", res.id); assistantId = res.id; test:assertNotEquals(res.id, ""); - } @test:Config { @@ -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 { @@ -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 { @@ -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 { @@ -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"); - } From 5eb81ac0eb6bb0066df97ed415ca5a37ecfefd38 Mon Sep 17 00:00:00 2001 From: SanduniU Date: Fri, 16 Aug 2024 09:25:30 +0530 Subject: [PATCH 2/7] Change the token configuration --- ballerina/tests/README.md | 6 +++--- ballerina/tests/test.bal | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 22ac86f..6ccae29 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -61,7 +61,7 @@ Create a `Config.toml` file in the `tests` directory and add your authentication ```toml isLiveServer = true -apiKey = "" +OPENAI_API_KEY = "" ``` ### Using Environment Variables @@ -72,14 +72,14 @@ For Linux or macOS: ```bash export isLiveServer=true -export apiKey="" +export OPENAI_API_KEY="" ``` For Windows: ```bash setx isLiveServer true -setx apiKey +setx OPENAI_API_KEY ``` Then, run the following command to execute the tests: diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 0d01239..a1525ce 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -19,7 +19,7 @@ import ballerina/os; import ballerina/test; configurable boolean isLiveServer = os:getEnv("isLiveServer") == "true"; -configurable string token = ?; +configurable string token = isLiveServer ? os:getEnv("OPENAI_API_KEY"): "test"; configurable string serviceUrl = isLiveServer ? "https://api.openai.com/v1" : "http://localhost:9090"; ConnectionConfig config = { From a5b1bd4ec04513e9ab9132322d4c0b366c8ad529 Mon Sep 17 00:00:00 2001 From: SanduniU Date: Fri, 16 Aug 2024 09:38:10 +0530 Subject: [PATCH 3/7] Change the token configuration --- ballerina/tests/README.md | 6 +++--- ballerina/tests/mock_service.bal | 2 +- ballerina/tests/test.bal | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 6ccae29..7fc8994 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -60,7 +60,7 @@ Then, run the following command to execute the tests: Create a `Config.toml` file in the `tests` directory and add your authentication credentials: ```toml -isLiveServer = true +IS_LIVE_SERVER = true OPENAI_API_KEY = "" ``` @@ -71,14 +71,14 @@ Alternatively, you can set your authentication credentials as environment variab For Linux or macOS: ```bash -export isLiveServer=true +export IS_LIVE_SERVER=true export OPENAI_API_KEY="" ``` For Windows: ```bash -setx isLiveServer true +setx IS_LIVE_SERVER true setx OPENAI_API_KEY ``` diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 1040c04..5866519 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -980,7 +980,7 @@ http:Service mockService = service object { }; function init() returns error? { - if isLiveServer { + if IS_LIVE_SERVER { log:printInfo("Skipping mock server initialization as the tests are running on live server"); return; } diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index a1525ce..6294607 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -18,13 +18,13 @@ import ballerina/io; import ballerina/os; import ballerina/test; -configurable boolean isLiveServer = os:getEnv("isLiveServer") == "true"; -configurable string token = isLiveServer ? os:getEnv("OPENAI_API_KEY"): "test"; -configurable string serviceUrl = isLiveServer ? "https://api.openai.com/v1" : "http://localhost:9090"; +configurable boolean IS_LIVE_SERVER = os:getEnv("IS_LIVE_SERVER") == "true"; +configurable string OPENAI_API_KEY = IS_LIVE_SERVER ? os:getEnv("OPENAI_API_KEY") : "test"; +configurable string serviceUrl = IS_LIVE_SERVER ? "https://api.openai.com/v1" : "http://localhost:9090"; ConnectionConfig config = { auth: { - token + token: OPENAI_API_KEY } }; final Client openAIAssistant = check new (config, serviceUrl); From 637b8e6adf9c9ca4703de116af3b62eaf47c6e5c Mon Sep 17 00:00:00 2001 From: SanduniU Date: Fri, 16 Aug 2024 09:59:53 +0530 Subject: [PATCH 4/7] Change the case of the variable names --- ballerina/tests/README.md | 8 ++++---- ballerina/tests/mock_service.bal | 2 +- ballerina/tests/test.bal | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 7fc8994..70323af 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -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: @@ -60,8 +60,8 @@ Then, run the following command to execute the tests: Create a `Config.toml` file in the `tests` directory and add your authentication credentials: ```toml -IS_LIVE_SERVER = true -OPENAI_API_KEY = "" +isLiveSerer = true +token = "" ``` ### Using Environment Variables diff --git a/ballerina/tests/mock_service.bal b/ballerina/tests/mock_service.bal index 5866519..1040c04 100644 --- a/ballerina/tests/mock_service.bal +++ b/ballerina/tests/mock_service.bal @@ -980,7 +980,7 @@ http:Service mockService = service object { }; function init() returns error? { - if IS_LIVE_SERVER { + if isLiveServer { log:printInfo("Skipping mock server initialization as the tests are running on live server"); return; } diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 6294607..51eaa27 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -18,13 +18,13 @@ import ballerina/io; import ballerina/os; import ballerina/test; -configurable boolean IS_LIVE_SERVER = os:getEnv("IS_LIVE_SERVER") == "true"; -configurable string OPENAI_API_KEY = IS_LIVE_SERVER ? os:getEnv("OPENAI_API_KEY") : "test"; -configurable string serviceUrl = IS_LIVE_SERVER ? "https://api.openai.com/v1" : "http://localhost:9090"; +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 = { auth: { - token: OPENAI_API_KEY + token: token } }; final Client openAIAssistant = check new (config, serviceUrl); From 5002268f04aea7dc221ae4476e7b3f4287c0ff13 Mon Sep 17 00:00:00 2001 From: SanduniU Date: Fri, 16 Aug 2024 10:02:42 +0530 Subject: [PATCH 5/7] Fix a typo in the README.md --- ballerina/tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 70323af..2bbc6fe 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -60,7 +60,7 @@ Then, run the following command to execute the tests: Create a `Config.toml` file in the `tests` directory and add your authentication credentials: ```toml -isLiveSerer = true +isLiveServer = true token = "" ``` From b04154621f99b3dd1b057da4011601bdcada22b0 Mon Sep 17 00:00:00 2001 From: SanduniU Date: Fri, 16 Aug 2024 10:27:06 +0530 Subject: [PATCH 6/7] Fix a typo in the documentation --- ballerina/tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 2bbc6fe..cd536b9 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -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. From 2e44421107e0141bbdd83648cbdec01c7a8f462a Mon Sep 17 00:00:00 2001 From: Sanduni Ubayasiri <115542118+SanduniU@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:30:31 +0530 Subject: [PATCH 7/7] Update ballerina/tests/test.bal Co-authored-by: Nipuna Ransinghe --- ballerina/tests/test.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 51eaa27..610b91e 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -24,7 +24,7 @@ configurable string serviceUrl = isLiveServer ? "https://api.openai.com/v1" : "h ConnectionConfig config = { auth: { - token: token + token } }; final Client openAIAssistant = check new (config, serviceUrl);