metrics/circonus: move anonymous types into handlers
Peter Bourgon
7 years ago
34 | 34 | value uint64 |
35 | 35 | ) |
36 | 36 | s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
37 | type postCounter struct { | |
38 | Value uint64 `json:"_value"` // reverse-engineered | |
39 | } | |
37 | 40 | m := map[string]postCounter{} |
38 | 41 | json.NewDecoder(r.Body).Decode(&m) |
39 | 42 | value = m[name].Value |
74 | 77 | } |
75 | 78 | |
76 | 79 | 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() | |
79 | 82 | |
80 | 83 | var ( |
81 | 84 | name = "test_gauge" |
82 | 85 | value float64 |
83 | 86 | ) |
84 | 87 | s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
88 | type postGauge struct { | |
89 | Value float64 `json:"_value"` | |
90 | } | |
85 | 91 | m := map[string]postGauge{} |
86 | 92 | json.NewDecoder(r.Body).Decode(&m) |
87 | 93 | value = m[name].Value |
114 | 120 | } |
115 | 121 | |
116 | 122 | 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() | |
119 | 125 | |
120 | 126 | var ( |
121 | 127 | name = "test_histogram" |
123 | 129 | onceDecode sync.Once |
124 | 130 | ) |
125 | 131 | s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
132 | type postHistogram struct { | |
133 | Value []string `json:"_value"` | |
134 | } | |
126 | 135 | onceDecode.Do(func() { |
127 | 136 | m := map[string]postHistogram{} |
128 | 137 | json.NewDecoder(r.Body).Decode(&m) |
168 | 177 | time.Sleep(d / 10) |
169 | 178 | } |
170 | 179 | } |
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 | } |