File: stathat_test.go

package info (click to toggle)
golang-github-stathat-go 0.0~git20130314.0.01d012b-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 96 kB
  • ctags: 79
  • sloc: makefile: 2
file content (202 lines) | stat: -rw-r--r-- 4,193 bytes parent folder | download | duplicates (4)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright (C) 2012 Numerotron Inc.
// Use of this source code is governed by an MIT-style license
// that can be found in the LICENSE file.

package stathat

import (
	"testing"
)

func TestNewEZStatCount(t *testing.T) {
	setTesting()
	x := newEZStatCount("abc", "pc@pc.com", 1)
	if x == nil {
		t.Fatalf("expected a StatReport object")
	}
	if x.statType != kcounter {
		t.Errorf("expected counter")
	}
	if x.apiType != ez {
		t.Errorf("expected EZ api")
	}
	if x.StatKey != "abc" {
		t.Errorf("expected abc")
	}
	if x.UserKey != "pc@pc.com" {
		t.Errorf("expected pc@pc.com")
	}
	if x.Value != 1.0 {
		t.Errorf("expected 1.0")
	}
	if x.Timestamp != 0 {
		t.Errorf("expected 0")
	}
}

func TestNewEZStatValue(t *testing.T) {
	setTesting()
	x := newEZStatValue("abc", "pc@pc.com", 3.14159)
	if x == nil {
		t.Fatalf("expected a StatReport object")
	}
	if x.statType != kvalue {
		t.Errorf("expected value")
	}
	if x.apiType != ez {
		t.Errorf("expected EZ api")
	}
	if x.StatKey != "abc" {
		t.Errorf("expected abc")
	}
	if x.UserKey != "pc@pc.com" {
		t.Errorf("expected pc@pc.com")
	}
	if x.Value != 3.14159 {
		t.Errorf("expected 3.14159")
	}
}

func TestNewClassicStatCount(t *testing.T) {
	setTesting()
	x := newClassicStatCount("statkey", "userkey", 1)
	if x == nil {
		t.Fatalf("expected a StatReport object")
	}
	if x.statType != kcounter {
		t.Errorf("expected counter")
	}
	if x.apiType != classic {
		t.Errorf("expected CLASSIC api")
	}
	if x.StatKey != "statkey" {
		t.Errorf("expected statkey")
	}
	if x.UserKey != "userkey" {
		t.Errorf("expected userkey")
	}
	if x.Value != 1.0 {
		t.Errorf("expected 1.0")
	}
	if x.Timestamp != 0 {
		t.Errorf("expected 0")
	}
}

func TestNewClassicStatValue(t *testing.T) {
	setTesting()
	x := newClassicStatValue("statkey", "userkey", 2.28)
	if x == nil {
		t.Fatalf("expected a StatReport object")
	}
	if x.statType != kvalue {
		t.Errorf("expected value")
	}
	if x.apiType != classic {
		t.Errorf("expected CLASSIC api")
	}
	if x.StatKey != "statkey" {
		t.Errorf("expected statkey")
	}
	if x.UserKey != "userkey" {
		t.Errorf("expected userkey")
	}
	if x.Value != 2.28 {
		t.Errorf("expected 2.28")
	}
}

func TestURLValues(t *testing.T) {
	setTesting()
	x := newEZStatCount("abc", "pc@pc.com", 1)
	v := x.values()
	if v == nil {
		t.Fatalf("expected url values")
	}
	if v.Get("stat") != "abc" {
		t.Errorf("expected abc")
	}
	if v.Get("ezkey") != "pc@pc.com" {
		t.Errorf("expected pc@pc.com")
	}
	if v.Get("count") != "1" {
		t.Errorf("expected count of 1")
	}

	y := newEZStatValue("abc", "pc@pc.com", 3.14159)
	v = y.values()
	if v == nil {
		t.Fatalf("expected url values")
	}
	if v.Get("stat") != "abc" {
		t.Errorf("expected abc")
	}
	if v.Get("ezkey") != "pc@pc.com" {
		t.Errorf("expected pc@pc.com")
	}
	if v.Get("value") != "3.14159" {
		t.Errorf("expected value of 3.14159")
	}

	a := newClassicStatCount("statkey", "userkey", 1)
	v = a.values()
	if v == nil {
		t.Fatalf("expected url values")
	}
	if v.Get("key") != "statkey" {
		t.Errorf("expected statkey")
	}
	if v.Get("ukey") != "userkey" {
		t.Errorf("expected userkey")
	}
	if v.Get("count") != "1" {
		t.Errorf("expected count of 1")
	}

	b := newClassicStatValue("statkey", "userkey", 2.28)
	v = b.values()
	if v == nil {
		t.Fatalf("expected url values")
	}
	if v.Get("key") != "statkey" {
		t.Errorf("expected statkey")
	}
	if v.Get("ukey") != "userkey" {
		t.Errorf("expected userkey")
	}
	if v.Get("value") != "2.28" {
		t.Errorf("expected value of 2.28")
	}
}

func TestPaths(t *testing.T) {
	if ez.path(kcounter) != "/ez" {
		t.Errorf("expected /ez")
	}
	if ez.path(kvalue) != "/ez" {
		t.Errorf("expected /ez")
	}
	if classic.path(kcounter) != "/c" {
		t.Errorf("expected /c")
	}
	if classic.path(kvalue) != "/v" {
		t.Errorf("expected /v")
	}

	x := newEZStatCount("abc", "pc@pc.com", 1)
	if x.path() != "/ez" {
		t.Errorf("expected /ez")
	}
	y := newEZStatValue("abc", "pc@pc.com", 3.14159)
	if y.path() != "/ez" {
		t.Errorf("expected /ez")
	}
	a := newClassicStatCount("statkey", "userkey", 1)
	if a.path() != "/c" {
		t.Errorf("expected /c")
	}
	b := newClassicStatValue("statkey", "userkey", 2.28)
	if b.path() != "/v" {
		t.Errorf("expected /v")
	}
}