This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
forked from minotar/imgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus_test.go
80 lines (71 loc) · 2.03 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
package main
import (
"runtime"
"testing"
"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.HitCache()
runtime.Gosched()
if stats.info.CacheHits != 1 {
t.Fatalf("CacheHits not 1, was %d", stats.info.CacheHits)
}
}
func TestStatusHandleMessageCacheMiss(t *testing.T) {
stats.MissCache()
runtime.Gosched()
if stats.info.CacheMisses != 1 {
t.Fatalf("CacheMisses not 1, was %d", stats.info.CacheMisses)
}
}
func TestStatusHandleMessageRequested(t *testing.T) {
stats.Requested("test")
runtime.Gosched()
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")
runtime.Gosched()
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 TestStatusHandleMessageErrored(t *testing.T) {
stats.Errored("test")
runtime.Gosched()
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")
runtime.Gosched()
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"])
}
}