💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Gemigit › files › 02cb454a269d400c06533ebd33… captured on 2023-05-24 at 18:17:45. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
0 package db
1
2 import (
3 "testing"
4 "gemigit/test"
5 )
6
7 func TestCreateSession(t *testing.T) {
8
9 initDB(t)
10
11 user, signature := createUserAndSession(t)
12 test.IsNotNil(t, user.CreateSession(signature),
13 "should not be able to add the same signature")
14 }
15
16 func TestDisconnect(t *testing.T) {
17
18 initDB(t)
19
20 user, signature := createUserAndSession(t)
21
22 test.IsNil(t, user.Disconnect(signature))
23 test.IsNotNil(t, user.Disconnect(signature),
24 "should be already disconnected")
25 }
26
27 func TestGetSessionsCount(t *testing.T) {
28
29 initDB(t)
30
31 user, _ := createUserAndSession(t)
32
33 count, err := user.GetSessionsCount()
34 test.IsNil(t, err)
35 test.IsEqual(t, count, 1)
36
37 test.IsNil(t, user.CreateSession("new_signature"))
38
39 count, err = user.GetSessionsCount()
40 test.IsNil(t, err)
41 test.IsEqual(t, count, 2)
42
43 user.ID = -1
44
45 count, err = user.GetSessionsCount()
46 test.IsNil(t, err)
47 test.IsEqual(t, count, 0)
48 }
49
50 func TestDisconnectAll(t *testing.T) {
51
52 initDB(t)
53
54 user, signature := createUserAndSession(t)
55 test.IsNil(t, user.CreateSession(signature + "b"))
56 test.IsNotNil(t, user.DisconnectAll(signature + "a"),
57 "should return invalid signature")
58 test.IsNil(t, user.DisconnectAll(signature))
59 }
60