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:
Krzesimir Nowak
2016-07-12 13:00:22 +02:00
parent 1f222b9156
commit ccd26fe69d
2 changed files with 22 additions and 2 deletions

View File

@@ -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

View File

@@ -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",