summaryrefslogtreecommitdiffstats
path: root/store/sql_post_store_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-12-20 09:41:04 -0500
committerenahum <nahumhbl@gmail.com>2016-12-20 11:41:04 -0300
commit148fd01b54776cf7814f2f2370c60e48058c48ec (patch)
treeb7c013faa87bb1c48144588838902297640f799e /store/sql_post_store_test.go
parent927eb659781579c6e5cdddafc5e1a02999cf4571 (diff)
downloadchat-148fd01b54776cf7814f2f2370c60e48058c48ec.tar.gz
chat-148fd01b54776cf7814f2f2370c60e48058c48ec.tar.bz2
chat-148fd01b54776cf7814f2f2370c60e48058c48ec.zip
Modifying post etag cache to apply to getPostsSince (#4837)
Diffstat (limited to 'store/sql_post_store_test.go')
-rw-r--r--store/sql_post_store_test.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go
index 30376fae5..3299d67e1 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -4,6 +4,7 @@
package store
import (
+ "fmt"
"strings"
"testing"
"time"
@@ -38,14 +39,14 @@ func TestPostStoreGet(t *testing.T) {
o1.Message = "a" + model.NewId() + "b"
etag1 := (<-store.Post().GetEtag(o1.ChannelId, false)).Data.(string)
- if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
+ if strings.Index(etag1, model.CurrentVersion+".") != 0 {
t.Fatal("Invalid Etag")
}
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
etag2 := (<-store.Post().GetEtag(o1.ChannelId, false)).Data.(string)
- if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 {
+ if strings.Index(etag2, fmt.Sprintf("%v.%v", model.CurrentVersion, o1.UpdateAt)) != 0 {
t.Fatal("Invalid Etag")
}
@@ -70,13 +71,13 @@ func TestGetEtagCache(t *testing.T) {
o1.Message = "a" + model.NewId() + "b"
etag1 := (<-store.Post().GetEtag(o1.ChannelId, true)).Data.(string)
- if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
+ if strings.Index(etag1, model.CurrentVersion+".") != 0 {
t.Fatal("Invalid Etag")
}
// This one should come from the cache
etag2 := (<-store.Post().GetEtag(o1.ChannelId, true)).Data.(string)
- if strings.Index(etag2, model.CurrentVersion+".0.") != 0 {
+ if strings.Index(etag2, model.CurrentVersion+".") != 0 {
t.Fatal("Invalid Etag")
}
@@ -84,15 +85,15 @@ func TestGetEtagCache(t *testing.T) {
// We have not invalidated the cache so this should be the same as above
etag3 := (<-store.Post().GetEtag(o1.ChannelId, true)).Data.(string)
- if strings.Index(etag3, model.CurrentVersion+".0.") != 0 {
+ if strings.Index(etag3, etag2) != 0 {
t.Fatal("Invalid Etag")
}
- store.Post().InvalidatePostEtagCache(o1.ChannelId)
+ store.Post().InvalidateLastPostTimeCache(o1.ChannelId)
// Invalidated cache so we should get a good result
etag4 := (<-store.Post().GetEtag(o1.ChannelId, true)).Data.(string)
- if strings.Index(etag4, model.CurrentVersion+"."+o1.Id) != 0 {
+ if strings.Index(etag4, fmt.Sprintf("%v.%v", model.CurrentVersion, o1.UpdateAt)) != 0 {
t.Fatal("Invalid Etag")
}
}
@@ -200,7 +201,7 @@ func TestPostStoreDelete(t *testing.T) {
o1.Message = "a" + model.NewId() + "b"
etag1 := (<-store.Post().GetEtag(o1.ChannelId, false)).Data.(string)
- if strings.Index(etag1, model.CurrentVersion+".0.") != 0 {
+ if strings.Index(etag1, model.CurrentVersion+".") != 0 {
t.Fatal("Invalid Etag")
}
@@ -224,7 +225,7 @@ func TestPostStoreDelete(t *testing.T) {
}
etag2 := (<-store.Post().GetEtag(o1.ChannelId, false)).Data.(string)
- if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 {
+ if strings.Index(etag2, model.CurrentVersion+".") != 0 {
t.Fatal("Invalid Etag")
}
}
@@ -680,7 +681,7 @@ func TestPostStoreGetPostsSince(t *testing.T) {
o5.RootId = o4.Id
o5 = (<-store.Post().Save(o5)).Data.(*model.Post)
- r1 := (<-store.Post().GetPostsSince(o1.ChannelId, o1.CreateAt)).Data.(*model.PostList)
+ r1 := (<-store.Post().GetPostsSince(o1.ChannelId, o1.CreateAt, false)).Data.(*model.PostList)
if r1.Order[0] != o5.Id {
t.Fatal("invalid order")
@@ -705,6 +706,12 @@ func TestPostStoreGetPostsSince(t *testing.T) {
if r1.Posts[o1.Id].Message != o1.Message {
t.Fatal("Missing parent")
}
+
+ r2 := (<-store.Post().GetPostsSince(o1.ChannelId, o5.UpdateAt, true)).Data.(*model.PostList)
+
+ if len(r2.Order) != 0 {
+ t.Fatal("wrong size ", len(r2.Posts))
+ }
}
func TestPostStoreSearch(t *testing.T) {