Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): execute from function #3899

Merged
merged 10 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

- [#3835](https://github.com/ignite/cli/pull/3835) Add `--minimal` flag to `scaffold chain` to scaffold a chain with the least amount of sdk modules


### Changes

- [#3899](https://github.com/ignite/cli/pull/3899) Introduce plugin.Execute function
jeronimoalbi marked this conversation as resolved.
Show resolved Hide resolved

## [`v28.1.1`](https://github.com/ignite/cli/releases/tag/v28.1.1)

### Fixes
Expand Down
21 changes: 21 additions & 0 deletions ignite/services/plugin/internal/execute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package plugininternal

import (
"context"

pluginsconfig "github.com/ignite/cli/v28/ignite/config/plugins"
"github.com/ignite/cli/v28/ignite/services/plugin"
)

// Execute starts and executes a plugin, then shutdowns it.
func Execute(ctx context.Context, path string, args ...string) error {
plugins, err := plugin.Load(ctx, []pluginsconfig.Plugin{{Path: path}})
if err != nil {
return err
}

Check warning on line 15 in ignite/services/plugin/internal/execute.go

View check run for this annotation

Codecov / codecov/patch

ignite/services/plugin/internal/execute.go#L14-L15

Added lines #L14 - L15 were not covered by tests
defer plugins[0].KillClient()
if plugins[0].Error != nil {
return plugins[0].Error
}
return plugins[0].Interface.Execute(ctx, &plugin.ExecutedCommand{Args: args}, plugin.NewClientAPI())
jeronimoalbi marked this conversation as resolved.
Show resolved Hide resolved
}
47 changes: 47 additions & 0 deletions ignite/services/plugin/internal/execute_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package plugininternal

import (
"context"
"testing"

"github.com/stretchr/testify/require"

"github.com/ignite/cli/v28/ignite/services/plugin"
)

func TestPluginExecute(t *testing.T) {
tests := []struct {
name string
scaffoldPlugin func(t *testing.T) string
expectedError string
}{
{
name: "fail: plugin doesnt exist",
scaffoldPlugin: func(t *testing.T) string {
return "/not/exists"
},
expectedError: "local app path \"/not/exists\" not found: stat /not/exists: no such file or directory",
},
{
name: "ok: plugin exists",
scaffoldPlugin: func(t *testing.T) string {
path, err := plugin.Scaffold(context.Background(), t.TempDir(), "foo", false)
require.NoError(t, err)
return path
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path := tt.scaffoldPlugin(t)

err := Execute(context.Background(), path, "args")

if tt.expectedError != "" {
require.EqualError(t, err, tt.expectedError)
return
}
require.NoError(t, err)
})
}
}
Loading