summaryrefslogtreecommitdiff
path: root/plugins/metrics/config_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/metrics/config_test.go')
-rw-r--r--plugins/metrics/config_test.go52
1 files changed, 32 insertions, 20 deletions
diff --git a/plugins/metrics/config_test.go b/plugins/metrics/config_test.go
index a64e9047..24c8406c 100644
--- a/plugins/metrics/config_test.go
+++ b/plugins/metrics/config_test.go
@@ -1,47 +1,54 @@
package metrics
import (
+ "bytes"
+ "testing"
+
json "github.com/json-iterator/go"
"github.com/prometheus/client_golang/prometheus"
- "github.com/spiral/roadrunner/service"
"github.com/stretchr/testify/assert"
- "testing"
)
-type mockCfg struct{ cfg string }
-
-func (cfg *mockCfg) Get(name string) service.Config { return nil }
-func (cfg *mockCfg) Unmarshal(out interface{}) error {
- j := json.ConfigCompatibleWithStandardLibrary
- return j.Unmarshal([]byte(cfg.cfg), out)
-}
-
func Test_Config_Hydrate_Error1(t *testing.T) {
- cfg := &mockCfg{`{"request": {"From": "Something"}}`}
+ cfg := `{"request": {"From": "Something"}}`
c := &Config{}
+ f := new(bytes.Buffer)
+ f.WriteString(cfg)
- assert.NoError(t, c.Hydrate(cfg))
+ err := json.Unmarshal(f.Bytes(), &c)
+ if err != nil {
+ t.Fatal(err)
+ }
}
func Test_Config_Hydrate_Error2(t *testing.T) {
- cfg := &mockCfg{`{"dir": "/dir/"`}
+ cfg := `{"dir": "/dir/"`
c := &Config{}
- assert.Error(t, c.Hydrate(cfg))
+ f := new(bytes.Buffer)
+ f.WriteString(cfg)
+
+ err := json.Unmarshal(f.Bytes(), &c)
+ assert.Error(t, err)
}
func Test_Config_Metrics(t *testing.T) {
- cfg := &mockCfg{`{
+ cfg := `{
"collect":{
"metric1":{"type": "gauge"},
"metric2":{ "type": "counter"},
"metric3":{"type": "summary"},
"metric4":{"type": "histogram"}
}
-}`}
+}`
c := &Config{}
+ f := new(bytes.Buffer)
+ f.WriteString(cfg)
- assert.NoError(t, c.Hydrate(cfg))
+ err := json.Unmarshal(f.Bytes(), &c)
+ if err != nil {
+ t.Fatal(err)
+ }
m, err := c.getCollectors()
assert.NoError(t, err)
@@ -53,17 +60,22 @@ func Test_Config_Metrics(t *testing.T) {
}
func Test_Config_MetricsVector(t *testing.T) {
- cfg := &mockCfg{`{
+ cfg := `{
"collect":{
"metric1":{"type": "gauge","labels":["label"]},
"metric2":{ "type": "counter","labels":["label"]},
"metric3":{"type": "summary","labels":["label"]},
"metric4":{"type": "histogram","labels":["label"]}
}
-}`}
+}`
c := &Config{}
+ f := new(bytes.Buffer)
+ f.WriteString(cfg)
- assert.NoError(t, c.Hydrate(cfg))
+ err := json.Unmarshal(f.Bytes(), &c)
+ if err != nil {
+ t.Fatal(err)
+ }
m, err := c.getCollectors()
assert.NoError(t, err)