Skip to content

Commit 22456fd

Browse files
committed
chore: increase the integration tests speed
1 parent 40af7a2 commit 22456fd

4 files changed

Lines changed: 54 additions & 20 deletions

File tree

integration/app/cmd_app_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717

1818
// TestGenerateAnApp tests scaffolding a new chain.
1919
func TestGenerateAnApp(t *testing.T) {
20+
t.Parallel()
21+
2022
var (
2123
env = envtest.New(t)
2224
app = env.ScaffoldApp("github.com/test/blog")
@@ -30,6 +32,8 @@ func TestGenerateAnApp(t *testing.T) {
3032

3133
// TestGenerateAnAppMinimal tests scaffolding a new minimal chain.
3234
func TestGenerateAnAppMinimal(t *testing.T) {
35+
t.Parallel()
36+
3337
var (
3438
env = envtest.New(t)
3539
app = env.ScaffoldApp("blog", "--minimal")
@@ -43,6 +47,8 @@ func TestGenerateAnAppMinimal(t *testing.T) {
4347

4448
// TestGenerateAnAppWithName tests scaffolding a new chain using a local name instead of a GitHub URI.
4549
func TestGenerateAnAppWithName(t *testing.T) {
50+
t.Parallel()
51+
4652
var (
4753
env = envtest.New(t)
4854
app = env.ScaffoldApp("blog")
@@ -56,6 +62,8 @@ func TestGenerateAnAppWithName(t *testing.T) {
5662

5763
// TestGenerateAnAppWithInvalidName tests scaffolding a new chain using an invalid name.
5864
func TestGenerateAnAppWithInvalidName(t *testing.T) {
65+
t.Parallel()
66+
5967
buf := new(bytes.Buffer)
6068

6169
env := envtest.New(t)
@@ -72,6 +80,8 @@ func TestGenerateAnAppWithInvalidName(t *testing.T) {
7280
}
7381

7482
func TestGenerateAnAppWithNoDefaultModule(t *testing.T) {
83+
t.Parallel()
84+
7585
var (
7686
env = envtest.New(t)
7787
app = env.ScaffoldApp("github.com/test/blog", "--no-module")
@@ -84,6 +94,8 @@ func TestGenerateAnAppWithNoDefaultModule(t *testing.T) {
8494
}
8595

8696
func TestGenerateAnAppWithNoDefaultModuleAndCreateAModule(t *testing.T) {
97+
t.Parallel()
98+
8799
var (
88100
env = envtest.New(t)
89101
app = env.ScaffoldApp("github.com/test/blog", "--no-module")
@@ -99,6 +111,8 @@ func TestGenerateAnAppWithNoDefaultModuleAndCreateAModule(t *testing.T) {
99111
}
100112

101113
func TestGenerateAppWithEmptyModule(t *testing.T) {
114+
t.Parallel()
115+
102116
var (
103117
env = envtest.New(t)
104118
app = env.ScaffoldApp("github.com/test/blog")
@@ -174,6 +188,8 @@ func TestGenerateAppWithEmptyModule(t *testing.T) {
174188
}
175189

176190
func TestGenerateAnAppWithAddressPrefix(t *testing.T) {
191+
t.Parallel()
192+
177193
var (
178194
env = envtest.New(t)
179195
app = env.ScaffoldApp("github.com/test/blog", "--address-prefix=gm", "--coin-type=60")
@@ -198,6 +214,8 @@ func TestGenerateAnAppWithAddressPrefix(t *testing.T) {
198214
}
199215

200216
func TestGenerateAnAppWithDefaultDenom(t *testing.T) {
217+
t.Parallel()
218+
201219
var (
202220
env = envtest.New(t)
203221
app = env.ScaffoldApp("github.com/test/blog", "--default-denom=good")
@@ -218,6 +236,8 @@ func TestGenerateAnAppWithDefaultDenom(t *testing.T) {
218236
}
219237

220238
func TestScaffoldModuleWithUnderscoreAppName(t *testing.T) {
239+
t.Parallel()
240+
221241
var (
222242
env = envtest.New(t)
223243
app = env.ScaffoldApp("github.com/test/space_chain")

integration/app/cmd_proto_path_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ var (
5858
)
5959

6060
func TestChangeProtoPath(t *testing.T) {
61+
t.Parallel()
62+
6163
var (
6264
env = envtest.New(t)
6365
app = env.ScaffoldApp("github.com/test/protopath", "--proto-dir", newProtoPath)

integration/env.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/stretchr/testify/require"
1717

1818
"github.com/ignite/cli/v29/ignite/pkg/cosmosfaucet"
19-
"github.com/ignite/cli/v29/ignite/pkg/env"
2019
"github.com/ignite/cli/v29/ignite/pkg/errors"
2120
"github.com/ignite/cli/v29/ignite/pkg/gocmd"
2221
"github.com/ignite/cli/v29/ignite/pkg/httpstatuschecker"
@@ -40,23 +39,26 @@ var (
4039
// Env provides an isolated testing environment and what's needed to
4140
// make it possible.
4241
type Env struct {
43-
t *testing.T
44-
ctx context.Context
42+
t *testing.T
43+
ctx context.Context
44+
configDir string
45+
homeDir string
4546
}
4647

4748
// New creates a new testing environment.
4849
func New(t *testing.T) Env {
4950
t.Helper()
5051
ctx, cancel := context.WithCancel(t.Context())
52+
cfgDir := path.Join(t.TempDir(), ".ignite")
53+
homeDir := path.Join(t.TempDir(), ".home")
54+
require.NoError(t, os.MkdirAll(homeDir, 0o755))
55+
5156
e := Env{
52-
t: t,
53-
ctx: ctx,
57+
t: t,
58+
ctx: ctx,
59+
configDir: cfgDir,
60+
homeDir: homeDir,
5461
}
55-
// To avoid conflicts with the default config folder located in $HOME, we
56-
// set an other one thanks to env var.
57-
cfgDir := path.Join(t.TempDir(), ".ignite")
58-
env.SetConfigDir(cfgDir)
59-
enableDoNotTrackEnv(t)
6062

6163
t.Cleanup(cancel)
6264
compileBinaryOnce.Do(func() {
@@ -141,9 +143,7 @@ func (e Env) TmpDir() (path string) {
141143

142144
// Home returns user's home dir.
143145
func (e Env) Home() string {
144-
home, err := os.UserHomeDir()
145-
require.NoError(e.t, err)
146-
return home
146+
return e.homeDir
147147
}
148148

149149
// AppHome returns app's root home/data dir path.
@@ -167,12 +167,6 @@ func (e Env) RequireExpectations() {
167167
e.Must(e.HasFailed())
168168
}
169169

170-
// enableDoNotTrackEnv set true the DO_NOT_TRACK env var.
171-
func enableDoNotTrackEnv(t *testing.T) {
172-
t.Helper()
173-
t.Setenv(envDoNotTrack, "true")
174-
}
175-
176170
func HasTestVerboseFlag() bool {
177171
return flag.Lookup("test.v").Value.String() == "true"
178172
}

integration/exec.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner"
1414
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step"
15+
"github.com/ignite/cli/v29/ignite/pkg/env"
1516
"github.com/ignite/cli/v29/ignite/pkg/errors"
1617
)
1718

@@ -84,9 +85,26 @@ func (e Env) Exec(msg string, steps step.Steps, options ...ExecOption) (ok bool)
8485
if IsCI {
8586
copts = append(copts, cmdrunner.EndSignal(os.Kill))
8687
}
88+
defaultEnvs := []string{
89+
fmt.Sprintf("%s=true", envDoNotTrack),
90+
}
91+
if e.configDir != "" {
92+
defaultEnvs = append(defaultEnvs, fmt.Sprintf("%s=%s", env.ConfigDirEnvVar, e.configDir))
93+
}
94+
preparedSteps := make(step.Steps, 0, len(steps))
95+
for _, s := range steps {
96+
if s == nil {
97+
preparedSteps = append(preparedSteps, nil)
98+
continue
99+
}
100+
cloned := *s
101+
cloned.Env = append(append([]string{}, defaultEnvs...), s.Env...)
102+
preparedSteps = append(preparedSteps, &cloned)
103+
}
104+
87105
err := cmdrunner.
88106
New(copts...).
89-
Run(opts.ctx, steps...)
107+
Run(opts.ctx, preparedSteps...)
90108
if errors.Is(err, context.Canceled) {
91109
err = nil
92110
}

0 commit comments

Comments
 (0)