-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard_test.go
103 lines (90 loc) · 2.54 KB
/
dashboard_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
package collider
import (
"errors"
"log"
"reflect"
"testing"
"time"
"github.com/tihtw/collider/collidertest"
)
func createNewRoomTable() *roomTable {
return newRoomTable(time.Second, "")
}
func verifyIntValue(t *testing.T, i interface{}, name string, expected int, tag string) {
v := reflect.ValueOf(i)
f := v.FieldByName(name)
if f.Interface() != expected {
log.Printf("interface=%#v", i)
t.Errorf("%s is %d, want %d", tag, f.Interface(), expected)
}
}
func verifyStringValue(t *testing.T, i interface{}, name string, expected string, tag string) {
v := reflect.ValueOf(i)
f := v.FieldByName(name)
if f.Interface() != expected {
log.Printf("interface=%#v", i)
t.Errorf("%s is %v, want %s", tag, f.Interface(), expected)
}
}
func verifyArrayLen(t *testing.T, i interface{}, name string, expected int, tag string) {
v := reflect.ValueOf(i)
f := v.FieldByName(name)
if f.Len() != expected {
log.Printf("interface=%#v", i)
t.Errorf("%s is %d, want %d", tag, f.Len(), expected)
}
}
func TestDashboardWsCount(t *testing.T) {
rt := createNewRoomTable()
db := newDashboard()
r := db.getReport(rt)
if r.OpenWs != 0 {
t.Errorf("db.getReport().OpenWs is %d, want 0", r.OpenWs)
}
if r.TotalWs != 0 {
t.Errorf("db.getReport().TotalWs is %d, want 0", r.TotalWs)
}
db.incrWs()
r = db.getReport(rt)
if r.OpenWs != 0 {
t.Errorf("db.getReport().OpenWs is %d, want 0", r.OpenWs)
}
if r.TotalWs != 1 {
t.Errorf("db.getReport().TotalWs is %d, want 1", r.TotalWs)
}
rt.register("r", "c", &collidertest.MockReadWriteCloser{Closed: false})
r = db.getReport(rt)
if r.OpenWs != 1 {
t.Errorf("db.getReport().OpenWs is %d, want 1", r.OpenWs)
}
}
func TestDashboardWsErr(t *testing.T) {
rt := createNewRoomTable()
db := newDashboard()
r := db.getReport(rt)
if r.WsErrs != 0 {
t.Errorf("db.getReport().WsErrs is %d, want 0", r.WsErrs)
}
db.onWsErr(errors.New("Fake error"))
r = db.getReport(rt)
if r.WsErrs != 1 {
t.Errorf("db.getReport().WsErrs is %d, want 1", r.WsErrs)
}
}
func TestDashboardHttpErr(t *testing.T) {
rt := createNewRoomTable()
db := newDashboard()
r := db.getReport(rt)
if r.HttpErrs != 0 {
t.Errorf("db.getReport().HttpErrs is %d, want 0", r.HttpErrs)
}
db.onHttpErr(errors.New("Fake error"))
r = db.getReport(rt)
if r.HttpErrs != 1 {
t.Errorf("db.getReport().HttpErrs is %d, want 1", r.HttpErrs)
}
}