diff options
author | Chris <ccbrown112@gmail.com> | 2017-09-25 09:11:25 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-09-25 10:11:25 -0400 |
commit | 49fe5fbf3db56fc466b8997b182ee135d7a4365d (patch) | |
tree | 1252fea09aa3ce899e2e8edb1fb7b42900f50bca /store/sql_session_store_test.go | |
parent | b2c5b97601b61f5748b46e4e386134203111ebb0 (diff) | |
download | chat-49fe5fbf3db56fc466b8997b182ee135d7a4365d.tar.gz chat-49fe5fbf3db56fc466b8997b182ee135d7a4365d.tar.bz2 chat-49fe5fbf3db56fc466b8997b182ee135d7a4365d.zip |
Move sql store code into store/sqlstore package (#7502)
* move sql store code into store/sqlstore package
* move non-sql constants back up to store
* fix api test
* derp
Diffstat (limited to 'store/sql_session_store_test.go')
-rw-r--r-- | store/sql_session_store_test.go | 257 |
1 files changed, 0 insertions, 257 deletions
diff --git a/store/sql_session_store_test.go b/store/sql_session_store_test.go deleted file mode 100644 index 3db1cbba2..000000000 --- a/store/sql_session_store_test.go +++ /dev/null @@ -1,257 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package store - -import ( - "testing" - - "github.com/mattermost/mattermost-server/model" -) - -func TestSessionStoreSave(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - - if err := (<-store.Session().Save(&s1)).Err; err != nil { - t.Fatal(err) - } -} - -func TestSessionGet(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - Must(store.Session().Save(&s1)) - - s2 := model.Session{} - s2.UserId = s1.UserId - Must(store.Session().Save(&s2)) - - s3 := model.Session{} - s3.UserId = s1.UserId - s3.ExpiresAt = 1 - Must(store.Session().Save(&s3)) - - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { - t.Fatal(rs1.Err) - } else { - if rs1.Data.(*model.Session).Id != s1.Id { - t.Fatal("should match") - } - } - - if rs2 := (<-store.Session().GetSessions(s1.UserId)); rs2.Err != nil { - t.Fatal(rs2.Err) - } else { - if len(rs2.Data.([]*model.Session)) != 2 { - t.Fatal("should match len") - } - } -} - -func TestSessionGetWithDeviceId(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - s1.ExpiresAt = model.GetMillis() + 10000 - Must(store.Session().Save(&s1)) - - s2 := model.Session{} - s2.UserId = s1.UserId - s2.DeviceId = model.NewId() - s2.ExpiresAt = model.GetMillis() + 10000 - Must(store.Session().Save(&s2)) - - s3 := model.Session{} - s3.UserId = s1.UserId - s3.ExpiresAt = 1 - s3.DeviceId = model.NewId() - Must(store.Session().Save(&s3)) - - if rs1 := (<-store.Session().GetSessionsWithActiveDeviceIds(s1.UserId)); rs1.Err != nil { - t.Fatal(rs1.Err) - } else { - if len(rs1.Data.([]*model.Session)) != 1 { - t.Fatal("should match len") - } - } -} - -func TestSessionRemove(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - Must(store.Session().Save(&s1)) - - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { - t.Fatal(rs1.Err) - } else { - if rs1.Data.(*model.Session).Id != s1.Id { - t.Fatal("should match") - } - } - - Must(store.Session().Remove(s1.Id)) - - if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil { - t.Fatal("should have been removed") - } -} - -func TestSessionRemoveAll(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - Must(store.Session().Save(&s1)) - - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { - t.Fatal(rs1.Err) - } else { - if rs1.Data.(*model.Session).Id != s1.Id { - t.Fatal("should match") - } - } - - Must(store.Session().RemoveAllSessions()) - - if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil { - t.Fatal("should have been removed") - } -} - -func TestSessionRemoveByUser(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - Must(store.Session().Save(&s1)) - - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { - t.Fatal(rs1.Err) - } else { - if rs1.Data.(*model.Session).Id != s1.Id { - t.Fatal("should match") - } - } - - Must(store.Session().PermanentDeleteSessionsByUser(s1.UserId)) - - if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil { - t.Fatal("should have been removed") - } -} - -func TestSessionRemoveToken(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - Must(store.Session().Save(&s1)) - - if rs1 := (<-store.Session().Get(s1.Id)); rs1.Err != nil { - t.Fatal(rs1.Err) - } else { - if rs1.Data.(*model.Session).Id != s1.Id { - t.Fatal("should match") - } - } - - Must(store.Session().Remove(s1.Token)) - - if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil { - t.Fatal("should have been removed") - } - - if rs3 := (<-store.Session().GetSessions(s1.UserId)); rs3.Err != nil { - t.Fatal(rs3.Err) - } else { - if len(rs3.Data.([]*model.Session)) != 0 { - t.Fatal("should match len") - } - } -} - -func TestSessionUpdateDeviceId(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - Must(store.Session().Save(&s1)) - - if rs1 := (<-store.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt)); rs1.Err != nil { - t.Fatal(rs1.Err) - } - - s2 := model.Session{} - s2.UserId = model.NewId() - Must(store.Session().Save(&s2)) - - if rs2 := (<-store.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE+":1234567890", s1.ExpiresAt)); rs2.Err != nil { - t.Fatal(rs2.Err) - } -} - -func TestSessionUpdateDeviceId2(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - Must(store.Session().Save(&s1)) - - if rs1 := (<-store.Session().UpdateDeviceId(s1.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs1.Err != nil { - t.Fatal(rs1.Err) - } - - s2 := model.Session{} - s2.UserId = model.NewId() - Must(store.Session().Save(&s2)) - - if rs2 := (<-store.Session().UpdateDeviceId(s2.Id, model.PUSH_NOTIFY_APPLE_REACT_NATIVE+":1234567890", s1.ExpiresAt)); rs2.Err != nil { - t.Fatal(rs2.Err) - } -} - -func TestSessionStoreUpdateLastActivityAt(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - Must(store.Session().Save(&s1)) - - if err := (<-store.Session().UpdateLastActivityAt(s1.Id, 1234567890)).Err; err != nil { - t.Fatal(err) - } - - if r1 := <-store.Session().Get(s1.Id); r1.Err != nil { - t.Fatal(r1.Err) - } else { - if r1.Data.(*model.Session).LastActivityAt != 1234567890 { - t.Fatal("LastActivityAt not updated correctly") - } - } - -} - -func TestSessionCount(t *testing.T) { - Setup() - - s1 := model.Session{} - s1.UserId = model.NewId() - s1.ExpiresAt = model.GetMillis() + 100000 - Must(store.Session().Save(&s1)) - - if r1 := <-store.Session().AnalyticsSessionCount(); r1.Err != nil { - t.Fatal(r1.Err) - } else { - if r1.Data.(int64) == 0 { - t.Fatal("should have at least 1 session") - } - } -} |