-
Notifications
You must be signed in to change notification settings - Fork 0
/
doit_var_test.go
53 lines (45 loc) · 946 Bytes
/
doit_var_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
package main
import (
"os"
"testing"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
func TestVarDBBasic(t *testing.T) {
testDBFile := "_test_tmp/TestVarDBBasic.db"
//Remove testing file
os.Remove(testDBFile)
db, err := gorm.Open("sqlite3", testDBFile)
if err != nil {
t.Fatal(err)
}
db.DB()
db.CreateTable(&Var{})
testVar := &Var{Name: "Potato", Value: "Spud"}
db.NewRecord(testVar)
db.Create(&testVar)
db.Close()
}
func TestVarDBUpdate(t *testing.T) {
testDBFile := "_test_tmp/TestVarDBUpdate.db"
//Remove testing file
os.Remove(testDBFile)
db, err := gorm.Open("sqlite3", testDBFile)
if err != nil {
t.Fatal(err)
}
db.DB()
db.CreateTable(&Var{})
testVar := &Var{Name: "Potato", Value: "Spud"}
db.NewRecord(testVar)
db.Create(&testVar)
v := &Var{ID: testVar.ID}
db.First(&v)
if v.Name != "" {
v.Value = "Clock"
db.Save(&v)
} else {
t.Fatal("Unable to find document")
}
db.Close()
}