Skip to content

Commit

Permalink
Panic if plugin root implements delete
Browse files Browse the repository at this point in the history
Signed-off-by: Enis Inan <[email protected]>
  • Loading branch information
ekinanp committed Oct 22, 2019
1 parent 1328e4b commit c493521
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugin/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (r *Registry) RegisterPlugin(root Root, config map[string]interface{}) erro
msg := fmt.Sprintf("r.RegisterPlugin: the %v plugin's already been registered", root.name())
panic(msg)
}

if DeleteAction().IsSupportedOn(root) {
msg := fmt.Sprintf("r.RegisterPlugin: the %v plugin's root implements delete", root.name())
panic(msg)
}
}

r.plugins[root.name()] = root
Expand Down
22 changes: 22 additions & 0 deletions plugin/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ func (suite *RegistryTestSuite) TestRegisterPluginRegisteredPlugin() {
suite.Panics(panicFunc, "r.RegisterPlugin: the mine plugin's already been registered")
}

type mockRootWithDelete struct {
*mockRoot
}

func (m *mockRootWithDelete) Delete(ctx context.Context) error {
return nil
}

func (suite *RegistryTestSuite) TestRegisterPluginPluginRootImplementsDelete() {
panicFunc := func() {
reg := NewRegistry()
m := &mockRootWithDelete{
mockRoot: &mockRoot{
EntryBase: NewEntry("mine"),
},
}
_ = reg.RegisterPlugin(m, map[string]interface{}{})
}

suite.Panics(panicFunc, "r.RegisterPlugin: the mine plugin's root implements delete")
}

func TestRegistry(t *testing.T) {
suite.Run(t, new(RegistryTestSuite))
}

0 comments on commit c493521

Please sign in to comment.