diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-06 00:21:07 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-06 00:21:07 +0300 |
commit | cb8e7f4fef060e0b8c942ca8a4dbe92ff61a0a02 (patch) | |
tree | 72b026832f7e1ce26a7bd9e52b9fcdfdfa3fd173 /persistence | |
parent | ec1197f83cfa064ea8170d4b9f8a9ec021f88a87 (diff) |
Add tests for sessions
Diffstat (limited to 'persistence')
-rw-r--r-- | persistence/sessions_test.go | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/persistence/sessions_test.go b/persistence/sessions_test.go new file mode 100644 index 0000000..0968b53 --- /dev/null +++ b/persistence/sessions_test.go @@ -0,0 +1,79 @@ +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", + } + m := session.ToMap() + sample := map[string]string{ + "timezone": "klsf", + } + 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!") + } +} |