Search⌘ K
AI Features

Testing the Repository with SQLite

Explore how to implement and test the SQLite repository in a Go command-line application. Learn to use build tags for repository selection, create temporary files for database testing, and verify functionality by executing tests with different backends.

We wrote tests for the pomodoro package using a helper function getRepo() to obtain the repository. At that time, only the inMemory repository was available. Now that we’ve added the sqlite3 repository, we’ll provide an alternative version of this function that returns the new repository. We can control when to use each by applying build tags.

Updating the sqlite3_test.go file

We update the sqlite3_test.go file ...