aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/sql/settings_test.go
blob: f1c859dd0c89980f9349c863388488b75339b69f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
}