From 5b91e99d233e93011504fabc35ea87e2297c53a3 Mon Sep 17 00:00:00 2001 From: Lakshan Sivagnanasothy Date: Mon, 30 May 2022 10:41:14 +0530 Subject: [PATCH] Improve tests --- .github/workflows/ci.yml | 31 ++-- .github/workflows/daily-build.yml | 26 ++-- .github/workflows/dev-stg-release.yml | 40 +---- .github/workflows/release.yml | 42 +---- mongodb/tests/main_test.bal | 216 +++++++++----------------- mongodb/tests/ssl_connection_test.bal | 13 +- 6 files changed, 121 insertions(+), 247 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f012ecb7..8df0c000 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,11 +14,13 @@ jobs: MONGO_INITDB_ROOT_PASSWORD: admin mongodb-ssl: image: rzhilkibaev/mongo-x509-auth-ssl:latest + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -31,7 +33,7 @@ jobs: run: | ./gradlew build - - name: Ballerina Build W/O tests + - name: Ballerina Build uses: ballerina-platform/ballerina-action/@nightly with: args: @@ -39,28 +41,31 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true - - name: Ballerina Build W/ tests + + - name: SSL Tests uses: ballerina-platform/ballerina-action/@nightly with: args: - test --groups mongodb --code-coverage mongodb + test --groups mongodb-ssl --code-coverage env: JAVA_HOME: /usr/lib/jvm/default-jvm # Following credentials are only used during testing in docker container - MONGODB_HOST: mongodb - MONGODB_USER: admin - MONGODB_PASSWORD: admin - - name: Ballerina Build W/ tests (SSL) + WORKING_DIR: ./mongodb + MONGODB_HOST: mongodb-ssl + MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin + + - name: MongoDB Tests uses: ballerina-platform/ballerina-action/@nightly with: args: - test --groups mongodb-ssl --code-coverage + test --groups mongodb --code-coverage mongodb env: JAVA_HOME: /usr/lib/jvm/default-jvm # Following credentials are only used during testing in docker container - WORKING_DIR: ./mongodb - MONGODB_HOST: mongodb-ssl - MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin + MONGODB_HOST: mongodb + MONGODB_USER: admin + MONGODB_PASSWORD: admin + # Read the ballerina test results - name: Read Ballerina Test Results diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index b1ff2439..f51369ec 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -17,13 +17,15 @@ jobs: MONGO_INITDB_ROOT_PASSWORD: admin mongodb-ssl: image: rzhilkibaev/mongo-x509-auth-ssl:latest + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # Set up Java Environment - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 # Grant execute permission to the gradlew script @@ -39,29 +41,29 @@ jobs: run: | ./gradlew build - - name: Ballerina Build W/ tests + - name: SSL Tests uses: ballerina-platform/ballerina-action/@nightly with: args: - test --groups mongodb --code-coverage mongodb + test --groups mongodb-ssl --code-coverage env: JAVA_HOME: /usr/lib/jvm/default-jvm # Following credentials are only used during testing in docker container - MONGODB_HOST: mongodb - MONGODB_USER: admin - MONGODB_PASSWORD: admin + WORKING_DIR: ./mongodb + MONGODB_HOST: mongodb-ssl + MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin - - name: Ballerina Build W/ tests (SSL) + - name: MongoDB Tests uses: ballerina-platform/ballerina-action/@nightly with: args: - test --groups mongodb-ssl --code-coverage + test --groups mongodb --code-coverage mongodb env: JAVA_HOME: /usr/lib/jvm/default-jvm # Following credentials are only used during testing in docker container - WORKING_DIR: ./mongodb - MONGODB_HOST: mongodb-ssl - MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin + MONGODB_HOST: mongodb + MONGODB_USER: admin + MONGODB_PASSWORD: admin # Read the ballerina test results - name: Read Ballerina Test Results diff --git a/.github/workflows/dev-stg-release.yml b/.github/workflows/dev-stg-release.yml index 5a7d890d..8e4284e1 100644 --- a/.github/workflows/dev-stg-release.yml +++ b/.github/workflows/dev-stg-release.yml @@ -16,20 +16,13 @@ jobs: runs-on: ubuntu-latest env: BALLERINA_${{ github.event.inputs.bal_central_environment }}_CENTRAL: true - services: - mongodb: - image: mongo:4.2.0 - env: - # Following credentials are only used during testing in docker container - MONGO_INITDB_ROOT_USERNAME: admin - MONGO_INITDB_ROOT_PASSWORD: admin - mongodb-ssl: - image: rzhilkibaev/mongo-x509-auth-ssl:latest + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -41,29 +34,8 @@ jobs: JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true run: | ./gradlew build - - name: Ballerina Build W/ tests - uses: ballerina-platform/ballerina-action/@master - with: - args: - test --groups mongodb mongodb - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_HOST: mongodb - MONGODB_USER: admin - MONGODB_PASSWORD: admin - - name: Ballerina Build W/ tests (SSL) - uses: ballerina-platform/ballerina-action/@master - with: - args: - test --groups mongodb-ssl - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - WORKING_DIR: ./mongodb - MONGODB_HOST: mongodb-ssl - MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin - - name: Ballerina Build W/O tests + + - name: Ballerina Build uses: ballerina-platform/ballerina-action/@master with: args: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e489997b..06815434 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,21 +7,15 @@ on: jobs: build: runs-on: ubuntu-latest - services: - mongodb: - image: mongo:4.2.0 - env: - # Following credentials are only used during testing in docker container - MONGO_INITDB_ROOT_USERNAME: admin - MONGO_INITDB_ROOT_PASSWORD: admin - mongodb-ssl: - image: rzhilkibaev/mongo-x509-auth-ssl:latest + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 + - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -32,29 +26,8 @@ jobs: JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true run: | ./gradlew build - - name: Ballerina Build W/ tests - uses: ballerina-platform/ballerina-action/@master - with: - args: - test --groups mongodb mongodb - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - MONGODB_HOST: mongodb - MONGODB_USER: admin - MONGODB_PASSWORD: admin - - name: Ballerina Build W/ tests (SSL) - uses: ballerina-platform/ballerina-action/@master - with: - args: - test --groups mongodb-ssl - env: - JAVA_HOME: /usr/lib/jvm/default-jvm - # Following credentials are only used during testing in docker container - WORKING_DIR: ./mongodb - MONGODB_HOST: mongodb-ssl - MONGODB_USER: C=US,ST=CA,L=San Francisco,O=Jaspersoft,OU=JSDev,CN=admin - - name: Ballerina Build W/O tests + + - name: Ballerina Build uses: ballerina-platform/ballerina-action/@master with: args: @@ -62,6 +35,7 @@ jobs: env: JAVA_HOME: /usr/lib/jvm/default-jvm JAVA_OPTS: -DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true + - name: Ballerina Push uses: ballerina-platform/ballerina-action/@master with: diff --git a/mongodb/tests/main_test.bal b/mongodb/tests/main_test.bal index c3b3c7d7..99be6580 100644 --- a/mongodb/tests/main_test.bal +++ b/mongodb/tests/main_test.bal @@ -19,8 +19,8 @@ import ballerina/os; import ballerina/test; string testHostName = os:getEnv("MONGODB_HOST") != "" ? os:getEnv("MONGODB_HOST") : "localhost"; -string testUser = os:getEnv("MONGODB_USER") != "" ? os:getEnv("MONGODB_USER") : ""; -string testPass = os:getEnv("MONGODB_PASSWORD") != "" ? os:getEnv("MONGODB_PASSWORD") : ""; +string testUser = os:getEnv("MONGODB_USER") != "" ? os:getEnv("MONGODB_USER") : "admin"; +string testPass = os:getEnv("MONGODB_PASSWORD") != "" ? os:getEnv("MONGODB_PASSWORD") : "admin"; ConnectionConfig mongoConfig = { host: testHostName, @@ -40,9 +40,9 @@ const COLLECTION_NAME = "moviedetails"; Client mongoClient = check new (mongoConfig, DATABASE_NAME); @test:Config { - groups: ["mongodb"] + groups: ["mongodb"] } -public function initializeInValidClient() { +public function initializeInvalidClient() { log:printInfo("Start initialization test failure"); Client|Error mongoClient = new (mongoConfigError,"MyDb"); if (mongoClient is ApplicationError) { @@ -53,114 +53,73 @@ public function initializeInValidClient() { } @test:Config { - dependsOn: [ initializeInValidClient ], + dependsOn: [ initializeInvalidClient ], groups: ["mongodb"] } -public function testListDatabaseNames() { +public function testListDatabaseNames() returns error? { log:printInfo("----------------- List Databases------------------"); - var returned = mongoClient->getDatabasesNames(); - - if (returned is string[]) { - log:printInfo("Database Names " + returned.toString()); - } else { - log:printInfo(returned.toString()); - test:assertFail("List databases failed!"); - } + string[] dbNames = check mongoClient->getDatabasesNames(); + log:printInfo("Database Names: " + dbNames.toString()); } @test:Config { dependsOn: [ testListDatabaseNames ], groups: ["mongodb"] } -public function testListCollections() returns Error? { +public function testListCollections() returns error? { log:printInfo("----------------- List Collections------------------"); - var returned = mongoClient->getCollectionNames("admin"); - - if (returned is string[]) { - log:printInfo("Collection Names " + returned.toString()); - } else { - log:printInfo(returned.toString()); - test:assertFail("List collections failed!"); - } + string[] collectionNames = check mongoClient->getCollectionNames("admin"); + log:printInfo("Collection Names: " + collectionNames.toString()); } @test:Config { dependsOn: [ testListCollections ], groups: ["mongodb"] } -public function testInsertData() returns Error? { +public function testInsertData() returns error? { log:printInfo("------------------ Inserting Data ------------------"); - map insertDocument = {name: "The Lion King", year: "2019", rating: 8}; - map insertDocument2 = {name: "Black Panther", year: "2018", rating: 7}; + map document1 = {name: "The Lion King", year: "2019", rating: 8}; + map ducument2 = {name: "Black Panther", year: "2018", rating: 7}; - var returned = mongoClient->insert(insertDocument, COLLECTION_NAME); - if (returned is Error) { - log:printInfo(returned.toString()); - test:assertFail("Inserting data failed!"); - } else { - log:printInfo("Successfully inserted document into collection"); - } + check mongoClient->insert(document1, COLLECTION_NAME); + log:printInfo("Successfully inserted document1 into collection"); - returned = mongoClient->insert(insertDocument2, COLLECTION_NAME); - if (returned is Error) { - log:printInfo(returned.toString()); - test:assertFail("Inserting data failed!"); - } else { - log:printInfo("Successfully inserted document into collection"); - } + check mongoClient->insert(ducument2, COLLECTION_NAME); + log:printInfo("Successfully inserted document2 into collection"); } + @test:Config { dependsOn: [ testInsertData ], groups: ["mongodb"] } -public function testInsertDataWithDbName() returns Error? { +public function testInsertDataWithDbName() returns error? { log:printInfo("------------------ Inserting Data With Second Database ------------------"); - map insertDocument = {name: "The Lion King", year: "2019", rating: 8}; - map insertDocument2 = {name: "Black Panther", year: "2018", rating: 7}; + map document1 = {name: "The Lion King", year: "2019", rating: 8}; + map document2 = {name: "Black Panther", year: "2018", rating: 7}; - var returned = mongoClient->insert(insertDocument, COLLECTION_NAME, "anothermoviecollection"); - if (returned is Error) { - log:printInfo(returned.toString()); - test:assertFail("Inserting data failed!"); - } else { - log:printInfo("Successfully inserted document into collection"); - } + check mongoClient->insert(document1, COLLECTION_NAME, "anothermoviecollection"); + log:printInfo("Successfully inserted document1 into collection"); - returned = mongoClient->insert(insertDocument2, COLLECTION_NAME, "anothermoviecollection"); - if (returned is Error) { - log:printInfo(returned.toString()); - test:assertFail("Inserting data failed!"); - } else { - log:printInfo("Successfully inserted document into collection"); - } + check mongoClient->insert(document2, COLLECTION_NAME, "anothermoviecollection"); + log:printInfo("Successfully inserted document2 into collection"); } @test:Config { dependsOn: [ testInsertDataWithDbName ], groups: ["mongodb"] } -public function testCountDocuments() returns Error? { +public function testCountDocuments() returns error? { log:printInfo("----------------- Count Documents------------------"); - var returned = mongoClient->countDocuments(COLLECTION_NAME, (),()); - if (returned is int) { - log:printInfo("Documents counted successfully '" + returned.toString() + "'"); - test:assertEquals(2, returned); - } else { - log:printInfo(returned.toString()); - test:assertFail("Count Failure"); - } + int documentCount = check mongoClient->countDocuments(COLLECTION_NAME, (),()); + log:printInfo("Documents counted successfully. Count: " + documentCount.toString()); + test:assertEquals(2, documentCount); - returned = mongoClient->countDocuments(COLLECTION_NAME,() , { + int documentCount2018 = check mongoClient->countDocuments(COLLECTION_NAME,() , { year: "2018" }); - if (returned is int) { - log:printInfo("Documents counted successfully '" + returned.toString() + "'"); - test:assertEquals(1, returned); - } else { - log:printInfo(returned.toString()); - test:assertFail("Count Failure"); - } + log:printInfo("Documents counted successfully. Count: " + documentCount2018.toString()); + test:assertEquals(1, documentCount2018); } @test:Config { @@ -183,31 +142,31 @@ public function testListIndices() returns error? { public function testFindData() returns error? { log:printInfo("----------------- Querying Data ----------------"); - map insertDocument1 = {name: "Joker", year: "2019", rating: 7}; - map insertDocument2 = {name: "Black Panther", year: "2018", rating: 7}; + map document1 = {name: "Joker", year: "2019", rating: 7}; + map document2 = {name: "Black Panther", year: "2018", rating: 7}; - check mongoClient->insert(insertDocument1, COLLECTION_NAME); - check mongoClient->insert(insertDocument2, COLLECTION_NAME); + check mongoClient->insert(document1, COLLECTION_NAME); + check mongoClient->insert(document2, COLLECTION_NAME); map findDoc = {year: "2019"}; - stream returned = check mongoClient->find(COLLECTION_NAME,filter = findDoc); - check returned.forEach(function(Movie data){ + stream result = check mongoClient->find(COLLECTION_NAME,filter = findDoc); + check result.forEach(function(Movie data){ log:printInfo(data.year.toString()); test:assertEquals(data.year,"2019","Querying year 2019 filter failed"); }); log:printInfo("Querying year 2019 filter tested successfully"); map sortDoc = {name: 1}; - returned = check mongoClient->find(COLLECTION_NAME, filter = findDoc, sort = sortDoc); - check returned.forEach(function(Movie data){ + result = check mongoClient->find(COLLECTION_NAME, filter = findDoc, sort = sortDoc); + check result.forEach(function(Movie data){ log:printInfo(data.name); }); log:printInfo("Querying year 2019 sort data tested successfully"); - returned = check mongoClient->find(COLLECTION_NAME, filter=findDoc, sort=sortDoc, 'limit=1); + result = check mongoClient->find(COLLECTION_NAME, filter=findDoc, sort=sortDoc, 'limit=1); int count = 0; - check returned.forEach(function(Movie data){ - count = count+1; + check result.forEach(function(Movie data){ + count += 1; log:printInfo(data.name); }); test:assertEquals(count, 1, "Querying filtered sort and limit failed"); @@ -224,121 +183,90 @@ public function testFindDataWithProjection() returns error? { map findDoc = {year: "2019"}; map projectionDoc = {name: 1, year: true}; - stream returned = check mongoClient->find(COLLECTION_NAME, projection = projectionDoc, + stream result = check mongoClient->find(COLLECTION_NAME, projection = projectionDoc, filter = findDoc); - check returned.forEach(function(MovieWithoutRating data){ + check result.forEach(function(MovieWithoutRating data){ log:printInfo(data.year.toString()); test:assertEquals(data.year,"2019","Querying year 2019 filter with projection failed"); }); log:printInfo("Querying year 2019 filter with projection tested successfully"); map sortDoc = {name: 1}; - returned = check mongoClient->find(COLLECTION_NAME, projection = projectionDoc, filter = findDoc, sort = sortDoc); - check returned.forEach(function(MovieWithoutRating data){ + result = check mongoClient->find(COLLECTION_NAME, projection = projectionDoc, filter = findDoc, sort = sortDoc); + check result.forEach(function(MovieWithoutRating data){ log:printInfo(data.name); }); log:printInfo("Querying year 2019 sort data with projection tested successfully"); - returned = check mongoClient->find(COLLECTION_NAME, projection = projectionDoc, filter=findDoc, sort=sortDoc, + result = check mongoClient->find(COLLECTION_NAME, projection = projectionDoc, filter=findDoc, sort=sortDoc, 'limit=1); int count = 0; - check returned.forEach(function(MovieWithoutRating data){ - count = count+1; + check result.forEach(function(MovieWithoutRating data){ + count += 1; log:printInfo(data.name); }); test:assertEquals(count, 1, "Querying filtered sort and limit with projection failed"); log:printInfo("Querying filtered sort and limit with projection tested successfully"); - } @test:Config { dependsOn: [ testFindDataWithProjection ], groups: ["mongodb"] } -function testUpdateDocument() returns Error? { +function testUpdateDocument() returns error? { log:printInfo("------------------ Updating Data -------------------"); map replaceFilter = {name: "The Lion King"}; map replaceDoc = { "$set": {name: "The Lion King", year: "2019", rating: 6}}; - var modifiedCount = mongoClient->update(replaceDoc, COLLECTION_NAME, (), replaceFilter, false); - if (modifiedCount is int) { - log:printInfo("Modified count: " + modifiedCount.toString()); - test:assertEquals(modifiedCount, 1, "Document modification failed"); - } else { - log:printInfo(modifiedCount.toString()); - test:assertFail("Document modification failed"); - } + int modifiedCount = check mongoClient->update(replaceDoc, COLLECTION_NAME, (), replaceFilter, false); + log:printInfo("Modified count: " + modifiedCount.toString()); + test:assertEquals(modifiedCount, 1, "Document modification failed"); replaceFilter = {rating: 7}; replaceDoc = { "$inc": {rating: 2}}; - modifiedCount = mongoClient->update(replaceDoc, COLLECTION_NAME, (), replaceFilter, true); - if (modifiedCount is int) { - log:printInfo("Modified count: " + modifiedCount.toString()); - test:assertEquals(modifiedCount, 3, "Document modification multiple failed"); - } else { - log:printInfo(modifiedCount.toString()); - test:assertFail("Document modification multiple failed"); - } + modifiedCount = check mongoClient->update(replaceDoc, COLLECTION_NAME, (), replaceFilter, true); + log:printInfo("Modified count: " + modifiedCount.toString()); + test:assertEquals(modifiedCount, 3, "Document modification multiple failed"); } @test:Config { dependsOn: [ testUpdateDocument ], groups: ["mongodb"] } -function testUpdateDocumentUpsertTrue() returns Error? { +function testUpdateDocumentUpsertTrue() returns error? { log:printInfo("------------------ Updating Data (Upsert) -------------------"); map replaceFilter = {name: "The Lion King 2"}; map replaceDoc = { "$set": {name: "The Lion King 2", year: "2019", rating: 7}}; - var modifiedCount = mongoClient->update(replaceDoc, COLLECTION_NAME, (), replaceFilter, true, true); - if (modifiedCount is int) { - log:printInfo("Modified count: " + modifiedCount.toString()); - test:assertEquals(modifiedCount, 0, "Document modification failed"); - } else { - log:printInfo(modifiedCount.toString()); - test:assertFail("Replacing data failed"); - } + int modifiedCount = check mongoClient->update(replaceDoc, COLLECTION_NAME, (), replaceFilter, true, true); + log:printInfo("Modified count: " + modifiedCount.toString()); + test:assertEquals(modifiedCount, 0, "Document modification failed"); } @test:Config { dependsOn: [ testUpdateDocumentUpsertTrue ], groups: ["mongodb"] } -function testDelete() returns Error? { +function testDelete() returns error? { log:printInfo("------------------ Deleting Data -------------------"); map deleteFilter = {"rating": 9}; - var deleteRet = mongoClient->delete(COLLECTION_NAME, (), deleteFilter, true); - if (deleteRet is int) { - log:printInfo("Deleted count: " + deleteRet.toString()); - test:assertEquals(deleteRet, 3, msg = "Document deletion multiple failed"); - } else { - log:printInfo(deleteRet.toString()); - test:assertFail("Deleting filter multiple failed"); - } + int deleteDocCount = check mongoClient->delete(COLLECTION_NAME, (), deleteFilter, true); + log:printInfo("Deleted count: " + deleteDocCount.toString()); + test:assertEquals(deleteDocCount, 3, msg = "Document deletion multiple failed"); - deleteRet = mongoClient->delete(COLLECTION_NAME, (), (), true); - if (deleteRet is int) { - log:printInfo("Deleted count: " + deleteRet.toString()); - test:assertEquals(deleteRet, 2, msg = "Document deletion failed"); - } else { - log:printInfo(deleteRet.toString()); - test:assertFail("Deleting data failed"); - } + deleteDocCount = check mongoClient->delete(COLLECTION_NAME, (), (), true); + log:printInfo("Deleted count: " + deleteDocCount.toString()); + test:assertEquals(deleteDocCount, 2, msg = "Document deletion failed"); log:printInfo("------------------ Deleting Data From Second Database-------------------"); - deleteRet = mongoClient->delete(COLLECTION_NAME, "anothermoviecollection", (), true); - if (deleteRet is int) { - log:printInfo("Deleted count: " + deleteRet.toString()); - test:assertEquals(deleteRet, 2, msg = "Document deletion failed"); - } else { - log:printInfo(deleteRet.toString()); - test:assertFail("Deleting data failed"); - } + deleteDocCount = check mongoClient->delete(COLLECTION_NAME, "anothermoviecollection", (), true); + log:printInfo("Deleted count: " + deleteDocCount.toString()); + test:assertEquals(deleteDocCount, 2, msg = "Document deletion failed"); mongoClient->close(); } diff --git a/mongodb/tests/ssl_connection_test.bal b/mongodb/tests/ssl_connection_test.bal index b6922b7c..43a247e2 100644 --- a/mongodb/tests/ssl_connection_test.bal +++ b/mongodb/tests/ssl_connection_test.bal @@ -67,17 +67,10 @@ public function initializeInValidConfig() { dependsOn: [ initializeInValidConfig ], groups: ["mongodb-ssl"] } -public function testSSLConnection() returns Error? { - +public function testSSLConnection() returns error? { log:printInfo("------------------ Inserting Data on SSL Connection ------------------"); - map insertDocument = {name: "The Lion King", year: "2019", rating: 8}; + map document = {name: "The Lion King", year: "2019", rating: 8}; Client mongoClient = check new (sslMongoConfig,"admin"); - var returned = mongoClient->insert(insertDocument, "test"); - if (returned is DatabaseError) { - log:printInfo(returned.toString()); - test:assertFail("Inserting data failed!"); - } else { - log:printInfo("Successfully inserted document into collection"); - } + check mongoClient->insert(document, "test"); }