Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ignite
GitHub Repository: ignite/cli
Path: blob/main/integration/plugin/plugin_test.go
1007 views
1
package plugin_test
2
3
import (
4
"path/filepath"
5
"testing"
6
7
"github.com/stretchr/testify/assert"
8
"github.com/stretchr/testify/require"
9
10
pluginsconfig "github.com/ignite/cli/v29/ignite/config/plugins"
11
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step"
12
"github.com/ignite/cli/v29/ignite/services/plugin"
13
envtest "github.com/ignite/cli/v29/integration"
14
)
15
16
func TestAddRemovePlugin(t *testing.T) {
17
var (
18
require = require.New(t)
19
assert = assert.New(t)
20
env = envtest.New(t)
21
app = env.ScaffoldApp("github.com/test/blog")
22
23
assertPlugins = func(expectedLocalPlugins, expectedGlobalPlugins []pluginsconfig.Plugin) {
24
localCfg, err := pluginsconfig.ParseDir(app.SourcePath())
25
require.NoError(err)
26
assert.ElementsMatch(expectedLocalPlugins, localCfg.Apps, "unexpected local plugins")
27
28
globalCfgPath, err := plugin.PluginsPath()
29
require.NoError(err)
30
globalCfg, err := pluginsconfig.ParseDir(globalCfgPath)
31
require.NoError(err)
32
assert.ElementsMatch(expectedGlobalPlugins, globalCfg.Apps, "unexpected global plugins")
33
}
34
)
35
36
// no plugins expected
37
assertPlugins(nil, nil)
38
39
// Note: Originally plugin repo was "github.com/ignite/example-plugin" instead of a local one
40
pluginRepo, err := filepath.Abs("testdata/example-plugin")
41
require.NoError(err)
42
43
env.Must(env.Exec("add plugin locally",
44
step.NewSteps(step.New(
45
step.Exec(envtest.IgniteApp, "app", "install", pluginRepo, "k1=v1", "k2=v2"),
46
step.Workdir(app.SourcePath()),
47
)),
48
))
49
50
// one local plugin expected
51
assertPlugins(
52
[]pluginsconfig.Plugin{
53
{
54
Path: pluginRepo,
55
With: map[string]string{
56
"k1": "v1",
57
"k2": "v2",
58
},
59
},
60
},
61
nil,
62
)
63
64
env.Must(env.Exec("uninstall plugin locally",
65
step.NewSteps(step.New(
66
step.Exec(envtest.IgniteApp, "app", "uninstall", pluginRepo),
67
step.Workdir(app.SourcePath()),
68
)),
69
))
70
71
// no plugins expected
72
assertPlugins(nil, nil)
73
74
env.Must(env.Exec("install plugin globally",
75
step.NewSteps(step.New(
76
step.Exec(envtest.IgniteApp, "app", "install", pluginRepo, "-g"),
77
step.Workdir(app.SourcePath()),
78
)),
79
))
80
81
// one global plugins expected
82
assertPlugins(
83
nil,
84
[]pluginsconfig.Plugin{
85
{
86
Path: pluginRepo,
87
},
88
},
89
)
90
91
env.Must(env.Exec("uninstall plugin globally",
92
step.NewSteps(step.New(
93
step.Exec(envtest.IgniteApp, "app", "uninstall", pluginRepo, "-g"),
94
step.Workdir(app.SourcePath()),
95
)),
96
))
97
98
// no plugins expected
99
assertPlugins(nil, nil)
100
}
101
102
// TODO install network plugin test
103
104
func TestPluginScaffold(t *testing.T) {
105
env := envtest.New(t)
106
107
env.Must(env.Exec("install a plugin",
108
step.NewSteps(step.New(
109
step.Exec(envtest.IgniteApp, "app", "scaffold", "test"),
110
step.Workdir(env.TmpDir()),
111
)),
112
))
113
}
114
115