-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package acc | |
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
) | ||
|
@@ -37,3 +38,8 @@ func RandomIP(a, b, c byte) string { | |
func RandomEmail() string { | ||
return fmt.Sprintf("%s-%[email protected]", prefixName, acctest.RandString(10)) | ||
} | ||
|
||
func ProjectIDGlobal(tb testing.TB) string { | ||
tb.Helper() | ||
return projectID(tb, prefixProjectKeep+"-global") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package acc | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func SetupSharedResources() { | ||
sharedInfo.init = true | ||
} | ||
|
||
func CleanupSharedResources() { | ||
if sharedInfo.projectID != "" { | ||
fmt.Printf("Deleting execution project: %s, id: %s\n", sharedInfo.projectName, sharedInfo.projectID) | ||
deleteProject(sharedInfo.projectID) | ||
} | ||
} | ||
|
||
// ProjectIDExecution returns a project id created for the execution of the tests in the resource package. | ||
func ProjectIDExecution(tb testing.TB) string { | ||
tb.Helper() | ||
SkipInUnitTest(tb) | ||
require.True(tb, sharedInfo.init, "SetupSharedResources must called from TestMain test package") | ||
|
||
sharedInfo.mu.Lock() | ||
defer sharedInfo.mu.Unlock() | ||
|
||
// lazy creation so it's only done if really needed | ||
if sharedInfo.projectID == "" { | ||
sharedInfo.projectName = RandomProjectName() | ||
tb.Logf("Creating execution project: %s, id: %s\n", sharedInfo.projectName, sharedInfo.projectID) | ||
sharedInfo.projectID = createProject(tb, sharedInfo.projectName) | ||
} | ||
|
||
return sharedInfo.projectID | ||
} | ||
|
||
var sharedInfo = struct { | ||
projectID string | ||
projectName string | ||
mu sync.Mutex | ||
init bool | ||
}{} |