-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlite_test.go
62 lines (56 loc) · 1.31 KB
/
sqlite_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
53
54
55
56
57
58
59
60
61
62
package tt
import (
"errors"
"testing"
"time"
"github.com/google/uuid"
)
func testDb(t *testing.T) DB {
db, err := NewSQLite(":memory:")
if err != nil {
t.Fatalf("unable to create in-memory database: %s", err.Error())
}
return db
}
func TestSaveValidTimer(t *testing.T) {
db := testDb(t)
err := db.SaveTimer(Timer{
ID: uuid.Must(uuid.NewRandom()).String(),
Start: time.Now(),
Stop: nil,
Project: "test",
Task: "test",
Tags: []string{"a", "b"},
})
if err != nil {
t.Fatalf("expected nil error but got '%s'", err.Error())
}
}
func TestSaveInvalidTimerEmptyProject(t *testing.T) {
db := testDb(t)
err := db.SaveTimer(Timer{
ID: uuid.Must(uuid.NewRandom()).String(),
Start: time.Now(),
Stop: nil,
Project: "",
Task: "test",
Tags: []string{"a", "b"},
})
if err == nil {
t.Fatal("expected non-nil error but got nil")
}
if !errors.Is(err, ErrInvalidTimer) {
t.Fatalf("expected error to contain '%s', but got '%s'", ErrInvalidTimer, err.Error())
}
}
func TestGetTimerNotFound(t *testing.T) {
db := testDb(t)
var timer Timer
err := db.GetTimer(EmptyFilter, OrderBy{}, &timer)
if err == nil {
t.Fatal("expected error but got nil")
}
if !errors.Is(err, ErrNotFound) {
t.Fatalf("expected error to contain '%s', but got '%s'", ErrNotFound, err.Error())
}
}