Skip to content

Commit

Permalink
[SQUASH] correct schema
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzaadi committed May 30, 2024
1 parent 3a4058d commit a373e61
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 104 deletions.
170 changes: 85 additions & 85 deletions port/integration/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/port-labs/terraform-provider-port-labs/v2/internal/utils"
)

func createBlueprint(identifier string) string {
func createIntegration(identifier string) string {
return fmt.Sprintf(`
resource "port_blueprint" "microservice" {
resource "port_integration" "microservice" {
identifier = "%s"
title = "TF Provider Test"
icon = "Terraform"
Expand All @@ -23,10 +23,10 @@ resource "port_blueprint" "microservice" {
`, identifier)
}

func createBlueprintWithProperties(identifier string) string {
func createIntegrationWithProperties(identifier string) string {
return fmt.Sprintf(`
resource "port_blueprint" "microservice" {
resource "port_integration" "microservice" {
identifier = "%s"
title = "TF Provider Test"
icon = "Terraform"
Expand Down Expand Up @@ -55,18 +55,18 @@ resource "port_blueprint" "microservice" {
`, identifier)
}

func TestAccPortBlueprintPermissionsBasic(t *testing.T) {
blueprintIdentifier := utils.GenID()
func TestAccPortIntegrationPermissionsBasic(t *testing.T) {
integrationIdentifier := utils.GenID()
err := os.Setenv("PORT_BETA_FEATURES_ENABLED", "true")
if err != nil {
t.Fatal(err)
}
var testAccPortBlueprintResourceBasic = createBlueprint(blueprintIdentifier)
var testAccPortIntegrationResourceBasic = createIntegration(integrationIdentifier)

var testAccBaseBlueprintPermissionsConfigUpdate = `
var testAccBaseIntegrationPermissionsConfigUpdate = `
resource "port_blueprint_permissions" "microservice_permissions" {
blueprint_identifier = port_blueprint.microservice.identifier
resource "port_integration_permissions" "microservice_permissions" {
integration_identifier = port_integration.microservice.identifier
entities = {
"register" = {
"roles": [
Expand Down Expand Up @@ -127,45 +127,45 @@ func TestAccPortBlueprintPermissionsBasic(t *testing.T) {
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccPortBlueprintResourceBasic,
Config: testAccPortIntegrationResourceBasic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintIdentifier),
resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationIdentifier),
resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"),
),
},
{
Config: testAccPortBlueprintResourceBasic + testAccBaseBlueprintPermissionsConfigUpdate,
Config: testAccPortIntegrationResourceBasic + testAccBaseIntegrationPermissionsConfigUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintIdentifier),
resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "blueprint_identifier", blueprintIdentifier),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "id", blueprintIdentifier),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.#", "1"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.0", "Member"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.users.#", "0"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.teams.#", "0"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_metadata_properties.icon.roles.#", "1"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_metadata_properties.icon.roles.0", "Member"),
resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationIdentifier),
resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "integration_identifier", integrationIdentifier),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "id", integrationIdentifier),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.#", "1"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.0", "Member"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.users.#", "0"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.teams.#", "0"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_metadata_properties.icon.roles.#", "1"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_metadata_properties.icon.roles.0", "Member"),
),
},
},
})
}

func TestAccPortBlueprintPermissionsWithProperties(t *testing.T) {
blueprintIdentifier := utils.GenID()
func TestAccPortIntegrationPermissionsWithProperties(t *testing.T) {
integrationIdentifier := utils.GenID()
err := os.Setenv("PORT_BETA_FEATURES_ENABLED", "true")
if err != nil {
t.Fatal(err)
}
var testAccPortBlueprintResourceBasic = createBlueprintWithProperties(blueprintIdentifier)
var testAccPortIntegrationResourceBasic = createIntegrationWithProperties(integrationIdentifier)

var testAccBaseBlueprintPermissionsConfigUpdate = `
var testAccBaseIntegrationPermissionsConfigUpdate = `
resource "port_blueprint_permissions" "microservice_permissions" {
blueprint_identifier = port_blueprint.microservice.identifier
resource "port_integration_permissions" "microservice_permissions" {
integration_identifier = port_integration.microservice.identifier
entities = {
"register" = {
"roles": [
Expand Down Expand Up @@ -233,41 +233,41 @@ func TestAccPortBlueprintPermissionsWithProperties(t *testing.T) {
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccPortBlueprintResourceBasic,
Config: testAccPortIntegrationResourceBasic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintIdentifier),
resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationIdentifier),
resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"),
),
},
{
Config: testAccPortBlueprintResourceBasic + testAccBaseBlueprintPermissionsConfigUpdate,
Config: testAccPortIntegrationResourceBasic + testAccBaseIntegrationPermissionsConfigUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintIdentifier),
resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "blueprint_identifier", blueprintIdentifier),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "id", blueprintIdentifier),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.#", "1"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.0", "Member"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.users.#", "0"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.teams.#", "0"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_properties.myStringIdentifier.roles.#", "1"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_properties.myStringIdentifier.roles.0", "Member"),
resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationIdentifier),
resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "integration_identifier", integrationIdentifier),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "id", integrationIdentifier),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.#", "1"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.0", "Member"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.users.#", "0"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.teams.#", "0"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_properties.myStringIdentifier.roles.#", "1"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_properties.myStringIdentifier.roles.0", "Member"),
)},
},
})
}

func TestAccPortBlueprintPermissionsWithRelations(t *testing.T) {
blueprintMicroserviceIdentifier := utils.GenID()
blueprintEnvIdentifier := utils.GenID()
func TestAccPortIntegrationPermissionsWithRelations(t *testing.T) {
integrationMicroserviceIdentifier := utils.GenID()
integrationEnvIdentifier := utils.GenID()
err := os.Setenv("PORT_BETA_FEATURES_ENABLED", "true")
if err != nil {
t.Fatal(err)
}
var testAccPortBlueprintResourceBasic = fmt.Sprintf(`
resource "port_blueprint" "environment" {
var testAccPortIntegrationResourceBasic = fmt.Sprintf(`
resource "port_integration" "environment" {
title = "Environment"
icon = "Environment"
identifier = "%s"
Expand All @@ -286,7 +286,7 @@ resource "port_blueprint" "environment" {
}
resource "port_blueprint" "microservice" {
resource "port_integration" "microservice" {
identifier = "%s"
title = "TF Provider Test"
icon = "Terraform"
Expand All @@ -295,23 +295,23 @@ resource "port_blueprint" "microservice" {
"environment" = {
title = "Test Relation"
required = "true"
target = port_blueprint.environment.identifier
target = port_integration.environment.identifier
}
}
}
`, blueprintEnvIdentifier, blueprintMicroserviceIdentifier)
`, integrationEnvIdentifier, integrationMicroserviceIdentifier)

teamName := utils.GenID()
var testAccBaseBlueprintPermissionsConfigUpdate = fmt.Sprintf(`
var testAccBaseIntegrationPermissionsConfigUpdate = fmt.Sprintf(`
resource "port_team" "team" {
name = "%s"
description = "Test description"
users = []
}
resource "port_blueprint_permissions" "microservice_permissions" {
blueprint_identifier = port_blueprint.microservice.identifier
resource "port_integration_permissions" "microservice_permissions" {
integration_identifier = port_integration.microservice.identifier
entities = {
"register" = {
"roles": [
Expand Down Expand Up @@ -381,54 +381,54 @@ resource "port_blueprint" "microservice" {
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccPortBlueprintResourceBasic,
Config: testAccPortIntegrationResourceBasic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_blueprint.environment", "identifier", blueprintEnvIdentifier),
resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintMicroserviceIdentifier),
resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_integration.environment", "identifier", integrationEnvIdentifier),
resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationMicroserviceIdentifier),
resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"),
),
},
{
Config: testAccPortBlueprintResourceBasic + testAccBaseBlueprintPermissionsConfigUpdate,
Config: testAccPortIntegrationResourceBasic + testAccBaseIntegrationPermissionsConfigUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintMicroserviceIdentifier),
resource.TestCheckResourceAttr("port_blueprint.environment", "identifier", blueprintEnvIdentifier),
resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "blueprint_identifier", blueprintMicroserviceIdentifier),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "id", blueprintMicroserviceIdentifier),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.#", "1"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.0", "Member"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.teams.#", "1"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.teams.0", teamName),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.users.#", "0"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_relations.environment.roles.#", "1"),
resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_relations.environment.roles.0", "Member"),
resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationMicroserviceIdentifier),
resource.TestCheckResourceAttr("port_integration.environment", "identifier", integrationEnvIdentifier),
resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "integration_identifier", integrationMicroserviceIdentifier),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "id", integrationMicroserviceIdentifier),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.#", "1"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.0", "Member"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.teams.#", "1"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.teams.0", teamName),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.users.#", "0"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_relations.environment.roles.#", "1"),
resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_relations.environment.roles.0", "Member"),
)},
},
})
}

func TestAccPortBlueprintPermissionsWithInvalidProperties(t *testing.T) {
blueprintIdentifier := utils.GenID()
func TestAccPortIntegrationPermissionsWithInvalidProperties(t *testing.T) {
integrationIdentifier := utils.GenID()
err := os.Setenv("PORT_BETA_FEATURES_ENABLED", "true")
if err != nil {
t.Fatal(err)
}
var testAccPortBlueprintResourceBasic = createBlueprintWithProperties(blueprintIdentifier)
var testAccPortIntegrationResourceBasic = createIntegrationWithProperties(integrationIdentifier)

teamName := utils.GenID()
var testAccBaseBlueprintPermissionsConfigUpdate = fmt.Sprintf(`
var testAccBaseIntegrationPermissionsConfigUpdate = fmt.Sprintf(`
resource "port_team" "team" {
name = "%s"
description = "Test description"
users = []
}
resource "port_blueprint_permissions" "microservice_permissions" {
blueprint_identifier = port_blueprint.microservice.identifier
resource "port_integration_permissions" "microservice_permissions" {
integration_identifier = port_integration.microservice.identifier
entities = {
"register" = {
"roles": [
Expand Down Expand Up @@ -496,7 +496,7 @@ func TestAccPortBlueprintPermissionsWithInvalidProperties(t *testing.T) {
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccPortBlueprintResourceBasic + testAccBaseBlueprintPermissionsConfigUpdate,
Config: testAccPortIntegrationResourceBasic + testAccBaseIntegrationPermissionsConfigUpdate,
ExpectError: regexp.MustCompile("Invalid Attribute Value Match"),
},
},
Expand Down
Loading

0 comments on commit a373e61

Please sign in to comment.