Codebase list golang-github-go-kit-kit / c3c0b7a
metrics/circonus: move anonymous types into handlers Peter Bourgon 7 years ago
1 changed file(s) with 13 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
3434 value uint64
3535 )
3636 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
37 type postCounter struct {
38 Value uint64 `json:"_value"` // reverse-engineered
39 }
3740 m := map[string]postCounter{}
3841 json.NewDecoder(r.Body).Decode(&m)
3942 value = m[name].Value
7477 }
7578
7679 func TestGauge(t *testing.T) {
77 log.SetOutput(ioutil.Discard) // Circonus logs errors directly! Bad Circonus!
78 defer circonusgometrics.Reset() // Circonus has package global state! Bad Circonus!
80 log.SetOutput(ioutil.Discard)
81 defer circonusgometrics.Reset()
7982
8083 var (
8184 name = "test_gauge"
8285 value float64
8386 )
8487 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
88 type postGauge struct {
89 Value float64 `json:"_value"`
90 }
8591 m := map[string]postGauge{}
8692 json.NewDecoder(r.Body).Decode(&m)
8793 value = m[name].Value
114120 }
115121
116122 func TestHistogram(t *testing.T) {
117 log.SetOutput(ioutil.Discard) // Circonus logs errors directly! Bad Circonus!
118 defer circonusgometrics.Reset() // Circonus has package global state! Bad Circonus!
123 log.SetOutput(ioutil.Discard)
124 defer circonusgometrics.Reset()
119125
120126 var (
121127 name = "test_histogram"
123129 onceDecode sync.Once
124130 )
125131 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
132 type postHistogram struct {
133 Value []string `json:"_value"`
134 }
126135 onceDecode.Do(func() {
127136 m := map[string]postHistogram{}
128137 json.NewDecoder(r.Body).Decode(&m)
168177 time.Sleep(d / 10)
169178 }
170179 }
171
172 // These are reverse-engineered from the POST body.
173
174 type postCounter struct {
175 Value uint64 `json:"_value"`
176 }
177
178 type postGauge struct {
179 Value float64 `json:"_value"`
180 }
181
182 type postHistogram struct {
183 Value []string `json:"_value"`
184 }