Skip to content

Commit 85aa502

Browse files
committed
test
1 parent 4217cce commit 85aa502

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

internal/provider/resource_tfe_registry_module.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
2323
)
2424

25+
var ctx = context.Background()
26+
2527
func resourceTFERegistryModule() *schema.Resource {
2628
return &schema.Resource{
2729
Create: resourceTFERegistryModuleCreate,
@@ -578,13 +580,16 @@ func validateTestConfig(d *schema.ResourceDiff) error {
578580
}
579581

580582
testConfigValue := testConfig.AsValueSlice()[0]
581-
agentExecutionModeValue := testConfigValue.GetAttr("agent_execution_mode")
582-
agentPoolIDValue := testConfigValue.GetAttr("agent_pool_id")
583583

584-
if agentExecutionModeValue.IsNull() && agentPoolIDValue.IsNull() {
585-
return nil
584+
// Check if test_config block is empty (no tests_enabled field)
585+
testsEnabledValue := testConfigValue.GetAttr("tests_enabled")
586+
if testsEnabledValue.IsNull() {
587+
return fmt.Errorf("tests_enabled must be provided when configuring a test_config")
586588
}
587589

590+
agentExecutionModeValue := testConfigValue.GetAttr("agent_execution_mode")
591+
agentPoolIDValue := testConfigValue.GetAttr("agent_pool_id")
592+
588593
// Skip validation if values are unknown (during plan phase)
589594
if !agentExecutionModeValue.IsKnown() || !agentPoolIDValue.IsKnown() {
590595
return nil

internal/provider/resource_tfe_registry_module_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package provider
55

66
import (
7+
"context"
78
"fmt"
89
"math/rand"
910
"regexp"
@@ -17,6 +18,8 @@ import (
1718
"github.com/hashicorp/terraform-plugin-testing/terraform"
1819
)
1920

21+
var ctx = context.Background()
22+
2023
func TestAccTFERegistryModule_vcsBasic(t *testing.T) {
2124
registryModule := &tfe.RegistryModule{}
2225
rInt := rand.New(rand.NewSource(time.Now().UnixNano())).Int()
@@ -666,7 +669,7 @@ func TestAccTFERegistryModuleImport_vcsPublishingMechanismTagsToBranchToTags(t *
666669
Config: testAccTFERegistryModule_vcsTags(rInt),
667670
Check: resource.ComposeTestCheckFunc(
668671
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "publishing_mechanism", "git_tag"),
669-
resource.TestCheckNoResourceAttr("tfe_registry_module.foobar", "test_config.0.tests_enabled"),
672+
resource.TestCheckNoResourceAttr("tfe_registry_module.foobar", "test_config.0"),
670673
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.tags", strconv.FormatBool(true)),
671674
resource.TestCheckResourceAttr("tfe_registry_module.foobar", "vcs_repo.0.branch", ""),
672675
),
@@ -686,7 +689,7 @@ func TestAccTFERegistryModule_invalidTestConfigOnCreate(t *testing.T) {
686689
ProtoV6ProviderFactories: testAccMuxedProviders,
687690
Steps: []resource.TestStep{
688691
{
689-
Config: testAccTFERegistryModule_vcsInvalidBranch(rInt),
692+
Config: testAccTFERegistryModule_invalidTestConfig(rInt),
690693
ExpectError: regexp.MustCompile(`tests_enabled must be provided when configuring a test_config`),
691694
},
692695
},

0 commit comments

Comments
 (0)