/
atlas.go
39 lines (34 loc) · 1.09 KB
/
atlas.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
package acc
import (
"context"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/require"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
)
func createProject(tb testing.TB, name string) string {
tb.Helper()
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
require.NotNil(tb, "Project creation failed: %s, org not set", name)
params := &admin.Group{Name: name, OrgId: orgID}
resp, _, err := ConnV2().ProjectsApi.CreateProject(context.Background(), params).Execute()
require.NoError(tb, err, "Project creation failed: %s, err: %s", name, err)
id := resp.GetId()
require.NotEmpty(tb, id, "Project creation failed: %s", name)
return id
}
func deleteProject(id string) {
_, _, err := ConnV2().ProjectsApi.DeleteProject(context.Background(), id).Execute()
if err != nil {
fmt.Printf("Project deletion failed: %s, error: %s", id, err)
}
}
func projectID(tb testing.TB, name string) string {
tb.Helper()
SkipInUnitTest(tb)
resp, _, _ := ConnV2().ProjectsApi.GetProjectByName(context.Background(), name).Execute()
id := resp.GetId()
require.NotEmpty(tb, id, "Project name not found: %s", name)
return id
}