Solution: Databases
See the solution to creating a helper function to test a function that requires data from a database.
We'll cover the following...
Solution explanation
In the pomodoro_test.go
file in the setup
function, we start by creating a temporary database file:
t.Helper()
tf, err := ioutil.TempFile("", "pomo")
if err != nil {
t.Fatal(err)
}
tf.Close()
We then open a DB connection to the SQLite database. If the connection cannot be made due to some error, the relevant message is thrown and the program is ended:
dbRepo, err := repository.NewSQLite3Repo(tf.Name())
if
...