Skip to content

Commit

Permalink
prevent acc tests auto triggering
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaweitao001 committed Dec 5, 2024
1 parent 1007af6 commit 55584b9
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions internal/services/dynatrace/dynatrace_tag_rules_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dynatrace_test
import (
"context"
"fmt"
"os"
"testing"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
Expand All @@ -14,11 +15,26 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type TagRulesResource struct{}
type TagRulesResource struct {
dynatraceInfo dynatraceInfo
}

func NewTagRulesResource() TagRulesResource {
return TagRulesResource{
dynatraceInfo: dynatraceInfo{
UserCountry: os.Getenv("DYNATRACE_USER_COUNTRY"),
UserEmail: os.Getenv("DYNATRACE_USER_EMAIL"),
UserFirstName: os.Getenv("DYNATRACE_USER_FIRST_NAME"),
UserLastName: os.Getenv("DYNATRACE_USER_LAST_NAME"),
UserPhoneNumber: os.Getenv("DYNATRACE_USER_PHONE_NUMBER"),
},
}
}

func TestAccDynatraceTagRules_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_dynatrace_tag_rules", "test")
r := TagRulesResource{}
r := NewTagRulesResource()
r.preCheck(t)

data.ResourceTest(t, r, []acceptance.TestStep{
{
Expand All @@ -33,7 +49,8 @@ func TestAccDynatraceTagRules_basic(t *testing.T) {

func TestAccDynatraceTagRules_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_dynatrace_tag_rules", "test")
r := TagRulesResource{}
r := NewTagRulesResource()
r.preCheck(t)

data.ResourceTest(t, r, []acceptance.TestStep{
{
Expand All @@ -46,6 +63,24 @@ func TestAccDynatraceTagRules_requiresImport(t *testing.T) {
})
}

func (r TagRulesResource) preCheck(t *testing.T) {
if r.dynatraceInfo.UserCountry == "" {
t.Skipf("DYNATRACE_USER_COUNTRY must be set for acceptance tests")
}
if r.dynatraceInfo.UserEmail == "" {
t.Skipf("DYNATRACE_USER_EMAIL must be set for acceptance tests")
}
if r.dynatraceInfo.UserFirstName == "" {
t.Skipf("DYNATRACE_USER_FIRST_NAME must be set for acceptance tests")
}
if r.dynatraceInfo.UserLastName == "" {
t.Skipf("DYNATRACE_USER_LAST_NAME must be set for acceptance tests")
}
if r.dynatraceInfo.UserPhoneNumber == "" {
t.Skipf("DYNATRACE_USER_PHONE_NUMBER must be set for acceptance tests")
}
}

func (r TagRulesResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := tagrules.ParseTagRuleID(state.ID)
if err != nil {
Expand Down

0 comments on commit 55584b9

Please sign in to comment.