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

Commit

Permalink
Update test to use helper for plugin path
Browse files Browse the repository at this point in the history
Currently most of the test have a hard coded expectation for plugin
path. This changes all test to use helper.PluginFilePath to determine
plugin binary location and allow easier updates in the future.
  • Loading branch information
nanliu committed Sep 26, 2016
1 parent aa35a43 commit ce090da
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 117 deletions.
6 changes: 3 additions & 3 deletions control/control_grpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package control

import (
"net"
"path"
"testing"

"github.com/intelsdi-x/gomit"
Expand All @@ -38,6 +37,7 @@ import (
"github.com/intelsdi-x/snap/grpc/common"
"github.com/intelsdi-x/snap/grpc/controlproxy/rpc"
"github.com/intelsdi-x/snap/pkg/rpcutil"
"github.com/intelsdi-x/snap/plugin/helper"
. "github.com/smartystreets/goconvey/convey"
)

Expand Down Expand Up @@ -99,7 +99,7 @@ func TestGRPCServerScheduler(t *testing.T) {
})
})
<-lpe.done
passthru, err := core.NewRequestedPlugin(path.Join(fixtures.SnapPath, "plugin", "snap-plugin-processor-passthru"))
passthru, err := core.NewRequestedPlugin(helper.PluginFilePath("snap-plugin-processor-passthru"))
if err != nil {
log.Fatal(err)
}
Expand All @@ -115,7 +115,7 @@ func TestGRPCServerScheduler(t *testing.T) {
typeName: catalogedPassthru.TypeName(),
}
<-lpe.done
filepub, err := core.NewRequestedPlugin(path.Join(fixtures.SnapPath, "plugin", "snap-plugin-publisher-mock-file"))
filepub, err := core.NewRequestedPlugin(helper.PluginFilePath("snap-plugin-publisher-mock-file"))
if err != nil {
log.Fatal(err)
}
Expand Down
27 changes: 14 additions & 13 deletions control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/intelsdi-x/snap/core/control_event"
"github.com/intelsdi-x/snap/core/ctypes"
"github.com/intelsdi-x/snap/core/serror"
"github.com/intelsdi-x/snap/plugin/helper"
)

// Mock Executor used to test
Expand Down Expand Up @@ -1460,7 +1461,7 @@ func TestPublishMetrics(t *testing.T) {
time.Sleep(1 * time.Second)

// Load plugin
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-publisher-mock-file"))
_, err := load(c, helper.PluginFilePath("snap-plugin-publisher-mock-file"))
So(err, ShouldBeNil)
<-lpe.done
So(len(c.pluginManager.all()), ShouldEqual, 1)
Expand Down Expand Up @@ -1508,7 +1509,7 @@ func TestProcessMetrics(t *testing.T) {
c.Config.Plugins.Processor.Plugins["passthru"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))

// Load plugin
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-processor-passthru"))
_, err := load(c, helper.PluginFilePath("snap-plugin-processor-passthru"))
So(err, ShouldBeNil)
<-lpe.done
So(len(c.pluginManager.all()), ShouldEqual, 1)
Expand Down Expand Up @@ -1590,7 +1591,7 @@ func TestMetricSubscriptionToNewVersion(t *testing.T) {
lpe := newListenToPluginEvents()
c.eventManager.RegisterHandler("TestMetricSubscriptionToNewVersion", lpe)
c.Start()
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
<-lpe.load
So(err, ShouldBeNil)
So(len(c.pluginManager.all()), ShouldEqual, 1)
Expand Down Expand Up @@ -1625,7 +1626,7 @@ func TestMetricSubscriptionToNewVersion(t *testing.T) {
})
Convey("Loading v2 of that plugin should move subscriptions to newer version", func() {
// Load version snap-plugin-collector-mock2
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock2"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock2"))
So(err, ShouldBeNil)
select {
// Wait on subscriptionMovedEvent
Expand Down Expand Up @@ -1662,7 +1663,7 @@ func TestMetricSubscriptionToOlderVersion(t *testing.T) {
lpe := newListenToPluginEvents()
c.eventManager.RegisterHandler("TestMetricSubscriptionToOlderVersion", lpe)
c.Start()
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock2"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock2"))
<-lpe.load
So(err, ShouldBeNil)
So(len(c.pluginManager.all()), ShouldEqual, 1)
Expand Down Expand Up @@ -1693,7 +1694,7 @@ func TestMetricSubscriptionToOlderVersion(t *testing.T) {
mockv2 := pc[0]
Convey("Loading v1 of that plugin and unloading v2 should move subscriptions to older version", func() {
// Load version snap-plugin-collector-mock1
_, err = load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1"))
_, err = load(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
<-lpe.load
So(err, ShouldBeNil)
// Unload version snap-plugin-collector-mock2
Expand Down Expand Up @@ -1746,7 +1747,7 @@ func TestDynamicMetricSubscriptionLoad(t *testing.T) {
lpe := newListenToPluginEvents()
c.eventManager.RegisterHandler("TestDynamicMetricSubscriptionLoad", lpe)
c.Start()
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
So(len(c.pluginManager.all()), ShouldEqual, 1)
lp, err2 := c.pluginManager.get("collector" + core.Separator + "mock" + core.Separator + "1")
Expand Down Expand Up @@ -1787,7 +1788,7 @@ func TestDynamicMetricSubscriptionLoad(t *testing.T) {
})
Convey("Loading mock plugin in version 2 should swap subscriptions to latest version", func() {
// Load version snap-plugin-collector-mock2
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock2"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock2"))
So(err, ShouldBeNil)
<-lpe.load // wait for load event
<-lpe.sub // wait for subscription event
Expand All @@ -1813,7 +1814,7 @@ func TestDynamicMetricSubscriptionLoad(t *testing.T) {
})
Convey("Loading another plugin should add subscriptions", func() {
// Load version snap-plugin-collector-anothermock1
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-anothermock1"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-anothermock1"))
So(err, ShouldBeNil)
<-lpe.load // wait for load event
<-lpe.sub // wait for subscription event
Expand Down Expand Up @@ -1845,9 +1846,9 @@ func TestDynamicMetricSubscriptionUnload(t *testing.T) {
lpe := newListenToPluginEvents()
c.eventManager.RegisterHandler("TestDynamicMetricSubscriptionUnload", lpe)
c.Start()
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
_, err = load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-anothermock1"))
_, err = load(c, helper.PluginFilePath("snap-plugin-collector-anothermock1"))
So(err, ShouldBeNil)
So(len(c.pluginManager.all()), ShouldEqual, 2)
lpMock, err2 := c.pluginManager.get("collector" + core.Separator + "mock" + core.Separator + "1")
Expand Down Expand Up @@ -1928,7 +1929,7 @@ func TestDynamicMetricSubscriptionLoadLessMetrics(t *testing.T) {
lpe := newListenToPluginEvents()
c.eventManager.RegisterHandler("TestDynamicMetricSubscriptionLoadLessMetrics", lpe)
c.Start()
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock1"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
So(len(c.pluginManager.all()), ShouldEqual, 1)
lp, err2 := c.pluginManager.get("collector" + core.Separator + "mock" + core.Separator + "1")
Expand Down Expand Up @@ -1970,7 +1971,7 @@ func TestDynamicMetricSubscriptionLoadLessMetrics(t *testing.T) {
})
Convey("Loading higher plugin version with less metrics", func() {
// Load version snap-plugin-collector-mock2
_, err := load(c, path.Join(fixtures.SnapPath, "plugin", "snap-plugin-collector-mock2"))
_, err := load(c, helper.PluginFilePath("snap-plugin-collector-mock2"))
So(err, ShouldBeNil)
<-lpe.load // wait for load event
<-lpe.sub // wait for subscription event
Expand Down
6 changes: 3 additions & 3 deletions control/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ package fixtures
import (
"encoding/json"
"os"
"path"
"time"

"github.com/intelsdi-x/snap/core"
"github.com/intelsdi-x/snap/core/cdata"
"github.com/intelsdi-x/snap/plugin/helper"
)

var (
PluginName = "snap-plugin-collector-mock2"
SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH"))
PluginPath = path.Join(SnapPath, "plugin", PluginName)
PluginPath = helper.PluginFilePath(PluginName)

JSONRPCPluginName = "snap-plugin-collector-mock1"
JSONRPCPluginPath = path.Join(SnapPath, "plugin", JSONRPCPluginName)
JSONRPCPluginPath = helper.PluginFilePath(JSONRPCPluginName)
)

// mocks a metric type
Expand Down
39 changes: 19 additions & 20 deletions control/subscription_group_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ package control

import (
"net"
"os"
"path"
"testing"

"github.com/intelsdi-x/snap/core"
"github.com/intelsdi-x/snap/core/cdata"
"github.com/intelsdi-x/snap/core/control_event"
"github.com/intelsdi-x/snap/core/serror"
"github.com/intelsdi-x/snap/plugin/helper"

log "github.com/Sirupsen/logrus"
"github.com/intelsdi-x/gomit"
Expand Down Expand Up @@ -128,7 +127,7 @@ func TestSubscriptionGroups_ProcessStaticNegative(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugin", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -166,7 +165,7 @@ func TestSubscriptionGroups_ProcessStaticNegative(t *testing.T) {
config: cdata.NewNode(),
}

_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1"))
So(err, ShouldBeNil)
<-lpe.load
serrs := sg.Process()
Expand Down Expand Up @@ -199,7 +198,7 @@ func TestSubscriptionGroups_ProcessStaticPositive(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugin", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -236,7 +235,7 @@ func TestSubscriptionGroups_ProcessStaticPositive(t *testing.T) {
version: 2,
config: cdata.NewNode(),
}
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock2"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock2"))
So(err, ShouldBeNil)
<-lpe.load
serrs := sg.Process()
Expand Down Expand Up @@ -269,7 +268,7 @@ func TestSubscriptionGroups_ProcessDynamicPositive(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugin", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)

<-lpe.load
Expand Down Expand Up @@ -307,7 +306,7 @@ func TestSubscriptionGroups_ProcessDynamicPositive(t *testing.T) {
version: 1,
config: cdata.NewNode(),
}
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1"))
So(err, ShouldBeNil)
<-lpe.load
serrs := sg.Process()
Expand Down Expand Up @@ -345,7 +344,7 @@ func TestSubscriptionGroups_ProcessDynamicNegative(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugin", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -382,7 +381,7 @@ func TestSubscriptionGroups_ProcessDynamicNegative(t *testing.T) {
version: 1,
config: cdata.NewNode(),
}
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1"))
So(err, ShouldBeNil)
<-lpe.load
serrs := sg.Process()
Expand Down Expand Up @@ -416,7 +415,7 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicPositive(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugin", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)

<-lpe.load
Expand Down Expand Up @@ -459,7 +458,7 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicPositive(t *testing.T) {
version: 1,
config: cdata.NewNode(),
}
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1"))
So(err, ShouldBeNil)
<-lpe.load
serrs := sg.Process()
Expand Down Expand Up @@ -499,7 +498,7 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicNegative(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugin", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -540,7 +539,7 @@ func TestSubscriptionGroups_ProcessSpecifiedDynamicNegative(t *testing.T) {
version: 1,
config: cdata.NewNode(),
}
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-anothermock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-anothermock1"))
So(err, ShouldBeNil)
<-lpe.load
serrs := sg.Process()
Expand Down Expand Up @@ -576,7 +575,7 @@ func TestSubscriptionGroups_AddRemoveStatic(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugn", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -615,7 +614,7 @@ func TestSubscriptionGroups_AddRemoveDynamic(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugn", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -657,7 +656,7 @@ func TestSubscriptionGroups_AddRemoveSpecifiedDynamic(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugn", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -702,7 +701,7 @@ func TestSubscriptionGroups_GetStatic(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugn", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -751,7 +750,7 @@ func TestSubscriptionGroups_GetDynamic(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugn", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down Expand Up @@ -800,7 +799,7 @@ func TestSubscriptionGroups_GetSpecifiedDynamic(t *testing.T) {
c.Start()

Convey("Loading a mock collector plugn", t, func() {
_, err := loadPlg(c, path.Join(os.ExpandEnv(os.Getenv("SNAP_PATH")), "plugin", "snap-plugin-collector-mock1"))
_, err := loadPlg(c, helper.PluginFilePath("snap-plugin-collector-mock1"))
So(err, ShouldBeNil)
<-lpe.load

Expand Down
6 changes: 3 additions & 3 deletions core/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ package core
import (
"crypto/sha256"
"io/ioutil"
"os"
"path"
"testing"

"github.com/intelsdi-x/snap/plugin/helper"
. "github.com/smartystreets/goconvey/convey"
)

var (
PluginName = "snap-plugin-collector-mock1"
SnapPath = os.ExpandEnv(os.Getenv("SNAP_PATH"))
PluginPath = path.Join(SnapPath, "plugin", PluginName)
SnapPath = helper.BuildPath
PluginPath = helper.PluginFilePath(PluginName)
SignatureFile = path.Join(SnapPath, "../pkg/psigning", "snap-plugin-collector-mock1.asc")
)

Expand Down
Loading

0 comments on commit ce090da

Please sign in to comment.