Skip to content

Commit 0a7ac4f

Browse files
committed
Refactor agent execution mode test to create org via Terraform
The test for agent execution mode with agent pool now creates the organization and OAuth client resources using Terraform configuration instead of helper functions. This improves test isolation and aligns resource creation with Terraform-managed infrastructure.
1 parent 1afa672 commit 0a7ac4f

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

internal/provider/resource_tfe_registry_module_test.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,16 +1770,9 @@ resource "tfe_registry_module" "foobar" {
17701770
func TestAccTFERegistryModule_agentExecutionModeWithAgentPool(t *testing.T) {
17711771
skipIfEnterprise(t)
17721772

1773-
tfeClient, err := getClientUsingEnv()
1774-
if err != nil {
1775-
t.Fatal(err)
1776-
}
1777-
1778-
org, orgCleanup := createBusinessOrganization(t, tfeClient)
1779-
t.Cleanup(orgCleanup)
1780-
17811773
registryModule := &tfe.RegistryModule{}
17821774
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
1775+
orgName := fmt.Sprintf("tst-terraform-%d", rInt)
17831776

17841777
resource.Test(t, resource.TestCase{
17851778
PreCheck: func() {
@@ -1789,16 +1782,16 @@ func TestAccTFERegistryModule_agentExecutionModeWithAgentPool(t *testing.T) {
17891782
CheckDestroy: testAccCheckTFERegistryModuleDestroy,
17901783
Steps: []resource.TestStep{
17911784
{
1792-
Config: testAccTFERegistryModule_agentExecutionModeWithAgentPool(org.Name, rInt),
1785+
Config: testAccTFERegistryModule_agentExecutionModeWithAgentPool(orgName, rInt),
17931786
Check: resource.ComposeTestCheckFunc(
17941787
testAccCheckTFERegistryModuleExists(
17951788
"tfe_registry_module.foobar",
17961789
tfe.RegistryModuleID{
1797-
Organization: org.Name,
1790+
Organization: orgName,
17981791
Name: getRegistryModuleName(),
17991792
Provider: getRegistryModuleProvider(),
18001793
RegistryName: tfe.PrivateRegistry,
1801-
Namespace: org.Name,
1794+
Namespace: orgName,
18021795
},
18031796
registryModule,
18041797
),
@@ -1939,18 +1932,31 @@ resource "tfe_registry_module" "foobar" {
19391932

19401933
func testAccTFERegistryModule_agentExecutionModeWithAgentPool(organization string, rInt int) string {
19411934
return fmt.Sprintf(`
1935+
resource "tfe_organization" "foobar" {
1936+
name = "%s"
1937+
1938+
}
1939+
1940+
resource "tfe_oauth_client" "foobar" {
1941+
organization = tfe_organization.foobar.name
1942+
api_url = "https://api.github.com"
1943+
http_url = "https://github.com"
1944+
oauth_token = "%s"
1945+
service_provider = "github"
1946+
}
1947+
19421948
resource "tfe_agent_pool" "foobar" {
19431949
name = "agent-pool-test-%d"
1944-
organization = "%s"
1950+
organization = tfe_organization.foobar.name
19451951
}
19461952
19471953
resource "tfe_registry_module" "foobar" {
1948-
organization = "%s"
1954+
organization = tfe_organization.foobar.name
19491955
19501956
vcs_repo {
19511957
display_identifier = "%s"
19521958
identifier = "%s"
1953-
oauth_token_id = "%s"
1959+
oauth_token_id = tfe_oauth_client.foobar.oauth_token_id
19541960
branch = "main"
19551961
tags = false
19561962
}
@@ -1962,7 +1968,7 @@ resource "tfe_registry_module" "foobar" {
19621968
agent_execution_mode = "agent"
19631969
agent_pool_id = tfe_agent_pool.foobar.id
19641970
}
1965-
}`, rInt, organization, organization, envGithubRegistryModuleIdentifer, envGithubRegistryModuleIdentifer, envGithubToken)
1971+
}`, organization, envGithubToken, rInt, envGithubRegistryModuleIdentifer, envGithubRegistryModuleIdentifer)
19661972
}
19671973

19681974
func testAccTFERegistryModule_remoteExecutionModeWithoutAgentPool(rInt int) string {

0 commit comments

Comments
 (0)