diff --git a/port/resource_port_entity_test.go b/port/resource_port_entity_test.go index 84a95c8d..4c34b8a9 100644 --- a/port/resource_port_entity_test.go +++ b/port/resource_port_entity_test.go @@ -1,6 +1,7 @@ package port import ( + "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -8,28 +9,49 @@ import ( ) func TestAccPortEntityUpdateProp(t *testing.T) { - var testAccActionConfigCreate = ` + identifier := genID() + var testAccActionConfigCreate = fmt.Sprintf(` provider "port-labs" {} + resource "port-labs_blueprint" "tf_bp" { + title = "TF Provider Test" + icon = "Terraform" + identifier = "%s" + properties { + identifier = "text" + type = "string" + title = "text" + } + } resource "port-labs_entity" "microservice" { title = "monolith" - blueprint = "tf-provider-test-bp" + blueprint = port-labs_blueprint.tf_bp.id properties { name = "text" value = "hedwig" } } -` - var testAccActionConfigUpdate = ` +`, identifier) + var testAccActionConfigUpdate = fmt.Sprintf(` provider "port-labs" {} + resource "port-labs_blueprint" "tf_bp" { + title = "TF Provider Test" + icon = "Terraform" + identifier = "%s" + properties { + identifier = "text" + type = "string" + title = "text" + } + } resource "port-labs_entity" "microservice" { title = "monolith" - blueprint = "tf-provider-test-bp" + blueprint = port-labs_blueprint.tf_bp.id properties { name = "text" value = "hedwig2" } } -` +`, identifier) resource.Test(t, resource.TestCase{ Providers: map[string]*schema.Provider{ "port-labs": Provider(), @@ -47,8 +69,39 @@ func TestAccPortEntityUpdateProp(t *testing.T) { } func TestAccPortEntity(t *testing.T) { - var testAccActionConfigCreate = ` + identifier := genID() + var testAccActionConfigCreate = fmt.Sprintf(` provider "port-labs" {} + resource "port-labs_blueprint" "microservice" { + title = "TF Provider Test BP0" + icon = "Terraform" + identifier = "%s" + properties { + identifier = "text" + type = "string" + title = "text" + } + properties { + identifier = "bool" + type = "boolean" + title = "boolean" + } + properties { + identifier = "num" + type = "number" + title = "number" + } + properties { + identifier = "obj" + type = "object" + title = "object" + } + properties { + identifier = "arr" + type = "array" + title = "array" + } + } resource "port-labs_entity" "microservice" { title = "monolith" blueprint = "tf-provider-test-bp" @@ -73,7 +126,7 @@ func TestAccPortEntity(t *testing.T) { value = jsonencode({"a":"b"}) } } -` +`, identifier) resource.Test(t, resource.TestCase{ Providers: map[string]*schema.Provider{ "port-labs": Provider(), @@ -87,11 +140,38 @@ func TestAccPortEntity(t *testing.T) { } func TestAccPortEntitiesRelation(t *testing.T) { - var testAccActionConfigCreate = ` + identifier1 := genID() + identifier2 := genID() + var testAccActionConfigCreate = fmt.Sprintf(` provider "port-labs" {} + resource "port-labs_blueprint" "microservice" { + title = "TF Provider Test BP0" + icon = "Terraform" + identifier = "%s" + properties { + identifier = "text" + type = "string" + title = "text" + } + relations { + identifier = "tf-relation" + title = "Test Relation" + target = port-labs_blueprint.microservice2.identifier + } + } + resource "port-labs_blueprint" "microservice2" { + title = "TF Provider Test BP0" + icon = "Terraform" + identifier = "%s" + properties { + identifier = "str" + type = "string" + title = "text" + } + } resource "port-labs_entity" "microservice" { title = "monolith" - blueprint = "tf-provider-test-bp" + blueprint = port-labs_blueprint.microservice.id relations { name = "tf-relation" identifier = port-labs_entity.microservice2.id @@ -103,13 +183,13 @@ func TestAccPortEntitiesRelation(t *testing.T) { } resource "port-labs_entity" "microservice2" { title = "monolith2" - blueprint = "tf-provider-test-bp2" + blueprint = port-labs_blueprint.microservice2.id properties { name = "str" value = "test-relation" } } -` +`, identifier1, identifier2) resource.Test(t, resource.TestCase{ Providers: map[string]*schema.Provider{ "port-labs": Provider(),