diff options
author | Valery Piashchynski <[email protected]> | 2020-11-13 17:36:22 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-11-13 17:36:22 +0300 |
commit | 99b6012400ab407cfcb04aab833640af565d550d (patch) | |
tree | 75a228cf96d90f99e7ee6367c5d7cbb4c465c61d /plugins/metrics/config_test.go | |
parent | 6eefd067f4c08ed51834926abd1a4c60ec55b56d (diff) |
Metrics config test
Config proper parsing
Add metrics tests to the CI and Makefile
Diffstat (limited to 'plugins/metrics/config_test.go')
-rw-r--r-- | plugins/metrics/config_test.go | 52 |
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) |