Go Back

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