diff --git a/integration/app/cmd_app_test.go b/integration/app/cmd_app_test.go index df23d4269d..7bac73ce94 100644 --- a/integration/app/cmd_app_test.go +++ b/integration/app/cmd_app_test.go @@ -17,6 +17,8 @@ import ( // TestGenerateAnApp tests scaffolding a new chain. func TestGenerateAnApp(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("github.com/test/blog") @@ -30,6 +32,8 @@ func TestGenerateAnApp(t *testing.T) { // TestGenerateAnAppMinimal tests scaffolding a new minimal chain. func TestGenerateAnAppMinimal(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("blog", "--minimal") @@ -43,6 +47,8 @@ func TestGenerateAnAppMinimal(t *testing.T) { // TestGenerateAnAppWithName tests scaffolding a new chain using a local name instead of a GitHub URI. func TestGenerateAnAppWithName(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("blog") @@ -56,6 +62,8 @@ func TestGenerateAnAppWithName(t *testing.T) { // TestGenerateAnAppWithInvalidName tests scaffolding a new chain using an invalid name. func TestGenerateAnAppWithInvalidName(t *testing.T) { + t.Parallel() + buf := new(bytes.Buffer) env := envtest.New(t) @@ -72,6 +80,8 @@ func TestGenerateAnAppWithInvalidName(t *testing.T) { } func TestGenerateAnAppWithNoDefaultModule(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("github.com/test/blog", "--no-module") @@ -84,6 +94,8 @@ func TestGenerateAnAppWithNoDefaultModule(t *testing.T) { } func TestGenerateAnAppWithNoDefaultModuleAndCreateAModule(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("github.com/test/blog", "--no-module") @@ -99,6 +111,8 @@ func TestGenerateAnAppWithNoDefaultModuleAndCreateAModule(t *testing.T) { } func TestGenerateAppWithEmptyModule(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("github.com/test/blog") @@ -174,6 +188,8 @@ func TestGenerateAppWithEmptyModule(t *testing.T) { } func TestGenerateAnAppWithAddressPrefix(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("github.com/test/blog", "--address-prefix=gm", "--coin-type=60") @@ -198,6 +214,8 @@ func TestGenerateAnAppWithAddressPrefix(t *testing.T) { } func TestGenerateAnAppWithDefaultDenom(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("github.com/test/blog", "--default-denom=good") @@ -218,6 +236,8 @@ func TestGenerateAnAppWithDefaultDenom(t *testing.T) { } func TestScaffoldModuleWithUnderscoreAppName(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("github.com/test/space_chain") diff --git a/integration/app/cmd_proto_path_test.go b/integration/app/cmd_proto_path_test.go index 4e1f109d12..72f4eea9b2 100644 --- a/integration/app/cmd_proto_path_test.go +++ b/integration/app/cmd_proto_path_test.go @@ -58,6 +58,8 @@ var ( ) func TestChangeProtoPath(t *testing.T) { + t.Parallel() + var ( env = envtest.New(t) app = env.ScaffoldApp("github.com/test/protopath", "--proto-dir", newProtoPath) diff --git a/integration/env.go b/integration/env.go index 72767c4377..a35d79f27e 100644 --- a/integration/env.go +++ b/integration/env.go @@ -16,7 +16,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ignite/cli/v29/ignite/pkg/cosmosfaucet" - "github.com/ignite/cli/v29/ignite/pkg/env" "github.com/ignite/cli/v29/ignite/pkg/errors" "github.com/ignite/cli/v29/ignite/pkg/gocmd" "github.com/ignite/cli/v29/ignite/pkg/httpstatuschecker" @@ -40,23 +39,26 @@ var ( // Env provides an isolated testing environment and what's needed to // make it possible. type Env struct { - t *testing.T - ctx context.Context + t *testing.T + ctx context.Context + configDir string + homeDir string } // New creates a new testing environment. func New(t *testing.T) Env { t.Helper() ctx, cancel := context.WithCancel(t.Context()) + cfgDir := path.Join(t.TempDir(), ".ignite") + homeDir := path.Join(t.TempDir(), ".home") + require.NoError(t, os.MkdirAll(homeDir, 0o755)) + e := Env{ - t: t, - ctx: ctx, + t: t, + ctx: ctx, + configDir: cfgDir, + homeDir: homeDir, } - // To avoid conflicts with the default config folder located in $HOME, we - // set an other one thanks to env var. - cfgDir := path.Join(t.TempDir(), ".ignite") - env.SetConfigDir(cfgDir) - enableDoNotTrackEnv(t) t.Cleanup(cancel) compileBinaryOnce.Do(func() { @@ -141,9 +143,7 @@ func (e Env) TmpDir() (path string) { // Home returns user's home dir. func (e Env) Home() string { - home, err := os.UserHomeDir() - require.NoError(e.t, err) - return home + return e.homeDir } // AppHome returns app's root home/data dir path. @@ -167,12 +167,6 @@ func (e Env) RequireExpectations() { e.Must(e.HasFailed()) } -// enableDoNotTrackEnv set true the DO_NOT_TRACK env var. -func enableDoNotTrackEnv(t *testing.T) { - t.Helper() - t.Setenv(envDoNotTrack, "true") -} - func HasTestVerboseFlag() bool { return flag.Lookup("test.v").Value.String() == "true" } diff --git a/integration/exec.go b/integration/exec.go index 02d1fd11f3..8cbc6495a5 100644 --- a/integration/exec.go +++ b/integration/exec.go @@ -12,6 +12,7 @@ import ( "github.com/ignite/cli/v29/ignite/pkg/cmdrunner" "github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step" + "github.com/ignite/cli/v29/ignite/pkg/env" "github.com/ignite/cli/v29/ignite/pkg/errors" ) @@ -84,9 +85,26 @@ func (e Env) Exec(msg string, steps step.Steps, options ...ExecOption) (ok bool) if IsCI { copts = append(copts, cmdrunner.EndSignal(os.Kill)) } + defaultEnvs := []string{ + fmt.Sprintf("%s=true", envDoNotTrack), + } + if e.configDir != "" { + defaultEnvs = append(defaultEnvs, fmt.Sprintf("%s=%s", env.ConfigDirEnvVar, e.configDir)) + } + preparedSteps := make(step.Steps, 0, len(steps)) + for _, s := range steps { + if s == nil { + preparedSteps = append(preparedSteps, nil) + continue + } + cloned := *s + cloned.Env = append(append([]string{}, defaultEnvs...), s.Env...) + preparedSteps = append(preparedSteps, &cloned) + } + err := cmdrunner. New(copts...). - Run(opts.ctx, steps...) + Run(opts.ctx, preparedSteps...) if errors.Is(err, context.Canceled) { err = nil }