From 22aa3f3f497fecfbb25407e9589db70542627fcb Mon Sep 17 00:00:00 2001 From: Michael Frankel-Lopez Date: Wed, 10 Jul 2024 15:43:34 -0700 Subject: [PATCH] Adding test for Namespace Already Exists --- internal/provider/namespace_resource_test.go | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/provider/namespace_resource_test.go b/internal/provider/namespace_resource_test.go index a345155..abea8a1 100644 --- a/internal/provider/namespace_resource_test.go +++ b/internal/provider/namespace_resource_test.go @@ -1,6 +1,7 @@ package provider_test import ( + "regexp" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -50,3 +51,31 @@ resource "temporal_namespace" "test" { }, }) } + +func TestAccNamespaceAlreadyExsits(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create and Read testing + { + Config: providerConfig + ` + resource "temporal_namespace" "test1" { + name = "test" + description = "This is a test namespace" + owner_email = "test@example.org" + }`, + }, + // Namespace already exists Error + { + Config: providerConfig + ` + resource "temporal_namespace" "test2" { + name = "test" + description = "This is a test namespace" + owner_email = "test@example.org" + } + `, + ExpectError: regexp.MustCompile("namespace registration failed.*code = AlreadyExists"), + }, + }, + }) +}