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

Commit 4b8f7af

Browse files
Renamed variables in fixtures.go and tests files
1 parent 908767e commit 4b8f7af

8 files changed

Lines changed: 52 additions & 53 deletions

File tree

control/available_plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestAvailablePlugin(t *testing.T) {
5757
r.SetEmitter(new(MockEmitter))
5858
a := plugin.Arg{}
5959

60-
exPlugin, _ := plugin.NewExecutablePlugin(a, fixtures.PluginPath)
60+
exPlugin, _ := plugin.NewExecutablePlugin(a, fixtures.PluginPathMock2)
6161
ap, err := r.startPlugin(exPlugin)
6262
So(err, ShouldBeNil)
6363

control/control_grpc_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestGRPCServerScheduler(t *testing.T) {
8888
// collector -- mock
8989
// processor -- passthru
9090
// publisher -- file
91-
mock, err := core.NewRequestedPlugin(fixtures.JSONRPCPluginPath)
91+
mock, err := core.NewRequestedPlugin(fixtures.PluginPathMock1)
9292
if err != nil {
9393
log.Fatal(err)
9494
}

control/control_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestSwapPlugin(t *testing.T) {
157157
lpe := newListenToPluginEvent()
158158
c.eventManager.RegisterHandler("Control.PluginsSwapped", lpe)
159159

160-
_, e := load(c, fixtures.PluginPath)
160+
_, e := load(c, fixtures.PluginPathMock2)
161161
Convey("Loading first plugin", t, func() {
162162
Convey("Should not error", func() {
163163
So(e, ShouldBeNil)
@@ -177,8 +177,7 @@ func TestSwapPlugin(t *testing.T) {
177177
So(c.PluginCatalog()[0].Name(), ShouldEqual, "mock")
178178
})
179179
})
180-
mock1Path := strings.Replace(fixtures.PluginPath, "snap-plugin-collector-mock2", "snap-plugin-collector-mock1", 1)
181-
mockRP, mErr := core.NewRequestedPlugin(mock1Path)
180+
mockRP, mErr := core.NewRequestedPlugin(fixtures.PluginPathMock1)
182181
Convey("Loading a plugin should not error", t, func() {
183182
So(mErr, ShouldBeNil)
184183
})
@@ -224,7 +223,7 @@ func TestSwapPlugin(t *testing.T) {
224223
})
225224
})
226225

227-
filePath := strings.Replace(fixtures.PluginPath, "snap-plugin-collector-mock2", "snap-plugin-publisher-mock-file", 1)
226+
filePath := strings.Replace(fixtures.PluginPathMock2, "snap-plugin-collector-mock2", "snap-plugin-publisher-mock-file", 1)
228227
fileRP, pErr := core.NewRequestedPlugin(filePath)
229228
Convey("Loading a plugin should not error", t, func() {
230229
So(pErr, ShouldBeNil)
@@ -248,7 +247,7 @@ func TestSwapPlugin(t *testing.T) {
248247
pm.ExistingPlugin = lp
249248
c.pluginManager = pm
250249

251-
mockRP, mErr := core.NewRequestedPlugin(mock1Path)
250+
mockRP, mErr := core.NewRequestedPlugin(fixtures.PluginPathMock1)
252251
So(mErr, ShouldBeNil)
253252
err := c.SwapPlugins(mockRP, lp)
254253
Convey("So err should be received if rollback fails", func() {
@@ -357,7 +356,7 @@ func TestLoad(t *testing.T) {
357356

358357
// Testing trying to load before starting pluginControl
359358
Convey("pluginControl before being started", t, func() {
360-
_, err := load(c, fixtures.PluginPath)
359+
_, err := load(c, fixtures.PluginPathMock2)
361360
Convey("should return an error when loading a plugin", func() {
362361
So(err, ShouldNotBeNil)
363362
})
@@ -371,7 +370,7 @@ func TestLoad(t *testing.T) {
371370
time.Sleep(100 * time.Millisecond)
372371
lpe := newListenToPluginEvent()
373372
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
374-
_, err := load(c, fixtures.PluginPath)
373+
_, err := load(c, fixtures.PluginPathMock2)
375374
Convey("pluginControl.Load on successful load", t, func() {
376375
Convey("Should not return an error", func() {
377376
So(err, ShouldBeNil)
@@ -400,7 +399,7 @@ func TestLoad(t *testing.T) {
400399
c.Stop()
401400
time.Sleep(100 * time.Millisecond)
402401
} else {
403-
fmt.Printf("SNAP_PATH not set. Cannot test %s plugin.\n", fixtures.PluginName)
402+
fmt.Printf("SNAP_PATH not set. Cannot test %s plugin.\n", fixtures.PluginNameMock2)
404403
}
405404
}
406405

@@ -414,7 +413,7 @@ func TestLoadWithSignedPlugins(t *testing.T) {
414413
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
415414
c.Start()
416415
time.Sleep(100 * time.Millisecond)
417-
_, err := load(c, fixtures.PluginPath, "mock.asc")
416+
_, err := load(c, fixtures.PluginPathMock2, "mock.asc")
418417
Convey("so error on loading a signed plugin should be nil", func() {
419418
So(err, ShouldBeNil)
420419
})
@@ -430,7 +429,7 @@ func TestLoadWithSignedPlugins(t *testing.T) {
430429
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
431430
c.Start()
432431
time.Sleep(100 * time.Millisecond)
433-
_, err := load(c, fixtures.PluginPath)
432+
_, err := load(c, fixtures.PluginPathMock2)
434433
Convey("so error on loading an unsigned plugin should be nil", func() {
435434
So(err, ShouldBeNil)
436435
})
@@ -443,14 +442,14 @@ func TestLoadWithSignedPlugins(t *testing.T) {
443442
c.signingManager = &mocksigningManager{signed: false}
444443
c.Start()
445444
time.Sleep(100 * time.Millisecond)
446-
_, err := load(c, fixtures.PluginPath)
445+
_, err := load(c, fixtures.PluginPathMock2)
447446
Convey("so error should not be nil when loading an unsigned plugin with trust enabled", func() {
448447
So(err, ShouldNotBeNil)
449448
})
450449
c.Stop()
451450
})
452451
} else {
453-
fmt.Printf("SNAP_PATH not set. Cannot test %s plugin.\n", fixtures.PluginName)
452+
fmt.Printf("SNAP_PATH not set. Cannot test %s plugin.\n", fixtures.PluginNameMock2)
454453
}
455454
}
456455

@@ -464,7 +463,7 @@ func TestUnload(t *testing.T) {
464463
c.eventManager.RegisterHandler("TestUnload", lpe)
465464
c.Start()
466465
time.Sleep(100 * time.Millisecond)
467-
_, e := load(c, fixtures.PluginPath)
466+
_, e := load(c, fixtures.PluginPathMock2)
468467
Convey("Loading a plugin to test unload", t, func() {
469468
Convey("Should not error", func() {
470469
So(e, ShouldBeNil)
@@ -516,7 +515,7 @@ func TestUnload(t *testing.T) {
516515
c.Stop()
517516
time.Sleep(100 * time.Millisecond)
518517
} else {
519-
fmt.Printf("SNAP_PATH not set. Cannot test %s plugin.\n", fixtures.PluginName)
518+
fmt.Printf("SNAP_PATH not set. Cannot test %s plugin.\n", fixtures.PluginNameMock2)
520519
}
521520
}
522521

@@ -770,7 +769,7 @@ func TestMetricConfig(t *testing.T) {
770769
c.Start()
771770
lpe := newListenToPluginEvent()
772771
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
773-
_, err := load(c, fixtures.JSONRPCPluginPath)
772+
_, err := load(c, fixtures.PluginPathMock1)
774773
So(err, ShouldBeNil)
775774
<-lpe.done
776775

@@ -805,7 +804,7 @@ func TestMetricConfig(t *testing.T) {
805804
c.Start()
806805
lpe := newListenToPluginEvent()
807806
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
808-
_, err := load(c, fixtures.JSONRPCPluginPath)
807+
_, err := load(c, fixtures.PluginPathMock1)
809808
So(err, ShouldBeNil)
810809
<-lpe.done
811810
m1 := fixtures.MockMetricType{
@@ -829,7 +828,7 @@ func TestMetricConfig(t *testing.T) {
829828
c.Start()
830829
lpe := newListenToPluginEvent()
831830
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
832-
_, err := load(c, fixtures.JSONRPCPluginPath)
831+
_, err := load(c, fixtures.PluginPathMock1)
833832
So(err, ShouldBeNil)
834833
<-lpe.done
835834

@@ -854,7 +853,7 @@ func TestMetricConfig(t *testing.T) {
854853
c.Start()
855854
lpe := newListenToPluginEvent()
856855
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
857-
_, err := load(c, fixtures.JSONRPCPluginPath)
856+
_, err := load(c, fixtures.PluginPathMock1)
858857
So(err, ShouldBeNil)
859858
<-lpe.done
860859
m1 := fixtures.MockMetricType{
@@ -878,7 +877,7 @@ func TestRoutingCachingStrategy(t *testing.T) {
878877
c.Start()
879878
lpe := newListenToPluginEvent()
880879
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
881-
_, e := load(c, fixtures.PluginPath)
880+
_, e := load(c, fixtures.PluginPathMock2)
882881
So(e, ShouldBeNil)
883882
if e != nil {
884883
t.FailNow()
@@ -948,7 +947,7 @@ func TestRoutingCachingStrategy(t *testing.T) {
948947
)
949948
lpe := newListenToPluginEvent()
950949
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
951-
_, e := load(c, fixtures.JSONRPCPluginPath)
950+
_, e := load(c, fixtures.PluginPathMock1)
952951
So(e, ShouldBeNil)
953952
if e != nil {
954953
t.FailNow()
@@ -1028,8 +1027,8 @@ func TestCollectDynamicMetrics(t *testing.T) {
10281027
So(strategy.GlobalCacheExpiration, ShouldResemble, time.Second*1)
10291028
lpe := newListenToPluginEvent()
10301029
c.eventManager.RegisterHandler("Control.PluginLoaded", lpe)
1031-
_, e := load(c, fixtures.PluginPath)
1032-
Convey("Loading native client plugin", func() {
1030+
_, e := load(c, fixtures.PluginPathMock2)
1031+
Convey("Loading the first native client plugin", func() {
10331032
Convey("Should not error", func() {
10341033
So(e, ShouldBeNil)
10351034
})
@@ -1038,8 +1037,9 @@ func TestCollectDynamicMetrics(t *testing.T) {
10381037
t.FailNow()
10391038
}
10401039
<-lpe.done
1041-
_, e = load(c, fixtures.JSONRPCPluginPath)
1042-
Convey("Loading JSONRPC client plugin", func() {
1040+
1041+
_, e = load(c, fixtures.PluginPathMock1)
1042+
Convey("Loading the second native client plugin", func() {
10431043
Convey("Should not error", func() {
10441044
So(e, ShouldBeNil)
10451045
})
@@ -1126,7 +1126,7 @@ func TestFailedPlugin(t *testing.T) {
11261126
c.Config.Plugins.All.AddItem("password", ctypes.ConfigValueStr{Value: "testval"})
11271127

11281128
// Load plugin
1129-
_, e := load(c, fixtures.PluginPath)
1129+
_, e := load(c, fixtures.PluginPathMock2)
11301130
So(e, ShouldBeNil)
11311131
<-lpe.done
11321132
_, err := c.MetricCatalog()
@@ -1210,7 +1210,7 @@ func TestCollectMetrics(t *testing.T) {
12101210
c.Config.Plugins.Collector.Plugins["mock"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))
12111211

12121212
// Load plugin
1213-
_, e := load(c, fixtures.JSONRPCPluginPath)
1213+
_, e := load(c, fixtures.PluginPathMock1)
12141214
So(e, ShouldBeNil)
12151215
<-lpe.done
12161216
mts, err := c.MetricCatalog()
@@ -1304,7 +1304,7 @@ func TestCollectNonSpecifiedDynamicMetrics(t *testing.T) {
13041304
c.Config.Plugins.Collector.Plugins["mock"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))
13051305

13061306
// Load plugin
1307-
_, e := load(c, fixtures.JSONRPCPluginPath)
1307+
_, e := load(c, fixtures.PluginPathMock1)
13081308
So(e, ShouldBeNil)
13091309
<-lpe.done
13101310
mts, err := c.MetricCatalog()
@@ -1387,7 +1387,7 @@ func TestCollectSpecifiedDynamicMetrics(t *testing.T) {
13871387
c.Start()
13881388

13891389
// Load plugin
1390-
_, e := load(c, fixtures.JSONRPCPluginPath)
1390+
_, e := load(c, fixtures.PluginPathMock1)
13911391
So(e, ShouldBeNil)
13921392

13931393
mts, err := c.MetricCatalog()

control/fixtures/fixtures.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ import (
3030
)
3131

3232
var (
33-
PluginName = "snap-plugin-collector-mock2"
34-
SnapPath = helper.BuildPath
35-
PluginPath = helper.PluginFilePath(PluginName)
33+
SnapPath = helper.BuildPath
3634

37-
JSONRPCPluginName = "snap-plugin-collector-mock1"
38-
JSONRPCPluginPath = helper.PluginFilePath(JSONRPCPluginName)
35+
PluginNameMock1 = "snap-plugin-collector-mock1"
36+
PluginPathMock1 = helper.PluginFilePath(PluginNameMock1)
37+
38+
PluginNameMock2 = "snap-plugin-collector-mock2"
39+
PluginPathMock2 = helper.PluginFilePath(PluginNameMock2)
3940
)
4041

4142
// mocks a metric type

control/plugin_manager_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestLoadPlugin(t *testing.T) {
102102
Convey("loads plugin successfully", func() {
103103
p := newPluginManager()
104104
p.SetMetricCatalog(newMetricCatalog())
105-
lp, err := loadPlugin(p, fixtures.PluginPath)
105+
lp, err := loadPlugin(p, fixtures.PluginPathMock2)
106106

107107
So(lp, ShouldHaveSameTypeAs, new(loadedPlugin))
108108
So(p.all(), ShouldNotBeEmpty)
@@ -115,7 +115,7 @@ func TestLoadPlugin(t *testing.T) {
115115
cfg.Plugins.Collector.Plugins["mock"] = newPluginConfigItem(optAddPluginConfigItem("test", ctypes.ConfigValueBool{Value: true}))
116116
p := newPluginManager(OptSetPluginConfig(cfg.Plugins))
117117
p.SetMetricCatalog(newMetricCatalog())
118-
lp, serr := loadPlugin(p, fixtures.PluginPath)
118+
lp, serr := loadPlugin(p, fixtures.PluginPathMock2)
119119

120120
So(lp, ShouldHaveSameTypeAs, new(loadedPlugin))
121121
So(p.all(), ShouldNotBeEmpty)
@@ -135,7 +135,7 @@ func TestLoadPlugin(t *testing.T) {
135135
cfg.Plugins.Collector.Plugins["mock"] = newPluginConfigItem(optAddPluginConfigItem("test-fail", ctypes.ConfigValueBool{Value: true}))
136136
p := newPluginManager(OptSetPluginConfig(cfg.Plugins))
137137
p.SetMetricCatalog(newMetricCatalog())
138-
lp, err := loadPlugin(p, fixtures.PluginPath)
138+
lp, err := loadPlugin(p, fixtures.PluginPathMock2)
139139

140140
So(lp, ShouldBeNil)
141141
So(p.all(), ShouldBeEmpty)
@@ -144,10 +144,10 @@ func TestLoadPlugin(t *testing.T) {
144144
So(len(p.all()), ShouldEqual, 0)
145145
})
146146

147-
Convey("loads json-rpc plugin successfully", func() {
147+
Convey("loads native-rpc plugin successfully", func() {
148148
p := newPluginManager()
149149
p.SetMetricCatalog(newMetricCatalog())
150-
lp, err := loadPlugin(p, fixtures.JSONRPCPluginPath)
150+
lp, err := loadPlugin(p, fixtures.PluginPathMock1)
151151

152152
So(lp, ShouldHaveSameTypeAs, new(loadedPlugin))
153153
So(p.loadedPlugins, ShouldNotBeEmpty)
@@ -158,7 +158,7 @@ func TestLoadPlugin(t *testing.T) {
158158
Convey("loads plugin with cache TTL set", func() {
159159
p := newPluginManager()
160160
p.SetMetricCatalog(newMetricCatalog())
161-
lp, err := loadPlugin(p, fixtures.JSONRPCPluginPath)
161+
lp, err := loadPlugin(p, fixtures.PluginPathMock1)
162162

163163
So(err, ShouldBeNil)
164164
So(lp.Meta.CacheTTL, ShouldNotBeNil)
@@ -178,7 +178,7 @@ func TestUnloadPlugin(t *testing.T) {
178178
Convey("then it is removed from the loadedPlugins", func() {
179179
p := newPluginManager()
180180
p.SetMetricCatalog(newMetricCatalog())
181-
_, err := loadPlugin(p, fixtures.PluginPath)
181+
_, err := loadPlugin(p, fixtures.PluginPathMock2)
182182
So(err, ShouldBeNil)
183183

184184
numPluginsLoaded := len(p.all())
@@ -195,7 +195,7 @@ func TestUnloadPlugin(t *testing.T) {
195195
Convey("then an error is thrown", func() {
196196
p := newPluginManager()
197197
p.SetMetricCatalog(newMetricCatalog())
198-
lp, err := loadPlugin(p, fixtures.PluginPath)
198+
lp, err := loadPlugin(p, fixtures.PluginPathMock2)
199199
glp, err2 := p.get("collector" + core.Separator + "mock" + core.Separator + "2")
200200
So(err2, ShouldBeNil)
201201
glp.State = DetectedState
@@ -208,7 +208,7 @@ func TestUnloadPlugin(t *testing.T) {
208208
Convey("then an error is thrown", func() {
209209
p := newPluginManager()
210210
p.SetMetricCatalog(newMetricCatalog())
211-
_, err := loadPlugin(p, fixtures.PluginPath)
211+
_, err := loadPlugin(p, fixtures.PluginPathMock2)
212212

213213
lp, err2 := p.get("collector" + core.Separator + "mock" + core.Separator + "2")
214214
So(err2, ShouldBeNil)

0 commit comments

Comments
 (0)