Skip to content

Commit 0330930

Browse files
committed
access token in tests
1 parent e55c705 commit 0330930

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

internal/provider/provider_authentication_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
func TestAccSTSAssumeRole_basic(t *testing.T) {
1313
acc.SkipInPAK(t, "skipping as this test is for AWS credentials only")
1414
acc.SkipInSA(t, "skipping as this test is for AWS credentials only")
15+
acc.SkipInAccessToken(t, "skipping as this test is for AWS credentials only")
1516
var (
1617
resourceName = "mongodbatlas_project.test"
1718
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
@@ -44,6 +45,7 @@ func TestAccSTSAssumeRole_basic(t *testing.T) {
4445

4546
func TestAccServiceAccount_basic(t *testing.T) {
4647
acc.SkipInPAK(t, "skipping as this test is for SA only")
48+
acc.SkipInAccessToken(t, "skipping as this test is for SA only")
4749
var (
4850
resourceName = "data.mongodbatlas_organization.test"
4951
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")

internal/service/project/resource_project_migration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func TestMigProject_withLimits(t *testing.T) {
154154
// based on bug report: https://github.com/mongodb/terraform-provider-mongodbatlas/issues/2263
155155
func TestMigGovProject_regionUsageRestrictionsDefault(t *testing.T) {
156156
acc.SkipInSA(t, "SA not supported in Gov tests yet")
157+
acc.SkipInAccessToken(t, "SA not supported in Gov tests yet")
157158
var (
158159
orgID = os.Getenv("MONGODB_ATLAS_GOV_ORG_ID")
159160
projectName = acc.RandomProjectName()

internal/service/project/resource_project_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ func TestAccProject_basic(t *testing.T) {
639639

640640
func TestAccGovProject_withProjectOwner(t *testing.T) {
641641
acc.SkipInSA(t, "SA not supported in Gov tests yet")
642+
acc.SkipInAccessToken(t, "SA not supported in Gov tests yet")
642643
var (
643644
orgID = os.Getenv("MONGODB_ATLAS_GOV_ORG_ID")
644645
projectOwnerID = os.Getenv("MONGODB_ATLAS_GOV_PROJECT_OWNER_ID")

internal/testutil/acc/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func init() {
6161
PrivateKey: os.Getenv("MONGODB_ATLAS_PRIVATE_KEY"),
6262
ClientID: os.Getenv("MONGODB_ATLAS_CLIENT_ID"),
6363
ClientSecret: os.Getenv("MONGODB_ATLAS_CLIENT_SECRET"),
64+
AccessToken: os.Getenv("MONGODB_ATLAS_ACCESS_TOKEN"),
6465
BaseURL: os.Getenv("MONGODB_ATLAS_BASE_URL"),
6566
RealmBaseURL: os.Getenv("MONGODB_REALM_BASE_URL"),
6667
}

internal/testutil/acc/pre_check.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ func PreCheckBasic(tb testing.TB) {
1414
if os.Getenv("MONGODB_ATLAS_ORG_ID") == "" {
1515
tb.Fatal("`MONGODB_ATLAS_ORG_ID` must be set for acceptance testing")
1616
}
17-
if HasPAKCreds() && HasSACreds() {
18-
tb.Fatal("PAK and SA credentials are defined in this test but only one should be set.")
17+
authCount := 0
18+
if HasPAKCreds() {
19+
authCount++
1920
}
20-
if !HasPAKCreds() && !HasSACreds() {
21-
tb.Fatal("No credentials are defined in this test, PAK or SA credentials should be set.")
21+
if HasSACreds() {
22+
authCount++
23+
}
24+
if HasAccessToken() {
25+
authCount++
26+
}
27+
if authCount > 1 {
28+
tb.Fatal("Multiple credentials are set (PAK, SA, Access Token) but only one should be set.")
29+
}
30+
if authCount == 0 {
31+
tb.Fatal("No credentials are set, one of PAK, SA, or Access Token should be set.")
2232
}
2333
}
2434

internal/testutil/acc/skip.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func HasSACreds() bool {
4040
return os.Getenv("MONGODB_ATLAS_CLIENT_ID") != "" || os.Getenv("MONGODB_ATLAS_CLIENT_SECRET") != ""
4141
}
4242

43+
func HasAccessToken() bool {
44+
return os.Getenv("MONGODB_ATLAS_ACCESS_TOKEN") != ""
45+
}
46+
4347
func SkipInSA(tb testing.TB, description string) {
4448
tb.Helper()
4549
if HasSACreds() {
@@ -53,3 +57,10 @@ func SkipInPAK(tb testing.TB, description string) {
5357
tb.Skip(description)
5458
}
5559
}
60+
61+
func SkipInAccessToken(tb testing.TB, description string) {
62+
tb.Helper()
63+
if HasAccessToken() {
64+
tb.Skip(description)
65+
}
66+
}

0 commit comments

Comments
 (0)