From 004c96f56ad47684389110510733ec8c3b1672f0 Mon Sep 17 00:00:00 2001 From: geauxvirtual Date: Tue, 15 Sep 2015 13:27:41 -0700 Subject: [PATCH 1/3] Update Pulse dependencies to current HEAD, 6078a9e82c1bbdb0d76d75e5c22a746f546ddf5c --- Godeps/Godeps.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 53ccf43..2d97c70 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -37,13 +37,13 @@ }, { "ImportPath": "github.com/intelsdi-x/pulse/control/plugin", - "Comment": "0.2.0", - "Rev": "1d138b91a09f8636547dba1bebdd26c86709fcd2" + "Comment": "HEAD", + "Rev": "6078a9e82c1bbdb0d76d75e5c22a746f546ddf5c" }, { "ImportPath": "github.com/intelsdi-x/pulse/core/ctypes", - "Comment": "0.2.0", - "Rev": "1d138b91a09f8636547dba1bebdd26c86709fcd2" + "Comment": "HEAD", + "Rev": "6078a9e82c1bbdb0d76d75e5c22a746f546ddf5c" } ] } From 0dd8348bd8c9960390cb6e111be31b83bbdd9809 Mon Sep 17 00:00:00 2001 From: geauxvirtual Date: Tue, 15 Sep 2015 13:43:37 -0700 Subject: [PATCH 2/3] Return ConfigPolicy instead of a ConfigPolicyNode --- influx/influx.go | 8 +++++--- influx/influx_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/influx/influx.go b/influx/influx.go index 15accb8..f82705f 100644 --- a/influx/influx.go +++ b/influx/influx.go @@ -18,7 +18,7 @@ import ( const ( name = "influx" - version = 3 + version = 4 pluginType = plugin.PublisherPluginType ) @@ -35,7 +35,8 @@ func NewInfluxPublisher() *influxPublisher { type influxPublisher struct { } -func (f *influxPublisher) GetConfigPolicyNode() cpolicy.ConfigPolicyNode { +func (f *influxPublisher) GetConfigPolicy() cpolicy.ConfigPolicy { + cp := cpolicy.New() config := cpolicy.NewPolicyNode() r1, err := cpolicy.NewStringRule("host", true) @@ -63,7 +64,8 @@ func (f *influxPublisher) GetConfigPolicyNode() cpolicy.ConfigPolicyNode { r5.Description = "Influxdb password" config.Add(r4) - return *config + cp.Add([]string{""}, config) + return *cp } // Publish publishes metric data to influxdb diff --git a/influx/influx_test.go b/influx/influx_test.go index 63245a4..7f7f1f3 100644 --- a/influx/influx_test.go +++ b/influx/influx_test.go @@ -27,13 +27,13 @@ func TestInfluxDBPlugin(t *testing.T) { Convey("So ip should be of influxPublisher type", func() { So(ip, ShouldHaveSameTypeAs, &influxPublisher{}) }) - Convey("ip.GetConfigPolicyNode() should return a config policy node", func() { - config := ip.GetConfigPolicyNode() + Convey("ip.GetConfigPolicy() should return a config policy", func() { + config := ip.GetConfigPolicy() Convey("So config should not be nil", func() { So(config, ShouldNotBeNil) }) - Convey("So config should be a cpolicy.ConfigPolicyNode", func() { - So(config, ShouldHaveSameTypeAs, cpolicy.ConfigPolicyNode{}) + Convey("So config should be a cpolicy.ConfigPolicy", func() { + So(config, ShouldHaveSameTypeAs, cpolicy.ConfigPolicy{}) }) }) }) From c7f37b9e068ee42e7686d236450131a18af6ed19 Mon Sep 17 00:00:00 2001 From: geauxvirtual Date: Tue, 15 Sep 2015 14:01:55 -0700 Subject: [PATCH 3/3] Add tests to process example config --- influx/influx_integration_test.go | 4 ++-- influx/influx_test.go | 32 ++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/influx/influx_integration_test.go b/influx/influx_integration_test.go index 39e4b3f..bda413c 100644 --- a/influx/influx_integration_test.go +++ b/influx/influx_integration_test.go @@ -29,8 +29,8 @@ func TestInfluxPublish(t *testing.T) { config["database"] = ctypes.ConfigValueStr{Value: "test"} ip := NewInfluxPublisher() - policy := ip.GetConfigPolicyNode() - cfg, _ := policy.Process(config) + cp := ip.GetConfigPolicy() + cfg, _ := cp.Get([]string{""}).Process(config) Convey("Publish integer metric", func() { metrics := []plugin.PluginMetricType{ diff --git a/influx/influx_test.go b/influx/influx_test.go index 7f7f1f3..61cb527 100644 --- a/influx/influx_test.go +++ b/influx/influx_test.go @@ -8,6 +8,7 @@ import ( "github.com/intelsdi-x/pulse/control/plugin" "github.com/intelsdi-x/pulse/control/plugin/cpolicy" + "github.com/intelsdi-x/pulse/core/ctypes" . "github.com/smartystreets/goconvey/convey" ) @@ -28,12 +29,33 @@ func TestInfluxDBPlugin(t *testing.T) { So(ip, ShouldHaveSameTypeAs, &influxPublisher{}) }) Convey("ip.GetConfigPolicy() should return a config policy", func() { - config := ip.GetConfigPolicy() - Convey("So config should not be nil", func() { - So(config, ShouldNotBeNil) + configPolicy := ip.GetConfigPolicy() + Convey("So config policy should not be nil", func() { + So(configPolicy, ShouldNotBeNil) }) - Convey("So config should be a cpolicy.ConfigPolicy", func() { - So(config, ShouldHaveSameTypeAs, cpolicy.ConfigPolicy{}) + Convey("So config policy should be a cpolicy.ConfigPolicy", func() { + So(configPolicy, ShouldHaveSameTypeAs, cpolicy.ConfigPolicy{}) + }) + testConfig := make(map[string]ctypes.ConfigValue) + testConfig["host"] = ctypes.ConfigValueStr{Value: "localhost"} + testConfig["port"] = ctypes.ConfigValueInt{Value: 8086} + testConfig["user"] = ctypes.ConfigValueStr{Value: "root"} + testConfig["password"] = ctypes.ConfigValueStr{Value: "root"} + testConfig["database"] = ctypes.ConfigValueStr{Value: "test"} + cfg, errs := configPolicy.Get([]string{""}).Process(testConfig) + Convey("So config policy should process testConfig and return a config", func() { + So(cfg, ShouldNotBeNil) + }) + Convey("So testConfig processing should return no errors", func() { + So(errs.HasErrors(), ShouldBeFalse) + }) + testConfig["port"] = ctypes.ConfigValueStr{Value: "8086"} + cfg, errs = configPolicy.Get([]string{""}).Process(testConfig) + Convey("So config policy should not return a config after processing invalid testConfig", func() { + So(cfg, ShouldBeNil) + }) + Convey("So testConfig processing should return errors", func() { + So(errs.HasErrors(), ShouldBeTrue) }) }) })