-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_sqlite3_test.go
113 lines (96 loc) · 2.29 KB
/
session_sqlite3_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package goserver
import (
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Session Repo powered by sqlite3", func() {
var (
db *sqlx.DB
err error
)
BeforeEach(func() {
db, err = sqlx.Open("sqlite3", "dummy.db")
Expect(err).To(BeNil())
//db.Query(".read db_setup.sql")
})
AfterEach(func() {
db.Close()
})
Describe("Creating a session repo", func() {
It("should return no error", func() {
_, err := NewSessionRepoSqlite3(db)
Expect(err).To(BeNil())
})
})
Context("Given an open repo", func() {
var (
s *Session
repo *SessionRepoSqlite3
)
BeforeEach(func() {
repo, err = NewSessionRepoSqlite3(db)
Expect(err).To(BeNil())
s = &Session{
UserID: 41,
Token: "stupid",
Origin: "nowhere",
Expires: "Always",
}
})
AfterEach(func() {
_, err = db.Exec("DELETE FROM sessions")
Expect(err).To(BeNil())
_, err = db.Exec("delete from sqlite_sequence where name='sessions';")
Expect(err).To(BeNil())
})
Describe("Creating a session", func() {
It("should create a good session", func() {
var ss []*Session
err = repo.Create(s)
Expect(err).To(BeNil())
err = db.Select(&ss, "SELECT * FROM sessions")
Expect(err).To(BeNil())
Expect(len(ss)).To(Equal(1))
s.ID = 1
Expect(ss[0]).To(Equal(s))
})
})
Context("given an existing session", func() {
var (
ss []*Session
)
JustBeforeEach(func() {
err = repo.Create(s)
Expect(err).To(BeNil())
Expect(s.ID).To(Equal(1))
})
Describe("Deleting a session", func() {
It("Should delete", func() {
err = repo.DeleteByToken(s)
Expect(err).To(BeNil())
err = db.Select(&ss, "SELECT * FROM sessions")
Expect(err).To(BeNil())
Expect(len(ss)).To(Equal(0))
})
})
Describe("Retrieve a session", func() {
It("should get back the existing session by ID", func() {
uut := &Session{ID: 1}
err = repo.GetByID(uut)
Expect(err).To(BeNil())
s.ID = 1
Expect(uut).To(Equal(s))
})
It("should get back the existing session", func() {
uut := &Session{Token: "stupid"}
err = repo.GetByToken(uut)
Expect(err).To(BeNil())
s.ID = 1
Expect(uut).To(Equal(s))
})
})
})
})
})