mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-20 22:10:30 +00:00
Ban the possibility of changing plugin's ID
Changing plugin's ID only complicates control handling in plugins so let's ban it.
This commit is contained in:
@@ -257,6 +257,9 @@ func (p *Plugin) Report() (result report.Report, err error) {
|
||||
|
||||
key := result.Plugins.Keys()[0]
|
||||
spec, _ := result.Plugins.Lookup(key)
|
||||
if spec.ID != p.PluginSpec.ID {
|
||||
return result, fmt.Errorf("plugin must not change its id (is %q, should be %q)", spec.ID, p.PluginSpec.ID)
|
||||
}
|
||||
p.PluginSpec = spec
|
||||
|
||||
foundReporter := false
|
||||
|
||||
@@ -316,10 +316,17 @@ func TestRegistryUpdatesPluginsWhenTheyChange(t *testing.T) {
|
||||
checkLoadedPluginIDs(t, r.ForEach, []string{"testPlugin"})
|
||||
|
||||
// Update the plugin. Just change what the handler will respond with.
|
||||
resp = `{"Plugins":[{"id":"updatedPlugin","label":"updatedPlugin","interfaces":["reporter"]}]}`
|
||||
resp = `{"Plugins":[{"id":"testPlugin","label":"updatedPlugin","interfaces":["reporter"]}]}`
|
||||
|
||||
r.Report()
|
||||
checkLoadedPluginIDs(t, r.ForEach, []string{"updatedPlugin"})
|
||||
checkLoadedPlugins(t, r.ForEach, []xfer.PluginSpec{
|
||||
{
|
||||
ID: "testPlugin",
|
||||
Label: "updatedPlugin",
|
||||
Interfaces: []string{"reporter"},
|
||||
Status: "ok",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestRegistryReturnsPluginsByInterface(t *testing.T) {
|
||||
@@ -413,6 +420,11 @@ func TestRegistryRejectsErroneousPluginResponses(t *testing.T) {
|
||||
Name: "nonJSONResponseBody",
|
||||
Handler: stringHandler(http.StatusOK, `notJSON`),
|
||||
}.file(),
|
||||
mockPlugin{
|
||||
t: t,
|
||||
Name: "changedId",
|
||||
Handler: stringHandler(http.StatusOK, `{"Plugins":[{"id":"differentId","label":"changedId","interfaces":["reporter"]}]}`),
|
||||
}.file(),
|
||||
)
|
||||
defer restore(t)
|
||||
|
||||
@@ -425,6 +437,11 @@ func TestRegistryRejectsErroneousPluginResponses(t *testing.T) {
|
||||
|
||||
r.Report()
|
||||
checkLoadedPlugins(t, r.ForEach, []xfer.PluginSpec{
|
||||
{
|
||||
ID: "changedId",
|
||||
Label: "changedId",
|
||||
Status: `error: plugin must not change its id (is "differentId", should be "changedId")`,
|
||||
},
|
||||
{
|
||||
ID: "noInterface",
|
||||
Label: "noInterface",
|
||||
|
||||
Reference in New Issue
Block a user