forked from minotar/imgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus_test.go
126 lines (113 loc) · 3.78 KB
/
status_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"testing"
"time"
"github.com/op/go-logging"
)
func testSetupStatus() *StashingWriter {
sw := new(StashingWriter)
logBackend := logging.NewLogBackend(sw, "", 0)
stats = MakeStatsCollector()
setupConfig()
setupLog(logBackend)
setupCache()
return sw
}
func TestStatusHandleMessageCacheHit(t *testing.T) {
stats = MakeStatsCollector()
stats.CacheUUID("hit")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.CacheUUID.Hits != 1 {
t.Fatalf("CacheUUID.Hits not 1, was %d", stats.info.CacheUUID.Hits)
}
}
func TestStatusHandleMessageCacheFresh(t *testing.T) {
stats = MakeStatsCollector()
stats.CacheUUID("fresh")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.CacheUUID.FreshHits != 1 {
t.Fatalf("CacheUUID.FreshHits not 1, was %d", stats.info.CacheUUID.FreshHits)
}
}
func TestStatusHandleMessageCacheStale(t *testing.T) {
stats = MakeStatsCollector()
stats.CacheUUID("stale")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.CacheUUID.StaleHits != 1 {
t.Fatalf("CacheUUID.StaleHits not 1, was %d", stats.info.CacheUUID.StaleHits)
}
}
func TestStatusHandleMessageCacheMiss(t *testing.T) {
stats = MakeStatsCollector()
stats.CacheUUID("miss")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.CacheUUID.Misses != 1 {
t.Fatalf("CacheUUID.Misses not 1, was %d", stats.info.CacheUUID.Misses)
}
}
func TestStatusHandleMessageRequested(t *testing.T) {
stats = MakeStatsCollector()
stats.Requested("test")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.Requested["test"] != 1 {
t.Fatalf("Requested[\"test\"] not 1, was %d", stats.info.Requested["test"])
}
stats.Requested("test")
stats.Requested("test")
stats.Requested("bacon")
stats.Requested("fromage")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.Requested["test"] != 3 {
t.Fatalf("Requested[\"test\"] not 3, was %d", stats.info.Requested["test"])
}
if stats.info.Requested["bacon"] != 1 {
t.Fatalf("Requested[\"bacon\"] not 1, was %d", stats.info.Requested["bacon"])
}
if stats.info.Requested["fromage"] != 1 {
t.Fatalf("Requested[\"fromage\"] not 1, was %d", stats.info.Requested["fromage"])
}
}
func TestStatusHandleMessageUserRequested(t *testing.T) {
stats = MakeStatsCollector()
stats.UserRequested("test")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.UserRequested["test"] != 1 {
t.Fatalf("UserRequested[\"test\"] not 1, was %d", stats.info.UserRequested["test"])
}
stats.UserRequested("test")
stats.UserRequested("test")
stats.UserRequested("bacon")
stats.UserRequested("fromage")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.UserRequested["test"] != 3 {
t.Fatalf("UserRequested[\"test\"] not 3, was %d", stats.info.UserRequested["test"])
}
if stats.info.UserRequested["bacon"] != 1 {
t.Fatalf("UserRequested[\"bacon\"] not 1, was %d", stats.info.UserRequested["bacon"])
}
if stats.info.UserRequested["fromage"] != 1 {
t.Fatalf("UserRequested[\"fromage\"] not 1, was %d", stats.info.UserRequested["fromage"])
}
}
func TestStatusHandleMessageErrored(t *testing.T) {
stats = MakeStatsCollector()
stats.Errored("test")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.Errored["test"] != 1 {
t.Fatalf("Errored[\"test\"] not 1, was %d", stats.info.Errored["test"])
}
stats.Errored("test")
stats.Errored("test")
stats.Errored("bacon")
stats.Errored("fromage")
time.Sleep(time.Duration(1) * time.Millisecond)
if stats.info.Errored["test"] != 3 {
t.Fatalf("Errored[\"test\"] not 3, was %d", stats.info.Errored["test"])
}
if stats.info.Errored["bacon"] != 1 {
t.Fatalf("Errored[\"bacon\"] not 1, was %d", stats.info.Errored["bacon"])
}
if stats.info.Errored["fromage"] != 1 {
t.Fatalf("Errored[\"fromage\"] not 1, was %d", stats.info.Errored["fromage"])
}
}