summaryrefslogtreecommitdiffstats
path: root/store/redis_test.go
blob: 11bd9ca6a030a1a96d554d5ee70834725a6b4fbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.

package store

import (
	"fmt"
	"github.com/mattermost/platform/model"
	"github.com/mattermost/platform/utils"
	"testing"
)

func TestRedis(t *testing.T) {
	utils.LoadConfig("config.json")

	c := RedisClient()

	if c == nil {
		t.Fatal("should have a valid redis connection")
	}

	pubsub := c.PubSub()
	defer pubsub.Close()

	m := model.NewMessage(model.NewId(), model.NewId(), model.NewId(), model.ACTION_TYPING)
	m.Add("RootId", model.NewId())

	err := pubsub.Subscribe(m.TeamId)
	if err != nil {
		t.Fatal(err)
	}

	// should be the subscribe success message
	// lets gobble that up
	if _, err := pubsub.Receive(); err != nil {
		t.Fatal(err)
	}

	PublishAndForget(m)

	fmt.Println("here1")

	if msg, err := pubsub.Receive(); err != nil {
		t.Fatal(err)
	} else {

		rmsg := GetMessageFromPayload(msg)

		if m.TeamId != rmsg.TeamId {
			t.Fatal("Ids do not match")
		}

		if m.Props["RootId"] != rmsg.Props["RootId"] {
			t.Fatal("Ids do not match")
		}
	}

	RedisClose()
}