github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/model/session_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "strings" 8 "testing" 9 "time" 10 ) 11 12 func TestSessionJson(t *testing.T) { 13 session := Session{} 14 session.PreSave() 15 json := session.ToJson() 16 rsession := SessionFromJson(strings.NewReader(json)) 17 18 if rsession.Id != session.Id { 19 t.Fatal("Ids do not match") 20 } 21 22 session.Sanitize() 23 24 if session.IsExpired() { 25 t.Fatal("Shouldn't expire") 26 } 27 28 session.ExpiresAt = GetMillis() 29 time.Sleep(10 * time.Millisecond) 30 if !session.IsExpired() { 31 t.Fatal("Should expire") 32 } 33 34 session.SetExpireInDays(10) 35 }