-
Notifications
You must be signed in to change notification settings - Fork 557
/
Copy pathcmd_serve_test.go
106 lines (84 loc) · 2.54 KB
/
cmd_serve_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
//go:build !relayer
package chain_test
import (
"context"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/ignite/cli/v29/ignite/pkg/xos"
envtest "github.com/ignite/cli/v29/integration"
)
func TestServeWithCustomHome(t *testing.T) {
var (
env = envtest.New(t)
app = env.Scaffold("github.com/test/sgbloga")
servers = app.RandomizeServerPorts()
)
var (
ctx, cancel = context.WithTimeout(env.Ctx(), envtest.ServeTimeout)
isBackendAliveErr error
)
go func() {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers.API)
}()
env.Must(app.Serve("should serve", envtest.ExecCtx(ctx)))
require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
func TestServeWithConfigHome(t *testing.T) {
var (
env = envtest.New(t)
app = env.Scaffold("github.com/test/sgblogb")
servers = app.RandomizeServerPorts()
)
var (
ctx, cancel = context.WithTimeout(env.Ctx(), envtest.ServeTimeout)
isBackendAliveErr error
)
go func() {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers.API)
}()
env.Must(app.Serve("should serve", envtest.ExecCtx(ctx)))
require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
func TestServeWithCustomConfigFile(t *testing.T) {
tmpDir := t.TempDir()
var (
env = envtest.New(t)
app = env.Scaffold("github.com/test/sgblogc")
)
// Move config
newConfig := "new_config.yml"
newConfigPath := filepath.Join(tmpDir, newConfig)
err := xos.Rename(filepath.Join(app.SourcePath(), "config.yml"), newConfigPath)
require.NoError(t, err)
app.SetConfigPath(newConfigPath)
servers := app.RandomizeServerPorts()
var (
ctx, cancel = context.WithTimeout(env.Ctx(), envtest.ServeTimeout)
isBackendAliveErr error
)
go func() {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers.API)
}()
env.Must(app.Serve("should serve", envtest.ExecCtx(ctx)))
require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}
// TestServeWithName tests serving a new chain scaffolded using a local name instead of a GitHub URI.
func TestServeWithName(t *testing.T) {
var (
env = envtest.New(t)
app = env.Scaffold("sgblogd")
servers = app.RandomizeServerPorts()
)
ctx, cancel := context.WithTimeout(env.Ctx(), envtest.ServeTimeout)
var isBackendAliveErr error
go func() {
defer cancel()
isBackendAliveErr = env.IsAppServed(ctx, servers.API)
}()
env.Must(app.Serve("should serve", envtest.ExecCtx(ctx)))
require.NoError(t, isBackendAliveErr, "app cannot get online in time")
}