Skip to content

Commit 462f48b

Browse files
authored
Merge pull request #9 from ory/fix/update-tests-to-clean-projects
fix: adding prefix for tests to mark them for deletion
2 parents e96dcff + 84dcd06 commit 462f48b

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

internal/acctest/acctest.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ func createSharedProject(t *testing.T) {
152152
return
153153
}
154154

155-
projectName := fmt.Sprintf("tf-acc-test-%d", time.Now().UnixNano())
155+
// Use prefix from env var (set by scripts/run-acceptance-tests.sh) for auto-cleanup support
156+
prefix := os.Getenv("ORY_TEST_PROJECT_PREFIX")
157+
var projectName string
158+
if prefix != "" {
159+
projectName = fmt.Sprintf("%s-tf-%d", prefix, time.Now().UnixNano())
160+
} else {
161+
projectName = fmt.Sprintf("tf-acc-test-%d", time.Now().UnixNano())
162+
}
156163
t.Logf("Creating test project: %s (environment: prod)", projectName)
157164

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

internal/resources/project/resource_test.go

Lines changed: 16 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,16 @@ func TestAccProjectResource_prodEnvironment(t *testing.T) {
6972
})
7073
}
7174

75+
// testProjectName generates a project name with the e2e prefix for hard deletion support.
76+
// The prefix is read from ORY_TEST_PROJECT_PREFIX env var (set by scripts/run-acceptance-tests.sh).
77+
func testProjectName(suffix string) string {
78+
prefix := os.Getenv("ORY_TEST_PROJECT_PREFIX")
79+
if prefix != "" {
80+
return fmt.Sprintf("%s-tf-%s-%d", prefix, suffix, time.Now().UnixNano())
81+
}
82+
return fmt.Sprintf("tf-acc-test-%s-%d", suffix, time.Now().UnixNano())
83+
}
84+
7285
func testAccProjectResourceConfig(name, environment string) string {
7386
return fmt.Sprintf(`
7487
provider "ory" {}

scripts/run-acceptance-tests.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ 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+
# Projects with names starting with this prefix are automatically purged by the e2e cleanup job.
59+
# DO NOT CHANGE THIS PREFIX - it must match the pattern in cloud/backoffice/backoffice/x/patterns.go
60+
export ORY_TEST_PROJECT_PREFIX="ory-cy-e2e-da2f162d-af61-42dd-90dc-e3fcfa7c84a0"
61+
PROJECT_NAME="${ORY_TEST_PROJECT_PREFIX}-tf-$(date +%s)"
5862

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

0 commit comments

Comments
 (0)