Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fix #379 and add tests around checking errors for manifests defined w…
Browse files Browse the repository at this point in the history
…ithout config for metric with policy defined
  • Loading branch information
geauxvirtual committed Oct 1, 2015
1 parent b894893 commit 3a44873
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
6 changes: 5 additions & 1 deletion control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric,
}
m.config = cd

if m.Config() != nil {
if m.policy != nil {
if m.Config() == nil {
perrs = append(perrs, perror.New(errors.New(fmt.Sprintf("Policy defined for metric, (%s) version (%d), but no config defined in manifest", mt.Namespace(), mt.Version()))))
return nil, perrs
}
ncdTable, errs := m.policy.Process(m.Config().Table())
if errs != nil && errs.HasErrors() {
for _, e := range errs.Errors() {
Expand Down
21 changes: 21 additions & 0 deletions control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,27 @@ func (m MockMetricType) Data() interface{} {
return nil
}

func TestMetricConfig(t *testing.T) {
c := New()
c.Start()
c.Load(PluginPath)
cd := cdata.NewNode()
m1 := MockMetricType{
namespace: []string{"intel", "dummy", "foo"},
}
metric, errs := c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should not be valid without config", t, func() {
So(metric, ShouldBeNil)
So(errs, ShouldNotBeNil)
})
cd.AddItem("password", ctypes.ConfigValueStr{Value: "testval"})
metric, errs = c.validateMetricTypeSubscription(m1, cd)
Convey("So metric should be valid with config", t, func() {
So(metric, ShouldNotBeNil)
So(errs, ShouldBeNil)
})
}

func TestCollectMetrics(t *testing.T) {

Convey("given a new router", t, func() {
Expand Down
15 changes: 15 additions & 0 deletions mgmt/rest/client/client_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,22 @@ func TestPulseClient(t *testing.T) {
So(a.events[x], ShouldEqual, "metric-event")
}
})
})
Convey("Passing a bad task manifest", func() {
port := getPort()
uri := startAPI(port)
c := New(uri, "v1")

c.LoadPlugin(DUMMY_PLUGIN_PATH2)
c.LoadPlugin(FILE_PLUGIN_PATH)

wf := getWMFromSample("bad.json")
sch := &Schedule{Type: "simple", Interval: "1s"}
p := c.CreateTask(sch, wf, "bad", true)

Convey("Should generate an error", func() {
So(p.Err, ShouldNotBeNil)
})
})
})
}
6 changes: 5 additions & 1 deletion mgmt/rest/wmap_sample/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"metrics": {
"/intel/dummy/foo": {}
},
"config": {},
"config": {
"/intel/dummy/foo": {
"password": "testval"
}
},
"process": [],
"publish": [
{
Expand Down
18 changes: 18 additions & 0 deletions mgmt/rest/wmap_sample/bad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"collect": {
"metrics": {
"/intel/dummy/foo": {}
},
"config": {},
"process": [],
"publish": [
{
"plugin_name": "file",
"plugin_version": 1,
"config": {
"file": "/tmp/rest.test"
}
}
]
}
}

0 comments on commit 3a44873

Please sign in to comment.