1 // Copyright (c) 2012-2018 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
9 "github.com/revel/revel"
10 "github.com/revel/revel/session"
11 "github.com/stretchr/testify/assert"
16 func TestSessionString(t *testing.T) {
17 session.InitSession(revel.RevelLog)
19 s := session.NewSession()
21 a.Equal("day", s.GetDefault("happy", nil, ""), fmt.Sprintf("Session Data %#v\n", s))
25 func TestSessionStruct(t *testing.T) {
26 session.InitSession(revel.RevelLog)
28 s := session.NewSession()
30 a.Equal("test", s.GetDefault("happy.a.aa", nil, ""), fmt.Sprintf("Session Data %#v\n", s))
32 stringMap := s.Serialize()
33 s1 := session.NewSession()
35 testSharedData(s, s1, t, a)
39 func setSharedDataTest(s session.Session) {
55 func testSharedData(s, s1 session.Session, t *testing.T, a *assert.Assertions) {
56 // Compress the session to a string
57 t.Logf("Original session %#v\n", s)
58 t.Logf("New built session %#v\n", s1)
59 data,err := s1.Get("happy.a.aa")
60 a.Nil(err,"Expected nil")
61 a.Equal("test", data, fmt.Sprintf("Session Data %#v\n", s))
62 t.Logf("After test session %#v\n", s1)