/
stats_test.go
39 lines (34 loc) · 970 Bytes
/
stats_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
package main
import (
"github.com/amundi/escheck/eslog"
"github.com/amundi/escheck/worker"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func initStatsForTests1() {
stats.statsMap = make(map[string]queryStats)
stats.statsMap["Test"] = queryStats{true, false, 3, 0, "Yesterday"}
stats.statsMap["Test"] = queryStats{true, false, 3, 0, "Yesterday"}
}
func initStatsForTests2() {
stats.statsMap = make(map[string]queryStats)
stats.statsMap["Test"] = queryStats{true, true, 3, 0, "Now"}
}
func Test_DisplayPage(t *testing.T) {
eslog.InitSilent()
ts := httptest.NewServer(http.HandlerFunc(collectorDisplay))
defer ts.Close()
initStatsForTests1()
worker.StartDispatcher(32)
res, err := http.Get(ts.URL)
assert.Nil(t, err)
page, err := ioutil.ReadAll(res.Body)
res.Body.Close()
assert.Nil(t, err)
expected := formatQueriesForLayout()
assert.Equal(t, expected, string(page))
worker.StopAllWorkers(32)
}