X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ffoundation%2Fapi%2Frevel%2Fsession%2Fsession_test.go;fp=src%2Ffoundation%2Fapi%2Frevel%2Fsession%2Fsession_test.go;h=6be1ce568363f77fc94df01990fa7dac475c3d1e;hb=1d1ee6961c93781e1187d8c7faa868da6b2f01f4;hp=0000000000000000000000000000000000000000;hpb=56dd5e0f2164b37b40ac1daa188ccc618b4cbd19;p=iec.git diff --git a/src/foundation/api/revel/session/session_test.go b/src/foundation/api/revel/session/session_test.go new file mode 100644 index 0000000..6be1ce5 --- /dev/null +++ b/src/foundation/api/revel/session/session_test.go @@ -0,0 +1,64 @@ +// Copyright (c) 2012-2018 The Revel Framework Authors, All rights reserved. +// Revel Framework source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package session_test + +import ( + "fmt" + "github.com/revel/revel" + "github.com/revel/revel/session" + "github.com/stretchr/testify/assert" + "testing" +) + +// test the commands +func TestSessionString(t *testing.T) { + session.InitSession(revel.RevelLog) + a := assert.New(t) + s := session.NewSession() + s.Set("happy", "day") + a.Equal("day", s.GetDefault("happy", nil, ""), fmt.Sprintf("Session Data %#v\n", s)) + +} + +func TestSessionStruct(t *testing.T) { + session.InitSession(revel.RevelLog) + a := assert.New(t) + s := session.NewSession() + setSharedDataTest(s) + a.Equal("test", s.GetDefault("happy.a.aa", nil, ""), fmt.Sprintf("Session Data %#v\n", s)) + + stringMap := s.Serialize() + s1 := session.NewSession() + s1.Load(stringMap) + testSharedData(s, s1, t, a) + +} + +func setSharedDataTest(s session.Session) { + data := struct { + A struct { + Aa string + } + B int + C string + D float32 + }{A: struct { + Aa string + }{Aa: "test"}, + B: 5, + C: "test", + D: -325.25} + s.Set("happy", data) +} +func testSharedData(s, s1 session.Session, t *testing.T, a *assert.Assertions) { + // Compress the session to a string + t.Logf("Original session %#v\n", s) + t.Logf("New built session %#v\n", s1) + data,err := s1.Get("happy.a.aa") + a.Nil(err,"Expected nil") + a.Equal("test", data, fmt.Sprintf("Session Data %#v\n", s)) + t.Logf("After test session %#v\n", s1) + +}