-
Notifications
You must be signed in to change notification settings - Fork 204
Database Integration Tests : SQL Generation : Adding new tests for a database
Ephrim Stanley edited this page Mar 15, 2022
·
3 revisions
The SQL generation tests are run against real databases. There are 2 ways to inject a database connection into the test framework :
- Static test connections - These are test connections configured in the TestServer's configuration file. These are static in the sense that they point to databases that you might already have access to.
- Dynamic test connections - These are test connections configured via code. The TestServer makes use of ConnectionTestManager implementations that can create databases and connections on demand. For e.g. spin up a database in a Docker container.
- Build the legend-engine project
- Start org.finos.legend.engine.server.test.shared.TestServer with the following configuration
server <path to>userTestConfig_withTestConnections.json
The following API
curl -X GET "http://localhost:6060/api/pure/v1/utilities/testConnection/getTestConnection/H2" -H "accept: application/json"
should return a response like
{
"_type": "RelationalDatabaseConnection",
...
"datasourceSpecification": {
"_type": "static",
"sourceInformation": null,
"host": "127.0.0.1",
"port": 4038,
"databaseName": "temp"
},
"authenticationStrategy": {
"_type": "h2Default",
"sourceInformation": null
},
"databaseType": "H2",
"postProcessors": []
}
- Build the legend-pure project
- Start the PureIDE Server with configuration that points to the test server started above
-Dlegend.test.server.host=127.0.0.1 -Dlegend.test.server.port=6060 -Dlegend.test.clientVersion=vX_X_X -Dlegend.test.serverVersion=v1
Add a go
function to welcome.pure
Each database type has a top level "test runner" function which collects various test functions and executes them with a particular database type.
function go():Any[*]
{
meta::relational::tests::dbSpecificTests::H2::runSQLQueryTests();
}
Hit F9
to run the tests. Test summary statistics are printed in the console
pane
function <<dbTest.Test>> meta::relational::tests::dbSpecificTests::sqlQueryTests::dynaFunctions::numeric::testFloor2(config:DbTestConfig[1]):String[0..1]
{
let dynaFunc = ^DynaFunction(name='floor', parameters=[^Literal(value= 5.4)]);
let expected = ^Literal(value=5);
runDynaFunctionDatabaseTest($dynaFunc, $expected, $config);
}
Rinse and repeat
- For Legend Users
- For Legend Maintainers