-
Notifications
You must be signed in to change notification settings - Fork 19
/
stats_test.go
78 lines (63 loc) · 1.35 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package stats
import (
"os"
"testing"
"time"
. "gopkg.in/go-playground/assert.v1"
)
// NOTES:
// - Run "go test" to run tests
// - Run "gocov test | gocov report" to report on test converage by file
// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called
//
// or
//
// -- may be a good idea to change to output path to somewherelike /tmp
// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
//
func TestMain(m *testing.M) {
// setup
//
// setup server for tests
config := &ServerConfig{
Domain: "",
Port: 3010,
}
server, err := NewServer(config)
if err != nil {
panic(err)
}
go server.Run()
<-time.Tick(time.Second * 1)
os.Exit(m.Run())
// teardown
}
func TestClientSendingData(t *testing.T) {
serverConfig := &ServerConfig{
Domain: "",
Port: 3010,
}
localConfig := &ClientConfig{
Domain: "",
Port: 3011,
PollInterval: 1000,
LogHostInfo: true,
LogCPUInfo: true,
LogTotalCPUTimes: true,
LogPerCPUTimes: true,
LogMemory: true,
LogGoMemory: true,
}
client, err := NewClient(localConfig, serverConfig)
Equal(t, err, nil)
go client.Run()
ticker := time.NewTicker(time.Second * 1)
i := 0
for range ticker.C {
if i == 1 {
client.Stop()
return
}
i++
}
}