Welcome to step 3 on TGIMBANodeJSAPI testing. If you remember last time, I detailed the first half of the integration tests by describing the AWS client code integration test solution. Here, I will continue by describing the SQL Server integration test solution.
First and just like the AWS client code, I had to get a local version of SQL Server that I can use to connect with. At first, I was a little concerned that this would not be possible…but docker to the rescue. After a little ‘googling’ later, I found an excellent post (reference #1) that described in fairly easy steps how to accomplish this. More specifically:
- Install/setup docker (see reference #1 for details)
- Pull down the SQL Server Docker Image
- run command in terminal – docker pull microsoft/mssql-server-linux:2017-latest
- Run the container
- run command in terminal
docker run -d -–name name_your_container -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=P@55w0rd’ -e ‘MSSQL_PID=Developer’ -p 1433:1433 microsoft/mssql-server-linux:2017-latest
- Install sql client
- run command in terminal – npm install -g sql-cli
- Connect to the database
- run command in terminal – mssql -u sa -p P@55w0rd
- Run a query to verify database is running
- run command in database – .databases
NOTE: The queries are different. I was expecting something like ‘select * from databases’. This is not the case with this client (at least). So, I decided to go another route. More specifically, I just connected the Tedious client that I use for production connectivity and turned it to this local docker SQL Server version and was able to connect. The connection looks like this:
Second, I replicated my production SQL Server database to this local one by going the following:
- Creating database table create and drop SQL statements that can be run within the TGIMBA API.
- Creating a setup Script
- Adding a setup test. This test runs with the other integration tests (see below)
Thirdly, I put it all together up to the point of creating the local SQL Server. Specifically:
- Unit tests running
- SQL Server integration tests running
The next blog will be to add a complete set of integration tests for each expected API command (i.e. register user, login, etc.). After that,this track will be moving the Dynamo Db and SQL Server local environments into one docker container that I can easily port into my code for use in my Continuous Development Continuous Integration (CDCI) pipeline.