-
Notifications
You must be signed in to change notification settings - Fork 169
/
shared_resource.go
46 lines (37 loc) · 1.12 KB
/
shared_resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
}{}