diff --git a/cmd/world/root/root_test.go b/cmd/world/root/root_test.go index 62f91e2..f721369 100644 --- a/cmd/world/root/root_test.go +++ b/cmd/world/root/root_test.go @@ -116,11 +116,17 @@ func TestCreateStartStopRestartPurge(t *testing.T) { // set tea ouput to variable teaOut := &bytes.Buffer{} createCmd := getCreateCmd(teaOut) - createCmd.SetArgs([]string{gameDir}) + // checkout the repo + sgtDir := gameDir + "/sgt" + createCmd.SetArgs([]string{sgtDir}) err = createCmd.Execute() assert.NilError(t, err) + // Change dir + err = os.Chdir(sgtDir) + assert.NilError(t, err) + // Start cardinal rootCmd.SetArgs([]string{"cardinal", "start", "--detach", "--editor=false"}) err = rootCmd.Execute() @@ -173,6 +179,9 @@ func TestDev(t *testing.T) { createCmd := getCreateCmd(teaOut) createCmd.SetArgs([]string{gameDir}) + // checkout the repo + sgtDir := gameDir + "/sgt" + createCmd.SetArgs([]string{sgtDir}) err = createCmd.Execute() assert.NilError(t, err) @@ -280,6 +289,9 @@ func TestEVMStart(t *testing.T) { createCmd := getCreateCmd(teaOut) createCmd.SetArgs([]string{gameDir}) + // checkout the repo + sgtDir := gameDir + "/sgt" + createCmd.SetArgs([]string{sgtDir}) err = createCmd.Execute() assert.NilError(t, err) diff --git a/common/docker/client_test.go b/common/docker/client_test.go index 2ad21e2..4159870 100644 --- a/common/docker/client_test.go +++ b/common/docker/client_test.go @@ -180,9 +180,11 @@ func TestBuild(t *testing.T) { err = os.Chdir(dir) assert.NilError(t, err) + sgtDir := dir + "/sgt" + // Pull the repository templateGitURL := "https://github.com/Argus-Labs/starter-game-template.git" - err = teacmd.GitCloneCmd(templateGitURL, dir, "Initial commit from World CLI") + err = teacmd.GitCloneCmd(templateGitURL, sgtDir, "Initial commit from World CLI") assert.NilError(t, err) // Preparation @@ -190,7 +192,7 @@ func TestBuild(t *testing.T) { DockerEnv: map[string]string{ "CARDINAL_NAMESPACE": cardinalNamespace, }, - RootDir: dir, + RootDir: sgtDir, } cardinalService := service.Cardinal(cfg) ctx := context.Background() diff --git a/common/teacmd/git.go b/common/teacmd/git.go index 5a613be..b5d4135 100644 --- a/common/teacmd/git.go +++ b/common/teacmd/git.go @@ -47,6 +47,12 @@ func git(args ...string) (string, error) { } func GitCloneCmd(url string, targetDir string, initMsg string) error { + // check targetDir exists + if _, err := os.Stat(targetDir); err == nil { + return eris.Errorf("Game shard named '%s' already exists in this directory, "+ + "please change the directory or use another name", targetDir) + } + _, err := git("clone", url, targetDir) if err != nil { return err