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

Commit

Permalink
SDI-2115: remove metric.String() in plugin-lib-go
Browse files Browse the repository at this point in the history
  • Loading branch information
candysmurf committed Oct 25, 2016
1 parent fabc865 commit 216cd4f
Showing 1 changed file with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ package mock

import (
"math/rand"
"strings"
"testing"
"time"

"github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin"
"github.com/intelsdi-x/snap-plugin-utilities/str"
. "github.com/smartystreets/goconvey/convey"
)

Expand Down Expand Up @@ -96,7 +96,7 @@ func TestCollectMetric(t *testing.T) {

// only one metric for this specific hostname should be returned
So(len(mts), ShouldEqual, 1)
So(mts[0].Namespace.String(), ShouldEqual, "/intel/mock/host0/baz")
So(mts[0].Namespace.Strings(), ShouldResemble, []string{"intel", "mock", "host0", "baz"})

Convey("returned metric should have data type integer", func() {
_, ok := mts[0].Data.(int)
Expand Down Expand Up @@ -192,22 +192,12 @@ func TestGetMetricTypes(t *testing.T) {
So(len(mts), ShouldEqual, 6)

Convey("checking namespaces", func() {
metricNames := []string{}
for _, m := range mts {
metricNames = append(metricNames, m.Namespace.String())
nsRes := getNsResultHavingConfig()
for i, m := range mts {
Convey("checking namespaces: "+strings.Join(m.Namespace.Strings(), "%"), func() {
So(m.Namespace.Strings(), ShouldResemble, nsRes[i])
})
}

ns := plugin.NewNamespace("intel", "mock", "test%>")
So(str.Contains(metricNames, ns.String()), ShouldBeTrue)

ns = plugin.NewNamespace("intel", "mock", "/foo=㊽")
So(str.Contains(metricNames, ns.String()), ShouldBeTrue)

ns = plugin.NewNamespace("intel", "mock", "/bar⽔")
So(str.Contains(metricNames, ns.String()), ShouldBeTrue)

ns = plugin.NewNamespace("intel", "mock").AddDynamicElement("host", "name of the host").AddStaticElements("baz㊽", "/bar⽔")
So(str.Contains(metricNames, ns.String()), ShouldBeTrue)
})
})

Expand All @@ -218,22 +208,14 @@ func TestGetMetricTypes(t *testing.T) {
So(len(mts), ShouldEqual, 5)

Convey("checking namespaces", func() {
metricNames := []string{}
for _, m := range mts {
metricNames = append(metricNames, m.Namespace.String())
nsRes := getNsResultWithoutConfig()
for i, m := range mts {
Convey("checking namespaces: "+strings.Join(m.Namespace.Strings(), "%"), func() {
So(m.Namespace.Strings(), ShouldResemble, nsRes[i])
})
}

ns := plugin.NewNamespace("intel", "mock", "/foo=㊽")
So(str.Contains(metricNames, ns.String()), ShouldBeTrue)

ns = plugin.NewNamespace("intel", "mock", "/bar⽔")
So(str.Contains(metricNames, ns.String()), ShouldBeTrue)

ns = plugin.NewNamespace("intel", "mock").AddDynamicElement("host", "name of the host").AddStaticElements("baz㊽", "|barᵹÄ☍")
So(str.Contains(metricNames, ns.String()), ShouldBeTrue)
})
})

})
}

Expand All @@ -256,3 +238,26 @@ func TestGetConfigPolicy(t *testing.T) {
So(configPolicy, ShouldNotBeNil)
})
}

func getNsResultHavingConfig() [][]string {
nss := [][]string{
{"intel", "mock", "test%>"},
{"intel", "mock", "/foo=㊽"},
{"intel", "mock", "/bar⽔"},
{"intel", "mock", "*", "/baz⽔"},
{"intel", "mock", "*", "baz㊽", "/bar⽔"},
{"intel", "mock", "*", "baz㊽", "|barᵹÄ☍"},
}
return nss
}

func getNsResultWithoutConfig() [][]string {
nss := [][]string{
{"intel", "mock", "/foo=㊽"},
{"intel", "mock", "/bar⽔"},
{"intel", "mock", "*", "/baz⽔"},
{"intel", "mock", "*", "baz㊽", "/bar⽔"},
{"intel", "mock", "*", "baz㊽", "|barᵹÄ☍"},
}
return nss
}

0 comments on commit 216cd4f

Please sign in to comment.