-
Notifications
You must be signed in to change notification settings - Fork 3
/
app_test.go
107 lines (94 loc) · 2.72 KB
/
app_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package integration_test
import (
"bytes"
"context"
"os"
"path/filepath"
"strings"
"testing"
pluginsconfig "github.com/ignite/cli/v28/ignite/config/plugins"
"github.com/ignite/cli/v28/ignite/pkg/cmdrunner/step"
"github.com/ignite/cli/v28/ignite/pkg/errors"
"github.com/ignite/cli/v28/ignite/services/plugin"
envtest "github.com/ignite/cli/v28/integration"
"github.com/stretchr/testify/require"
)
func TestHealthMonitor(t *testing.T) {
var (
require = require.New(t)
env = envtest.New(t)
app = env.Scaffold("github.com/apps/health-monitor")
servers = app.RandomizeServerPorts()
ctx, cancel = context.WithCancel(env.Ctx())
)
dir, err := os.Getwd()
require.NoError(err)
pluginPath := filepath.Join(filepath.Dir(filepath.Dir(dir)), "health-monitor")
env.Must(env.Exec("install health-monitor app locally",
step.NewSteps(step.New(
step.Exec(envtest.IgniteApp, "app", "install", pluginPath),
step.Workdir(app.SourcePath()),
)),
))
// One local plugin expected
assertLocalPlugins(t, app, []pluginsconfig.Plugin{{Path: pluginPath}})
assertGlobalPlugins(t, nil)
var (
isRetrieved bool
got string
output = &bytes.Buffer{}
)
steps := step.NewSteps(
step.New(
step.Stderr(output),
step.Workdir(app.SourcePath()),
step.PreExec(func() error {
return env.IsAppServed(ctx, servers.API)
}),
step.Exec(
envtest.IgniteApp,
"health-monitor",
"monitor",
"--rpc-address", servers.RPC,
"--refresh-duration", "1s",
"--close-after", "2s",
),
step.PostExec(func(execErr error) error {
if execErr != nil {
return execErr
}
got = output.String()
if !strings.Contains(got, "Chain ID: healthmonitor") {
return errors.Errorf("invalid output: %s", got)
}
return nil
}),
),
)
go func() {
defer cancel()
isRetrieved = env.Exec("run health-monitor", steps, envtest.ExecRetry())
}()
env.Must(app.Serve("should serve", envtest.ExecCtx(ctx)))
if !isRetrieved {
t.FailNow()
}
require.Contains(got, "Chain ID: healthmonitor")
require.Contains(got, "Version:")
require.Contains(got, "Height:")
require.Contains(got, "Latest Block Hash:")
}
func assertLocalPlugins(t *testing.T, app envtest.App, expectedPlugins []pluginsconfig.Plugin) {
t.Helper()
cfg, err := pluginsconfig.ParseDir(app.SourcePath())
require.NoError(t, err)
require.ElementsMatch(t, expectedPlugins, cfg.Apps, "unexpected local apps")
}
func assertGlobalPlugins(t *testing.T, expectedPlugins []pluginsconfig.Plugin) {
t.Helper()
cfgPath, err := plugin.PluginsPath()
require.NoError(t, err)
cfg, err := pluginsconfig.ParseDir(cfgPath)
require.NoError(t, err)
require.ElementsMatch(t, expectedPlugins, cfg.Apps, "unexpected global apps")
}