Exercise: Databases
Test your coding skills on persisting data in SQLite.
We'll cover the following
Challenge
In this exercise, your challenge is to create a helper function to test a function that requires data from a database.
Problem statement
You can use helper functions to instantiate and populate a temporary database to assist with testing parts of your code that require data from a database.
Coding challenge
Create a helper function to set up a temporary database to assist with testing the function pomodoro.RangeSummary
. We’ll provide the test function. You need to define the setup
function to create and populate a database, ensuring all tests in the test function execute successfully. Your setup
function should return an instance of a pomodoro.Repository
type so tests can access the database, as well as a cleanup function to delete the database file at the end of the test execution.
Here’s the test function your setup
function needs to support, which is already added in interval_test.go
file:
Get hands-on with 1400+ tech skills courses.