1//go:build integration
2
3package sql
4
5import (
6 "testing"
7
8 "git.sr.ht/~gabrielgio/img/pkg/database/repository"
9 "git.sr.ht/~gabrielgio/img/pkg/testkit"
10)
11
12func TestSaveLoad(t *testing.T) {
13 db, tearDown := setup(t)
14 defer tearDown()
15
16 settingsRepository := NewSettingsRespository(db)
17
18 // testing saving once
19 want := &repository.Settings{
20 ShowMode: true,
21 ShowOwner: true,
22 }
23
24 err := settingsRepository.Save(ctx, want)
25 testkit.TestFatalError(t, "Save", err)
26
27 got, err := settingsRepository.Load(ctx)
28 testkit.TestFatalError(t, "Save", err)
29 testkit.TestValue(t, "Save", want, got)
30
31 // testing saving a second time
32 want = &repository.Settings{
33 ShowMode: false,
34 ShowOwner: false,
35 }
36
37 err = settingsRepository.Save(ctx, want)
38 testkit.TestFatalError(t, "Save", err)
39
40 got, err = settingsRepository.Load(ctx)
41 testkit.TestFatalError(t, "Save", err)
42 testkit.TestValue(t, "Save", want, got)
43}