-
Notifications
You must be signed in to change notification settings - Fork 0
/
getConfig_test.go
56 lines (44 loc) · 1.3 KB
/
getConfig_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pogifyapi
import (
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/alicebob/miniredis/v2"
"github.com/gin-gonic/gin"
)
func Test_server_getConfig(t *testing.T) {
mr, err := miniredis.Run()
defer mr.Close()
if err != nil {
t.Fatalf("MiniRedis error: %s", err)
}
os.Setenv("REDIS_URI", "redis://"+mr.Addr())
router := gin.New()
Server(router.Group("/"))
t.Run("test get on missing query", func(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/session/config", nil)
router.ServeHTTP(w, req)
if w.Code != 400 {
t.Errorf("getConfig didn't return 400 on empty query, instead: %#v", w.Code)
}
})
t.Run("test get on missing config", func(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/session/config?session=test", nil)
router.ServeHTTP(w, req)
if w.Code != 404 {
t.Errorf("getConfig didn't return 404 on empty query, instead: %#v", w.Code)
}
})
t.Run("test get on missing config", func(t *testing.T) {
mr.HSet("session:test:config", "RefreshInterval", "100")
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/session/config?session=test", nil)
router.ServeHTTP(w, req)
if w.Code != 200 {
t.Errorf("getConfig didn't return 404 on empty query, instead: %#v", w.Code)
}
})
}