From f94d96d2fa94f9bf5aee6519ccb92a9fe31c2d1c Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 8 Feb 2024 14:14:32 +0530 Subject: [PATCH] enable mssql database tests --- ballerina/build.gradle | 116 ++++++++++++++++----------------- ballerina/tests/init-tests.bal | 2 +- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 2838bf4..7c47eaf 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -200,67 +200,67 @@ task stopMySQLTestDockerContainer() { } } -//task createMSSQLTestDockerImage(type: Exec) { -// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { -// def standardOutput = new ByteArrayOutputStream() -// commandLine 'sh', '-c', "docker build -f $project.projectDir/tests/resources/mssql/Dockerfile -t ballerina-persist-mssql" + -// " -q $project.projectDir/tests/resources/mssql/" -// doLast { -// checkExecResult(executionResult, 'Error', standardOutput) -// sleep(10 * 1000) -// } -// } -//} +task createMSSQLTestDockerImage(type: Exec) { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + def standardOutput = new ByteArrayOutputStream() + commandLine 'sh', '-c', "docker build -f $project.projectDir/tests/resources/mssql/Dockerfile -t ballerina-persist-mssql" + + " -q $project.projectDir/tests/resources/mssql/" + doLast { + checkExecResult(executionResult, 'Error', standardOutput) + sleep(10 * 1000) + } + } +} -//def checkMSSQLTestDockerContainerStatus(containerName) { -// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { -// try { -// return exec { -// commandLine 'sh', '-c', -// "docker exec ${containerName} /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Test123#" -// }.exitValue -// } catch (all) { -// return 1; -// } -// } -//} +def checkMSSQLTestDockerContainerStatus(containerName) { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + try { + return exec { + commandLine 'sh', '-c', + "docker exec ${containerName} /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Test123#" + }.exitValue + } catch (all) { + return 1; + } + } +} -//task startMSSQLTestDockerContainer(type: Exec) { -// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { -// def standardOutput = new ByteArrayOutputStream() -// commandLine 'sh', '-c', -// "docker run --rm -d --name ballerina-persist-mssql -e ACCEPT_EULA=1 -e SA_PASSWORD=Test123# -p 1433:1433 -d ballerina-persist-mssql" -// def healthCheck = 1; -// def counter = 0; -// doLast { -// checkExecResult(executionResult, 'Error', standardOutput) -// while (healthCheck != 0 && counter < 12) { -// sleep(5 * 1000) -// healthCheck = checkMSSQLTestDockerContainerStatus("ballerina-persist-mssql") -// counter = counter + 1; -// } -// if (healthCheck != 0) { -// throw new GradleException("Docker container 'ballerina-persist-mssql' health test exceeded timeout!") -// } -// } -// } -//} +task startMSSQLTestDockerContainer(type: Exec) { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + def standardOutput = new ByteArrayOutputStream() + commandLine 'sh', '-c', + "docker run --rm -d --name ballerina-persist-mssql -e ACCEPT_EULA=1 -e SA_PASSWORD=Test123# -p 1433:1433 -d ballerina-persist-mssql" + def healthCheck = 1; + def counter = 0; + doLast { + checkExecResult(executionResult, 'Error', standardOutput) + while (healthCheck != 0 && counter < 12) { + sleep(5 * 1000) + healthCheck = checkMSSQLTestDockerContainerStatus("ballerina-persist-mssql") + counter = counter + 1; + } + if (healthCheck != 0) { + throw new GradleException("Docker container 'ballerina-persist-mssql' health test exceeded timeout!") + } + } + } +} -//task stopMSSQLTestDockerContainer() { -// doLast { -// if (!Os.isFamily(Os.FAMILY_WINDOWS)) { -// try { -// def stdOut = new ByteArrayOutputStream() -// exec { -// commandLine 'sh', '-c', "docker stop ballerina-persist-mssql" -// standardOutput = stdOut -// } -// } catch (all) { -// println("Process can safely ignore stopTestDockerContainer task") -// } -// } -// } -//} +task stopMSSQLTestDockerContainer() { + doLast { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + try { + def stdOut = new ByteArrayOutputStream() + exec { + commandLine 'sh', '-c', "docker stop ballerina-persist-mssql" + standardOutput = stdOut + } + } catch (all) { + println("Process can safely ignore stopTestDockerContainer task") + } + } + } +} task createPostgreSQLTestDockerImage(type: Exec) { if (!Os.isFamily(Os.FAMILY_WINDOWS)) { diff --git a/ballerina/tests/init-tests.bal b/ballerina/tests/init-tests.bal index 3b72d32..7ca47f0 100644 --- a/ballerina/tests/init-tests.bal +++ b/ballerina/tests/init-tests.bal @@ -64,7 +64,7 @@ configurable record {| @test:BeforeSuite function initSuite() returns error? { check initMySQLTest(); - //check initMSSQLTest(); + check initMSSQLTest(); check initPostgreSQLTest(); check initH2Test(); }