TGIMBA TypeScript API Tuneup – Step 3 – Local SQL Server Integration Tests

Git  Code

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

Screen Shot 2017-12-03 at 2.39.45 PM

  • 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

Screen Shot 2017-12-03 at 2.43.32 PM

  • Connect to the database
    • run command in terminal – mssql -u sa -p P@55w0rd

Screen Shot 2017-12-03 at 3.01.25 PM

  • Run a query to verify database is running
    • run command in database – .databases

Screen Shot 2017-12-03 at 2.49.05 PM

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:

Screen Shot 2017-12-03 at 11.34.10 PM

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.Screen Shot 2017-12-03 at 11.24.47 PM
  • Creating a setup Script

Screen Shot 2017-12-03 at 11.18.47 PM

  • Adding a setup test.  This test runs with the other integration tests (see below)

Screen Shot 2017-12-03 at 11.18.27 PM

Thirdly, I put it all together up to the point of creating the local SQL Server.  Specifically:

  • Unit tests running

Screen Shot 2017-12-03 at 11.16.10 PM

  • SQL Server integration tests running

Screen Shot 2017-12-03 at 11.16.46 PM

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.

Stay tuned!

References

  1. https://medium.com/@reverentgeek/sql-server-running-on-a-mac-3efafda48861
  2. https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker
  3. https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker#connect-to-sql-server
  4. https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s