-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite_test.go
More file actions
41 lines (36 loc) · 843 Bytes
/
Copy pathsqlite_test.go
File metadata and controls
41 lines (36 loc) · 843 Bytes
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
package main
import (
"testing"
)
func connectToTestDb() *connection {
c := connect(":memory:")
c.createTable()
return c
}
func TestInsertNewRecord(t *testing.T) {
c := connectToTestDb()
res := c.insertNewRecord()
id, _ := res.LastInsertId()
if id != 1 {
t.Error("Something went wrong when inserting a new record.")
}
}
func TestUpdateRecord(t *testing.T) {
c := connectToTestDb()
c.insertNewRecord()
rec := c.getLastRecord()
res := c.updateRecord(rec)
id, _ := res.LastInsertId()
if id != 1 {
t.Error("Something went wrong when updating a record.")
}
}
func TestUpdateRecordWithEmptyDatabase(t *testing.T) {
c := connectToTestDb()
rec := c.getLastRecord()
res := c.updateRecord(rec)
id, _ := res.LastInsertId()
if id != 0 {
t.Error("Did not expect to get id when no records are present in the database.")
}
}