1
0
out-of-tree/daemon/db/db_test.go

32 lines
520 B
Go
Raw Normal View History

2024-02-20 13:25:31 +00:00
package db
import (
2024-02-26 08:55:27 +00:00
"database/sql"
2024-02-20 13:25:31 +00:00
"os"
"testing"
"github.com/stretchr/testify/assert"
)
2024-02-26 08:55:27 +00:00
func tmpdb(t *testing.T) (file *os.File, db *sql.DB) {
2024-02-20 13:25:31 +00:00
file, err := os.CreateTemp("", "temp-sqlite.db")
assert.Nil(t, err)
2024-02-26 08:55:27 +00:00
// defer os.Remove(file.Name())
2024-02-20 13:25:31 +00:00
2024-02-26 08:55:27 +00:00
db, err = OpenDatabase(file.Name())
2024-02-20 13:25:31 +00:00
assert.Nil(t, err)
2024-02-26 08:55:27 +00:00
// defer db.Close()
return
}
func TestOpenDatabase(t *testing.T) {
file, db := tmpdb(t)
defer os.Remove(file.Name())
2024-02-20 13:25:31 +00:00
db.Close()
2024-02-26 08:55:27 +00:00
db, err := OpenDatabase(file.Name())
2024-02-20 13:25:31 +00:00
assert.Nil(t, err)
db.Close()
}