Skip to content

Testing

Adam Boutcher edited this page Aug 13, 2021 · 1 revision

If you want to test your updates with the current golang testing units, you can follow the guide below to run a full test process. Each test for Statping will run in MySQL, Postgres, and SQlite to make sure all database types work correctly.

Requirements

  • Golang (1.14.* or whichever go.mod states) GitHub go.mod Go version
    • go.rice Compiles all assets into golang file
  • Node (currently using 10.17)
    • Yarn
    • Sass

Basic Testing

The easiest way to run local unit testing by using SQLite and following the commands below...

  1. Make sure you have the requirements above. (being able to run rice)
  2. cd frontend && yarn Install npm packages for the frontend
  3. make compile Creates production version of Vue frontend and compiles all assets with rice.
  4. make install Will install statping locally so your system test CLI commands/flags.
  5. go test -v ./... Run all tests for Statping.

If you run Statping on port 8585, and then run yarn dev the debug Vue server will be running on port 8888.

Notifier Testing

To test the notifiers, you must include an environment variable that is set in each notifier test. If that notifier test environment variable is not set, it will be skipped.

Create Docker Databases

For more advanced testing, you can connect to a different type of database by using the DB_CONN environment variable. You can start them with Docker. Docker is available for Linux, Mac and Windows. You can download/install it by going to the Docker Installation site.

docker run -it -d \
   -p 3306:3306 \
   -env MYSQL_ROOT_PASSWORD=password123 \
   -env MYSQL_DATABASE=root mysql
docker run -it -d \
   -p 5432:5432 \
   -env POSTGRES_PASSWORD=password123 \
   -env POSTGRES_USER=root \
   -env POSTGRES_DB=root postgres

Once you have MySQL and Postgres running, you can begin the testing. SQLite database will automatically create a statping.db file and will delete after testing.

Run Tests

Insert the database environment variables to auto connect the the databases and run the normal test command: go test -v ./.... You'll see a verbose output of each test. If all tests pass, make a push request! 💃

DB_CONN=sqlite \
DB_DATABASE=root \
DB_USER=root \
DB_PASS=password123 \
DB_HOST=localhost \
go test -v ./...