Skip to content

Commit

Permalink
fix: plugin npe
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkYuan committed Mar 19, 2024
1 parent 1726f10 commit 90c4da5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func mockPlugin() {
mockey.Mock(modules.NewPlugin).To(func(key string) (*modules.Plugin, error) {
return &modules.Plugin{Module: &fakeModule{}}, nil
}).Build()
mockey.Mock((*modules.Plugin).KillPluginClient).Return().Build()
mockey.Mock((*modules.Plugin).KillPluginClient).Return(nil).Build()
}

func TestAppConfigurationGenerator_Generate_CustomNamespace(t *testing.T) {
Expand Down
9 changes: 6 additions & 3 deletions pkg/modules/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var PluginMap = map[string]plugin.Plugin{
}

type Plugin struct {
// key represents the module key, it consists of two parts: moduleName@version. e.g. "kusionstack/mysql@v0.1"
// key represents the module key, it consists of two parts: moduleName@version. e.g. "kusionstack/mysql@v0.1.0"
key string
client *plugin.Client
// Module represents the real module impl
Expand Down Expand Up @@ -126,9 +126,12 @@ func newPluginClient(path string) *plugin.Client {
return client
}

func (p *Plugin) KillPluginClient() {
// fixme: if p.client is nil, it will panic
func (p *Plugin) KillPluginClient() error {
if p.client == nil {
return fmt.Errorf("plugin: %s client is nil", p.key)
}
p.client.Kill()
return nil
}

func PluginDir() (string, error) {
Expand Down

0 comments on commit 90c4da5

Please sign in to comment.