forked from sentriz/gonic
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_test.go
52 lines (42 loc) · 993 Bytes
/
db_test.go
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
44
45
46
47
48
49
50
51
52
package db
import (
"io"
"log"
"math/rand"
"os"
"testing"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
log.SetOutput(io.Discard)
os.Exit(m.Run())
}
func TestGetSetting(t *testing.T) {
t.Parallel()
key := SettingKey(randKey())
value := "howdy"
testDB, err := NewMock()
if err != nil {
t.Fatalf("error creating db: %v", err)
}
if err := testDB.Migrate(MigrationContext{}); err != nil {
t.Fatalf("error migrating db: %v", err)
}
require.NoError(t, testDB.SetSetting(key, value))
actual, err := testDB.GetSetting(key)
require.NoError(t, err)
require.Equal(t, value, actual)
require.NoError(t, testDB.SetSetting(key, value))
actual, err = testDB.GetSetting(key)
require.NoError(t, err)
require.Equal(t, value, actual)
}
func randKey() string {
letters := []rune("abcdef0123456789")
b := make([]rune, 16)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}