Skip to content

Commit

Permalink
Chore: Update test workflow to use WARN logging; simplify test case f…
Browse files Browse the repository at this point in the history
…or environment user creation
  • Loading branch information
github-actions[bot] committed Nov 19, 2024
1 parent 448feba commit 6c24135
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 124 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
- name: Run tests
env:
TF_LOG: DEBUG
TF_LOG: WARN
TF_ACC: 1
POWER_PLATFORM_USE_OIDC: true
POWER_PLATFORM_TENANT_ID: ${{ secrets.ACCEPTANCE_TESTS_ENV_TENANT_ID }}
Expand All @@ -151,7 +151,7 @@ jobs:
ARM_SUBSCRIPTION_ID: ${{ secrets.ACCEPTANCE_TESTS_ENV_SUBSCRIPTION_ID }}
run: |
go clean -testcache
go test -p 3 -v ./... -run ^TestAccUserResource_Validate_Create_Environment_Dv$ -coverprofile=test-coverage.out -timeout 300m
go test -p 3 -v ./... -run ^Test -coverprofile=test-coverage.out -timeout 300m
go tool cover -html=test-coverage.out -o test-coverage.cov.html
- name: Upload Coverage Artifacts
Expand Down
122 changes: 0 additions & 122 deletions internal/services/authorization/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,128 +15,6 @@ import (
"github.com/microsoft/terraform-provider-power-platform/internal/mocks"
)

func TestAccUserResource_Validate_Create_Environment_Dv(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: mocks.TestAccProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"azuread": {
VersionConstraint: constants.AZURE_AD_PROVIDER_VERSION_CONSTRAINT,
Source: "hashicorp/azuread",
},
"random": {
VersionConstraint: constants.RANDOM_PROVIDER_VERSION_CONSTRAINT,
Source: "hashicorp/random",
},
},
Steps: []resource.TestStep{
{
ResourceName: "powerplatform_user.new_user",
Config: `
data "azuread_domains" "aad_domains" {
only_initial = true
}
locals {
domain_name = data.azuread_domains.aad_domains.domains[0].domain_name
}
resource "random_password" "passwords" {
min_lower = 1
min_upper = 1
min_numeric = 1
min_special = 1
length = 16
special = true
override_special = "_%@"
}
resource "azuread_user" "test_user" {
user_principal_name = "` + mocks.TestName() + `@${local.domain_name}"
display_name = "` + mocks.TestName() + `"
mail_nickname = "` + mocks.TestName() + `"
password = random_password.passwords.result
usage_location = "US"
}
resource "powerplatform_environment" "dataverse_user_example" {
display_name = "` + mocks.TestName() + `"
location = "unitedstates"
environment_type = "Sandbox"
}
resource "powerplatform_user" "new_user" {
environment_id = powerplatform_environment.dataverse_user_example.id
security_roles = [
"Environment Admin",
]
aad_id = element(split("/", azuread_user.test_user.id), 2)
}`,

Check: resource.ComposeAggregateTestCheckFunc(
resource.TestMatchResourceAttr("powerplatform_user.new_user", "id", regexp.MustCompile(helpers.GuidRegex)),
resource.TestMatchResourceAttr("powerplatform_user.new_user", "environment_id", regexp.MustCompile(helpers.GuidRegex)),
resource.TestMatchResourceAttr("powerplatform_user.new_user", "aad_id", regexp.MustCompile(helpers.GuidRegex)),
resource.TestCheckResourceAttr("powerplatform_user.new_user", "first_name", ""),
resource.TestCheckResourceAttr("powerplatform_user.new_user", "last_name", ""),

resource.TestCheckResourceAttr("powerplatform_user.new_user", "security_roles.#", "1"),
resource.TestCheckResourceAttr("powerplatform_user.new_user", "security_roles.0", "Environment Admin"),
),
},
{
ExpectError: regexp.MustCompile(".*Role with id 'Environment Admin' is not valid.*"),
ResourceName: "powerplatform_user.new_user",
Config: `
data "azuread_domains" "aad_domains" {
only_initial = true
}
locals {
domain_name = data.azuread_domains.aad_domains.domains[0].domain_name
}
resource "random_password" "passwords" {
min_lower = 1
min_upper = 1
min_numeric = 1
min_special = 1
length = 16
special = true
override_special = "_%@"
}
resource "azuread_user" "test_user" {
user_principal_name = "` + mocks.TestName() + `@${local.domain_name}"
display_name = "` + mocks.TestName() + `"
mail_nickname = "` + mocks.TestName() + `"
password = random_password.passwords.result
usage_location = "US"
}
resource "powerplatform_environment" "dataverse_user_example" {
display_name = "` + mocks.TestName() + `"
location = "unitedstates"
environment_type = "Sandbox"
dataverse = {
language_code = "1033"
currency_code = "USD"
security_group_id = "00000000-0000-0000-0000-000000000000"
}
}
resource "powerplatform_user" "new_user" {
environment_id = powerplatform_environment.dataverse_user_example.id
security_roles = [
"Environment Admin",
]
aad_id = element(split("/", azuread_user.test_user.id), 2)
}`,
Check: resource.ComposeAggregateTestCheckFunc(),
},
},
})
}

func TestAccUserResource_Validate_Create_Environment_User(t *testing.T) {
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: mocks.TestAccProtoV6ProviderFactories,
Expand Down

0 comments on commit 6c24135

Please sign in to comment.