Skip to content

Commit

Permalink
set global workspace path only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Dec 4, 2021
1 parent cfd7883 commit 96c6434
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions test/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package test
import (
"testing"

"github.com/mantil-io/mantil/domain"
"github.com/mantil-io/mantil/kit/clitest"
)

func TestBeforeActivation(t *testing.T) {
createNewWorkspaceWithoutToken(t)
workspacePath := createNewWorkspaceWithoutToken(t)

r := clitest.New(t)
r := clitest.New(t).Env(domain.EnvWorkspacePath, workspacePath)
r.Run("mantil", "--help").Success()
r.Run("mantil", "aws", "install", "--help").Success()

Expand Down
23 changes: 13 additions & 10 deletions test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ func setup() int {
// it will be used instead of creating new
// to speed up startup
if !defaultNodeExists() {
if err := createNewWorkspace(); err != nil {
workspacePath, err := createNewWorkspace()
if err != nil {
panic(err)
}
os.Setenv(domain.EnvWorkspacePath, workspacePath)
fmt.Printf("workspace path %s\n", workspacePath)

// create default node in the new workspace
t := &testingT{}
Expand Down Expand Up @@ -109,24 +112,24 @@ func defaultNodeExists() bool {
return false
}

func createNewWorkspaceWithoutToken(t *testing.T) {
func createNewWorkspaceWithoutToken(t *testing.T) string {
workspacePath, err := ioutil.TempDir("", "mantil-workspace-")
require.NoError(t, err)
os.Setenv(domain.EnvWorkspacePath, workspacePath)
//os.Setenv(domain.EnvWorkspacePath, workspacePath)
return workspacePath
}

func createNewWorkspace() error {
func createNewWorkspace() (string, error) {
workspacePath, err := ioutil.TempDir("", "mantil-workspace-")
if err != nil {
return err
return "", err
}

os.Setenv(domain.EnvWorkspacePath, workspacePath)
fmt.Printf("workspace path %s\n", workspacePath)

// create and store activation token for this workspace
jwt := secret.TokenForTests(domain.MachineID())
return domain.StoreActivationTokenTo(jwt, workspacePath)
if err := domain.StoreActivationTokenTo(jwt, workspacePath); err != nil {
return "", err
}
return workspacePath, nil
}

func newClitest(t *testing.T) *clitest.Env {
Expand Down

0 comments on commit 96c6434

Please sign in to comment.