summaryrefslogtreecommitdiffstats
path: root/api/post_test.go
diff options
context:
space:
mode:
authorDebanshu Kundu <debanshu.kundu@joshtechnologygroup.com>2017-02-12 22:01:49 +0530
committerJoram Wilander <jwawilander@gmail.com>2017-02-12 11:31:49 -0500
commiteab15da32122ec421d22dbfb3ee2cd1844d07b5c (patch)
tree8d0f26e8c48db93ce0c9407c22c554a6fb4784dd /api/post_test.go
parent37222ec1b3364e1bd57ce268416edd1832be368c (diff)
downloadchat-eab15da32122ec421d22dbfb3ee2cd1844d07b5c.tar.gz
chat-eab15da32122ec421d22dbfb3ee2cd1844d07b5c.tar.bz2
chat-eab15da32122ec421d22dbfb3ee2cd1844d07b5c.zip
PLT-5455 Added caching for OG metadata of link preview. (#5361)
Diffstat (limited to 'api/post_test.go')
-rw-r--r--api/post_test.go32
1 files changed, 28 insertions, 4 deletions
diff --git a/api/post_test.go b/api/post_test.go
index c97da6f68..6556bb3b9 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -1306,7 +1306,11 @@ func TestGetOpenGraphMetadata(t *testing.T) {
th := Setup().InitBasic()
Client := th.BasicClient
+ ogDataCacheMissCount := 0
+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ ogDataCacheMissCount++
+
if r.URL.Path == "/og-data/" {
fmt.Fprintln(w, `
<html><head><meta property="og:type" content="article" />
@@ -1319,15 +1323,35 @@ func TestGetOpenGraphMetadata(t *testing.T) {
}
}))
- for _, data := range [](map[string]string){{"path": "/og-data/", "title": "Test Title"}, {"path": "/no-og-data/", "title": ""}} {
- res, err := Client.DoApiPost("/get_opengraph_metadata", fmt.Sprintf("{\"url\":\"%s\"}", ts.URL+data["path"]))
+ for _, data := range [](map[string]interface{}){
+ {"path": "/og-data/", "title": "Test Title", "cacheMissCount": 1},
+ {"path": "/no-og-data/", "title": "", "cacheMissCount": 2},
+
+ // Data should be cached for following
+ {"path": "/og-data/", "title": "Test Title", "cacheMissCount": 2},
+ {"path": "/no-og-data/", "title": "", "cacheMissCount": 2},
+ } {
+ res, err := Client.DoApiPost(
+ "/get_opengraph_metadata",
+ fmt.Sprintf("{\"url\":\"%s\"}", ts.URL+data["path"].(string)),
+ )
if err != nil {
t.Fatal(err)
}
ogData := model.StringInterfaceFromJson(res.Body)
- if strings.Compare(ogData["title"].(string), data["title"]) != 0 {
- t.Fatal(fmt.Sprintf("OG data title mismatch for path \"%s\". Expected title: \"%s\". Actual title: \"%s\"", data["path"], data["title"], ogData["title"]))
+ if strings.Compare(ogData["title"].(string), data["title"].(string)) != 0 {
+ t.Fatal(fmt.Sprintf(
+ "OG data title mismatch for path \"%s\". Expected title: \"%s\". Actual title: \"%s\"",
+ data["path"].(string), data["title"].(string), ogData["title"].(string),
+ ))
+ }
+
+ if ogDataCacheMissCount != data["cacheMissCount"].(int) {
+ t.Fatal(fmt.Sprintf(
+ "Cache miss count didn't match. Expected value %d. Actual value %d.",
+ data["cacheMissCount"].(int), ogDataCacheMissCount,
+ ))
}
}
}