github.com/bcampbell/scrapeomat@v0.0.0-20220820232205-23e64141c89e/store/sqlstore/sqlite3_test.go (about)

     1  package sqlstore
     2  
     3  import (
     4  	"database/sql"
     5  	"testing"
     6  
     7  	_ "github.com/mattn/go-sqlite3"
     8  )
     9  
    10  // Run our DB tests against an in-memory sqlite3 database.
    11  func TestSqlite3(t *testing.T) {
    12  
    13  	// NOTE: ":memory" won't work, as it only persists for single connection.
    14  	// Use shared cache to share the database across all connections in
    15  	// this process.
    16  	// see https://github.com/mattn/go-sqlite3#faq
    17  	db, err := sql.Open("sqlite3", "file::memory:?cache=shared")
    18  	if err != nil {
    19  		t.Errorf("New: %s\n", err)
    20  		return
    21  	}
    22  	db.SetConnMaxLifetime(-1)
    23  	db.SetMaxIdleConns(2) // should be default but may change in future
    24  	ss, err := NewFromDB("sqlite3", db)
    25  	if err != nil {
    26  		t.Errorf("New: %s\n", err)
    27  		return
    28  	}
    29  	performDBTests(t, ss)
    30  
    31  	defer ss.Close()
    32  }