mukan-ignite/integration/plugin/plugin_test.go
Mukan Erkin Törük c32551b6f7
Some checks failed
Docs Deploy / build_and_deploy (push) Has been cancelled
Generate Docs / cli (push) Has been cancelled
Generate Config Doc / cli (push) Has been cancelled
Go formatting / go-formatting (push) Has been cancelled
Check links / markdown-link-check (push) Has been cancelled
Integration / pre-test (push) Has been cancelled
Integration / test on (push) Has been cancelled
Integration / status (push) Has been cancelled
Lint / Lint Go code (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
refactor: replace all github.com upstream refs with git.cw.tr/mukan-network
2026-05-11 03:36:24 +03:00

113 lines
2.7 KiB
Go

package plugin_test
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
pluginsconfig "git.cw.tr/mukan-network/mukan-ignite/ignite/config/plugins"
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/cmdrunner/step"
"git.cw.tr/mukan-network/mukan-ignite/ignite/services/plugin"
envtest "git.cw.tr/mukan-network/mukan-ignite/integration"
)
func TestAddRemovePlugin(t *testing.T) {
var (
require = require.New(t)
assert = assert.New(t)
env = envtest.New(t)
app = env.ScaffoldApp("github.com/test/blog")
assertPlugins = func(expectedLocalPlugins, expectedGlobalPlugins []pluginsconfig.Plugin) {
localCfg, err := pluginsconfig.ParseDir(app.SourcePath())
require.NoError(err)
assert.ElementsMatch(expectedLocalPlugins, localCfg.Apps, "unexpected local plugins")
globalCfgPath, err := plugin.PluginsPath()
require.NoError(err)
globalCfg, err := pluginsconfig.ParseDir(globalCfgPath)
require.NoError(err)
assert.ElementsMatch(expectedGlobalPlugins, globalCfg.Apps, "unexpected global plugins")
}
)
// no plugins expected
assertPlugins(nil, nil)
// Note: Originally plugin repo was "github.com/ignite/example-plugin" instead of a local one
pluginRepo, err := filepath.Abs("testdata/example-plugin")
require.NoError(err)
env.Must(env.Exec("add plugin locally",
step.NewSteps(step.New(
step.Exec(envtest.IgniteApp, "app", "install", pluginRepo, "k1=v1", "k2=v2"),
step.Workdir(app.SourcePath()),
)),
))
// one local plugin expected
assertPlugins(
[]pluginsconfig.Plugin{
{
Path: pluginRepo,
With: map[string]string{
"k1": "v1",
"k2": "v2",
},
},
},
nil,
)
env.Must(env.Exec("uninstall plugin locally",
step.NewSteps(step.New(
step.Exec(envtest.IgniteApp, "app", "uninstall", pluginRepo),
step.Workdir(app.SourcePath()),
)),
))
// no plugins expected
assertPlugins(nil, nil)
env.Must(env.Exec("install plugin globally",
step.NewSteps(step.New(
step.Exec(envtest.IgniteApp, "app", "install", pluginRepo, "-g"),
step.Workdir(app.SourcePath()),
)),
))
// one global plugins expected
assertPlugins(
nil,
[]pluginsconfig.Plugin{
{
Path: pluginRepo,
},
},
)
env.Must(env.Exec("uninstall plugin globally",
step.NewSteps(step.New(
step.Exec(envtest.IgniteApp, "app", "uninstall", pluginRepo, "-g"),
step.Workdir(app.SourcePath()),
)),
))
// no plugins expected
assertPlugins(nil, nil)
}
// TODO install network plugin test
func TestPluginScaffold(t *testing.T) {
env := envtest.New(t)
env.Must(env.Exec("install a plugin",
step.NewSteps(step.New(
step.Exec(envtest.IgniteApp, "app", "scaffold", "test"),
step.Workdir(env.TmpDir()),
)),
))
}