diff options
author | Wolfy-J <[email protected]> | 2019-06-27 14:41:19 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-06-27 14:41:19 +0300 |
commit | 7606e1cfddd26d2848923dc1079d9fb2858e84f1 (patch) | |
tree | e43def1e291c5f6ab75e734de6059c4522fc8f6b /service/metrics | |
parent | 5b678c091dfb02313a9d58c28e6c9054891430da (diff) |
more tests
Diffstat (limited to 'service/metrics')
-rw-r--r-- | service/metrics/rpc_test.go | 100 |
1 files changed, 99 insertions, 1 deletions
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)) +} |