summaryrefslogtreecommitdiff
path: root/service/metrics/rpc_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-06-27 14:29:49 +0300
committerWolfy-J <[email protected]>2019-06-27 14:29:49 +0300
commit5b678c091dfb02313a9d58c28e6c9054891430da (patch)
tree706d3c8513dfb3476e79ddf47c666e8ffc3af32c /service/metrics/rpc_test.go
parenta351210ac22fa6bcbf37e53dde0814245b927524 (diff)
more tests
Diffstat (limited to 'service/metrics/rpc_test.go')
-rw-r--r--service/metrics/rpc_test.go134
1 files changed, 131 insertions, 3 deletions
diff --git a/service/metrics/rpc_test.go b/service/metrics/rpc_test.go
index e9846e4b..10c71d13 100644
--- a/service/metrics/rpc_test.go
+++ b/service/metrics/rpc_test.go
@@ -159,6 +159,135 @@ func Test_Set_RPC_MetricError_3(t *testing.T) {
}, &ok))
}
+// sub
+
+func Test_Sub_RPC(t *testing.T) {
+ client, c := setup(
+ t,
+ `"user_gauge":{
+ "type": "gauge"
+ }`,
+ )
+ defer c.Stop()
+
+ var ok bool
+ assert.NoError(t, client.Call("metrics.Add", Metric{
+ Name: "user_gauge",
+ Value: 100.0,
+ }, &ok))
+ assert.True(t, ok)
+
+ assert.NoError(t, client.Call("metrics.Sub", Metric{
+ Name: "user_gauge",
+ Value: 10.0,
+ }, &ok))
+ assert.True(t, ok)
+
+ out, _, err := get("http://localhost:2112/metrics")
+ assert.NoError(t, err)
+ assert.Contains(t, out, `user_gauge 90`)
+}
+
+func Test_Sub_RPC_Vector(t *testing.T) {
+ client, c := setup(
+ t,
+ `"user_gauge":{
+ "type": "gauge",
+ "labels": ["type", "section"]
+ }`,
+ )
+ defer c.Stop()
+
+ var ok bool
+ assert.NoError(t, client.Call("metrics.Add", Metric{
+ Name: "user_gauge",
+ Value: 100.0,
+ Labels: []string{"core", "first"},
+ }, &ok))
+ assert.True(t, ok)
+
+ assert.NoError(t, client.Call("metrics.Sub", Metric{
+ Name: "user_gauge",
+ Value: 10.0,
+ Labels: []string{"core", "first"},
+ }, &ok))
+ assert.True(t, ok)
+
+ out, _, err := get("http://localhost:2112/metrics")
+ assert.NoError(t, err)
+ assert.Contains(t, out, `user_gauge{section="first",type="core"} 90`)
+}
+
+func Test_Sub_RPC_CollectorError(t *testing.T) {
+ client, c := setup(
+ t,
+ `"user_gauge":{
+ "type": "gauge",
+ "labels": ["type", "section"]
+ }`,
+ )
+ defer c.Stop()
+
+ var ok bool
+ assert.Error(t, client.Call("metrics.Sub", Metric{
+ Name: "user_gauge_2",
+ Value: 100.0,
+ Labels: []string{"missing"},
+ }, &ok))
+}
+
+func Test_Sub_RPC_MetricError(t *testing.T) {
+ client, c := setup(
+ t,
+ `"user_gauge":{
+ "type": "gauge",
+ "labels": ["type", "section"]
+ }`,
+ )
+ defer c.Stop()
+
+ var ok bool
+ assert.Error(t, client.Call("metrics.Sub", Metric{
+ Name: "user_gauge",
+ Value: 100.0,
+ Labels: []string{"missing"},
+ }, &ok))
+}
+
+func Test_Sub_RPC_MetricError_2(t *testing.T) {
+ client, c := setup(
+ t,
+ `"user_gauge":{
+ "type": "gauge",
+ "labels": ["type", "section"]
+ }`,
+ )
+ defer c.Stop()
+
+ var ok bool
+ assert.Error(t, client.Call("metrics.Sub", Metric{
+ Name: "user_gauge",
+ Value: 100.0,
+ }, &ok))
+}
+
+func Test_Sub_RPC_MetricError_3(t *testing.T) {
+ client, c := setup(
+ t,
+ `"user_gauge":{
+ "type": "histogram",
+ "labels": ["type", "section"]
+ }`,
+ )
+ defer c.Stop()
+
+ var ok bool
+ assert.Error(t, client.Call("metrics.Sub", Metric{
+ Name: "user_gauge",
+ Value: 100.0,
+ }, &ok))
+}
+
// -- observe
func Test_Observe_RPC(t *testing.T) {
@@ -309,9 +438,8 @@ func Test_Observe2_RPC_Invalid_2(t *testing.T) {
var ok bool
assert.Error(t, client.Call("metrics.Observe", Metric{
- Name: "user_histogram_2",
- Value: 100.0,
- Labels: []string{"missing"},
+ Name: "user_histogram_2",
+ Value: 100.0,
}, &ok))
}