Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions integration/app/cmd_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions integration/app/cmd_proto_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 13 additions & 19 deletions integration/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand Down Expand Up @@ -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.
Expand All @@ -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"
}
20 changes: 19 additions & 1 deletion integration/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
Loading