diff --git a/pkg/database/sql/main_test.go b/pkg/database/sql/main_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..c373740d66ac05e765ab5a4bb0e51ae9df8928e6
--- /dev/null
+++ b/pkg/database/sql/main_test.go
@@ -0,0 +1,45 @@
+//go:build integration
+
+package sql
+
+import (
+ "context"
+ "os"
+ "testing"
+
+ "gorm.io/driver/sqlite"
+ "gorm.io/gorm"
+ "gorm.io/gorm/logger"
+)
+
+var (
+ ctx context.Context
+)
+
+func setup(t *testing.T) (*gorm.DB, func()) {
+ t.Helper()
+
+ ctx = context.Background()
+
+ file, err := os.CreateTemp("", "img_user_*.db")
+ if err != nil {
+ t.Fatalf("Error creating tmp error: %s", err.Error())
+ }
+
+ db, err := gorm.Open(sqlite.Open(file.Name()), &gorm.Config{
+ Logger: logger.Default.LogMode(logger.Info),
+ })
+ if err != nil {
+ t.Fatalf("Error openning db, error %s", err.Error())
+ }
+
+ err = Migrate(db)
+ if err != nil {
+ t.Fatalf("Error migrating db, error %s", err.Error())
+ }
+
+ return db, func() {
+ //nolint:errcheck
+ os.Remove(file.Name())
+ }
+}
diff --git a/pkg/database/sql/settings_test.go b/pkg/database/sql/settings_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..f1c859dd0c89980f9349c863388488b75339b69f
--- /dev/null
+++ b/pkg/database/sql/settings_test.go
@@ -0,0 +1,43 @@
+//go:build integration
+
+package sql
+
+import (
+ "testing"
+
+ "git.sr.ht/~gabrielgio/img/pkg/database/repository"
+ "git.sr.ht/~gabrielgio/img/pkg/testkit"
+)
+
+func TestSaveLoad(t *testing.T) {
+ db, tearDown := setup(t)
+ defer tearDown()
+
+ settingsRepository := NewSettingsRespository(db)
+
+ // testing saving once
+ want := &repository.Settings{
+ ShowMode: true,
+ ShowOwner: true,
+ }
+
+ err := settingsRepository.Save(ctx, want)
+ testkit.TestFatalError(t, "Save", err)
+
+ got, err := settingsRepository.Load(ctx)
+ testkit.TestFatalError(t, "Save", err)
+ testkit.TestValue(t, "Save", want, got)
+
+ // testing saving a second time
+ want = &repository.Settings{
+ ShowMode: false,
+ ShowOwner: false,
+ }
+
+ err = settingsRepository.Save(ctx, want)
+ testkit.TestFatalError(t, "Save", err)
+
+ got, err = settingsRepository.Load(ctx)
+ testkit.TestFatalError(t, "Save", err)
+ testkit.TestValue(t, "Save", want, got)
+}
diff --git a/pkg/database/sql/user_test.go b/pkg/database/sql/user_test.go
index 01f6729bc00c576b97cc6bdf2fa45154e0b4eab8..db436767045e01cc9b20d03e3bee2576e01c6707 100644
--- a/pkg/database/sql/user_test.go
+++ b/pkg/database/sql/user_test.go
@@ -4,42 +4,12 @@ package sql
import (
"context"
- "os"
"testing"
"github.com/google/go-cmp/cmp"
- "gorm.io/driver/sqlite"
- "gorm.io/gorm"
- "gorm.io/gorm/logger"
"git.sr.ht/~gabrielgio/img/pkg/database/repository"
)
-
-func setup(t *testing.T) (*gorm.DB, func()) {
- t.Helper()
-
- file, err := os.CreateTemp("", "img_user_*.db")
- if err != nil {
- t.Fatalf("Error creating tmp error: %s", err.Error())
- }
-
- db, err := gorm.Open(sqlite.Open(file.Name()), &gorm.Config{
- Logger: logger.Default.LogMode(logger.Info),
- })
- if err != nil {
- t.Fatalf("Error openning db, error %s", err.Error())
- }
-
- err = Migrate(db)
- if err != nil {
- t.Fatalf("Error migrating db, error %s", err.Error())
- }
-
- return db, func() {
- //nolint:errcheck
- os.Remove(file.Name())
- }
-}
func TestCreate(t *testing.T) {
t.Parallel()