lens @ 049b9acbd9635c206f5eeb01074b5d63803c4cd5

 1//go:build integration
 2
 3package sql
 4
 5import (
 6	"context"
 7	"os"
 8	"testing"
 9
10	"gorm.io/driver/sqlite"
11	"gorm.io/gorm"
12	"gorm.io/gorm/logger"
13)
14
15var (
16	ctx context.Context
17)
18
19func setup(t *testing.T) (*gorm.DB, func()) {
20	t.Helper()
21
22	ctx = context.Background()
23
24	file, err := os.CreateTemp("", "img_user_*.db")
25	if err != nil {
26		t.Fatalf("Error creating tmp error: %s", err.Error())
27	}
28
29	db, err := gorm.Open(sqlite.Open(file.Name()), &gorm.Config{
30		Logger: logger.Default.LogMode(logger.Info),
31	})
32	if err != nil {
33		t.Fatalf("Error openning db, error %s", err.Error())
34	}
35
36	err = Migrate(db)
37	if err != nil {
38		t.Fatalf("Error migrating db, error %s", err.Error())
39	}
40
41	return db, func() {
42		//nolint:errcheck
43		os.Remove(file.Name())
44	}
45}