-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo_data_cache_test.go
41 lines (36 loc) · 1.24 KB
/
mongo_data_cache_test.go
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
package main
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/subosito/gotenv"
)
func TestSaveUserInfo(t *testing.T) {
gotenv.Apply(strings.NewReader("MONGO_URL=mongodb://localhost:27017"))
mdc := newMongoDataCache()
info := buildDummyUserInfo()
info.EtsyDetails.UserShopDetails.ShopName = "Whatay Shop"
info.EtsyDetails.UserShopDetails.ShopID = 54321
mdc.saveDetailsToCache(info.UserID, *info)
}
func TestGetUserInfo(t *testing.T) {
gotenv.Apply(strings.NewReader("MONGO_URL=mongodb://localhost:27017"))
mdc := newMongoDataCache()
info := buildDummyUserInfo()
info.EtsyDetails.UserShopDetails.ShopName = "Whatay Shop"
info.EtsyDetails.UserShopDetails.ShopID = 54321
mdc.saveDetailsToCache(info.UserID, *info)
savedInfo, err := mdc.getUserInfo(info.UserID)
assert.Nil(t, err)
assert.EqualValues(t, savedInfo, info)
}
func TestGetUserMap(t *testing.T) {
gotenv.Apply(strings.NewReader("MONGO_URL=mongodb://localhost:27017"))
mdc := newMongoDataCache()
info := buildDummyUserInfo()
info.EtsyDetails.UserShopDetails.ShopName = "Whatay Shop"
info.EtsyDetails.UserShopDetails.ShopID = 54321
mdc.saveDetailsToCache(info.UserID, *info)
usersMap := mdc.getUserMap()
assert.EqualValues(t, usersMap[info.UserID], *info)
}