86 lines
1.6 KiB
Go
86 lines
1.6 KiB
Go
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,
|
|
MUC: true,
|
|
}
|
|
m := session.ToMap()
|
|
sample := map[string]string{
|
|
"timezone": "klsf",
|
|
"keeponline": "false",
|
|
"muc": "true",
|
|
"rawmessages": "true",
|
|
"asciiarrows": "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!")
|
|
}
|
|
}
|