aboutsummaryrefslogtreecommitdiff
path: root/persistence/sessions_test.go
blob: df5e26d8d18f1e4217ccce5972598fb5c43cf098 (plain) (blame)
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
package persistence

import (
	"reflect"
	"testing"
)

func TestEmptySessionsMap(t *testing.T) {
	var sm SessionsMap
	emptySessionsMap(&sm)
	if sm.Sessions == nil {
		t.Error("Session map is still empty!")
	}
}

func TestNoEmptySessionsMap(t *testing.T) {
	var sm SessionsMap
	if sm.Sessions != nil {
		t.Error("Session map is not empty at start!")
	}
}

func TestSessionGet(t *testing.T) {
	session := Session{
		Timezone: "klsf",
	}
	tz, err := session.Get("timezone")
	if err != nil {
		t.Error(err)
	}
	if tz != "klsf" {
		t.Errorf("Wrong value from session: %s", tz)
	}
}

func TestSessionGetAbsent(t *testing.T) {
	session := Session{
		Timezone: "klsf",
	}
	_, err := session.Get("donkey")
	if err == nil {
		t.Error("There shouldn't be a donkey!")
	}
}

func TestSessionToMap(t *testing.T) {
	session := Session{
		Timezone:    "klsf",
		RawMessages: true,
		OOBMode:     true,
	}
	m := session.ToMap()
	sample := map[string]string{
		"timezone":    "klsf",
		"keeponline":  "false",
		"rawmessages": "true",
		"asciiarrows": "false",
		"oobmode":     "true",
		"carbons":     "false",
	}
	if !reflect.DeepEqual(m, sample) {
		t.Errorf("Map does not match the sample: %v", m)
	}
}

func TestSessionSet(t *testing.T) {
	session := Session{}
	tz, err := session.Set("timezone", "zaz")
	if err != nil {
		t.Error(err)
	}
	if tz != "zaz" {
		t.Errorf("Wrong set result: %s", tz)
	}
	if session.Timezone != "zaz" {
		t.Errorf("Wrong actual value in the session: %s", session.Timezone)
	}
}

func TestSessionSetAbsent(t *testing.T) {
	session := Session{}
	_, err := session.Set("donkey", "zaz")
	if err == nil {
		t.Error("There shouldn't come a donkey!")
	}
}