From 7606e1cfddd26d2848923dc1079d9fb2858e84f1 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Thu, 27 Jun 2019 14:41:19 +0300 Subject: more tests --- service/metrics/rpc_test.go | 100 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) (limited to 'service') diff --git a/service/metrics/rpc_test.go b/service/metrics/rpc_test.go index 10c71d13..da991b34 100644 --- a/service/metrics/rpc_test.go +++ b/service/metrics/rpc_test.go @@ -438,7 +438,7 @@ func Test_Observe2_RPC_Invalid_2(t *testing.T) { var ok bool assert.Error(t, client.Call("metrics.Observe", Metric{ - Name: "user_histogram_2", + Name: "user_histogram", Value: 100.0, }, &ok)) } @@ -518,3 +518,101 @@ func Test_Observe2_RPC_MetricError_2(t *testing.T) { Value: 100.0, }, &ok)) } + +// add +func Test_Add_RPC(t *testing.T) { + client, c := setup( + t, + `"user_gauge":{ + "type": "counter" + }`, + ) + 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) + + out, _, err := get("http://localhost:2112/metrics") + assert.NoError(t, err) + assert.Contains(t, out, `user_gauge 100`) +} + +func Test_Add_RPC_Vector(t *testing.T) { + client, c := setup( + t, + `"user_gauge":{ + "type": "counter", + "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) + + out, _, err := get("http://localhost:2112/metrics") + assert.NoError(t, err) + assert.Contains(t, out, `user_gauge{section="first",type="core"} 100`) +} + +func Test_Add_RPC_CollectorError(t *testing.T) { + client, c := setup( + t, + `"user_gauge":{ + "type": "counter", + "labels": ["type", "section"] + }`, + ) + defer c.Stop() + + var ok bool + assert.Error(t, client.Call("metrics.Add", Metric{ + Name: "user_gauge_2", + Value: 100.0, + Labels: []string{"missing"}, + }, &ok)) +} + +func Test_Add_RPC_MetricError(t *testing.T) { + client, c := setup( + t, + `"user_gauge":{ + "type": "counter", + "labels": ["type", "section"] + }`, + ) + defer c.Stop() + + var ok bool + assert.Error(t, client.Call("metrics.Add", Metric{ + Name: "user_gauge", + Value: 100.0, + Labels: []string{"missing"}, + }, &ok)) +} + +func Test_Add_RPC_MetricError_2(t *testing.T) { + client, c := setup( + t, + `"user_gauge":{ + "type": "counter", + "labels": ["type", "section"] + }`, + ) + defer c.Stop() + + var ok bool + assert.Error(t, client.Call("metrics.Add", Metric{ + Name: "user_gauge", + Value: 100.0, + }, &ok)) +} -- cgit v1.2.3