Skip to content

Commit cb44413

Browse files
committed
adding prefix for tests to mark them for deletion
1 parent a2705a7 commit cb44413

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

internal/acctest/acctest.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818
"github.com/ory/terraform-provider-orynetwork/internal/provider"
1919
)
2020

21+
// Projects with names starting with this prefix are automatically purged by the e2e cleanup job.
22+
// DO NOT CHANGE THIS PREFIX - it must match the pattern in cloud/backoffice/backoffice/x/patterns.go
23+
const TestProjectNamePrefix = "ory-cy-e2e-da2f162d-af61-42dd-90dc-e3fcfa7c84a0"
24+
2125
// TestProject holds information about a test project created for acceptance tests.
2226
type TestProject struct {
2327
ID string
@@ -152,7 +156,7 @@ func createSharedProject(t *testing.T) {
152156
return
153157
}
154158

155-
projectName := fmt.Sprintf("tf-acc-test-%d", time.Now().UnixNano())
159+
projectName := fmt.Sprintf("%s-tf-%d", TestProjectNamePrefix, time.Now().UnixNano())
156160
t.Logf("Creating test project: %s (environment: prod)", projectName)
157161

158162
// Create as "prod" environment to support all features including organizations

internal/resources/project/resource_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"testing"
9+
"time"
910

1011
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1112

@@ -27,16 +28,17 @@ func testAccPreCheck(t *testing.T) {
2728
// WARNING: This test creates and deletes a real Ory project.
2829
// Only run this test if you have quota available and understand the implications.
2930
func TestAccProjectResource_basic(t *testing.T) {
31+
projectName := testProjectName("basic")
3032
acctest.RunTest(t, resource.TestCase{
3133
PreCheck: func() { testAccPreCheck(t) },
3234
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories(),
3335
Steps: []resource.TestStep{
3436
// Create and Read
3537
{
36-
Config: testAccProjectResourceConfig("tf-test-project", "dev"),
38+
Config: testAccProjectResourceConfig(projectName, "dev"),
3739
Check: resource.ComposeAggregateTestCheckFunc(
3840
resource.TestCheckResourceAttrSet("ory_project.test", "id"),
39-
resource.TestCheckResourceAttr("ory_project.test", "name", "tf-test-project"),
41+
resource.TestCheckResourceAttr("ory_project.test", "name", projectName),
4042
resource.TestCheckResourceAttr("ory_project.test", "environment", "dev"),
4143
resource.TestCheckResourceAttrSet("ory_project.test", "slug"),
4244
resource.TestCheckResourceAttr("ory_project.test", "state", "running"),
@@ -54,12 +56,13 @@ func TestAccProjectResource_basic(t *testing.T) {
5456

5557
// TestAccProjectResource_prodEnvironment tests creating a production project.
5658
func TestAccProjectResource_prodEnvironment(t *testing.T) {
59+
projectName := testProjectName("prod")
5760
acctest.RunTest(t, resource.TestCase{
5861
PreCheck: func() { testAccPreCheck(t) },
5962
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories(),
6063
Steps: []resource.TestStep{
6164
{
62-
Config: testAccProjectResourceConfig("tf-test-prod-project", "prod"),
65+
Config: testAccProjectResourceConfig(projectName, "prod"),
6366
Check: resource.ComposeAggregateTestCheckFunc(
6467
resource.TestCheckResourceAttrSet("ory_project.test", "id"),
6568
resource.TestCheckResourceAttr("ory_project.test", "environment", "prod"),
@@ -69,6 +72,11 @@ func TestAccProjectResource_prodEnvironment(t *testing.T) {
6972
})
7073
}
7174

75+
// testProjectName generates a project name with the e2e prefix for hard deletion support.
76+
func testProjectName(suffix string) string {
77+
return fmt.Sprintf("%s-tf-%s-%d", acctest.TestProjectNamePrefix, suffix, time.Now().UnixNano())
78+
}
79+
7280
func testAccProjectResourceConfig(name, environment string) string {
7381
return fmt.Sprintf(`
7482
provider "ory" {}

scripts/run-acceptance-tests.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ parse_curl_response() {
5454
# Configuration
5555
CONSOLE_API_URL="${ORY_CONSOLE_API_URL:-https://api.console.ory.sh}"
5656
PROJECT_API_URL="${ORY_PROJECT_API_URL:-https://%s.projects.oryapis.com}"
57-
PROJECT_NAME="tf-acc-test-$(date +%s)"
57+
58+
# Magic prefix that triggers hard deletion in the Ory Cloud backend.
59+
# Projects with names starting with this prefix are automatically purged by the e2e cleanup job.
60+
# DO NOT CHANGE THIS PREFIX - it must match the pattern in cloud/backoffice/backoffice/x/patterns.go
61+
PROJECT_NAME_PREFIX="ory-cy-e2e-da2f162d-af61-42dd-90dc-e3fcfa7c84a0"
62+
PROJECT_NAME="${PROJECT_NAME_PREFIX}-tf-$(date +%s)"
5863

5964
# Validate required environment variables
6065
if [[ -z "${ORY_WORKSPACE_API_KEY:-}" ]]; then

0 commit comments

Comments
 (0)