Skip to content

Commit

Permalink
enable mssql database tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daneshk committed Feb 8, 2024
1 parent a78aebd commit f94d96d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
116 changes: 58 additions & 58 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion ballerina/tests/init-tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ configurable record {|
@test:BeforeSuite
function initSuite() returns error? {
check initMySQLTest();
//check initMSSQLTest();
check initMSSQLTest();
check initPostgreSQLTest();
check initH2Test();
}
Expand Down

0 comments on commit f94d96d

Please sign in to comment.