github.com/newrelic/newrelic-client-go@v1.1.0/pkg/edge/trace_observers_integration_test.go (about)

     1  package edge
     2  
     3  import (
     4  	"os"
     5  	"strconv"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  
    10  	mock "github.com/newrelic/newrelic-client-go/pkg/testhelpers"
    11  )
    12  
    13  var (
    14  	testAccountIDStr      = os.Getenv("NEW_RELIC_MASTER_ACCOUNT_ID")
    15  	testTraceObserverName = "testTraceObserver"
    16  	testProviderRegion    = EdgeProviderRegionTypes.AWS_US_EAST_2
    17  )
    18  
    19  func TestIntegrationTraceObserver(t *testing.T) {
    20  	if testAccountIDStr == "" {
    21  		t.Skip("a master account is required to run trace observer integration tests")
    22  		return
    23  	}
    24  
    25  	testAccountID, err := strconv.Atoi(testAccountIDStr)
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  
    30  	t.Parallel()
    31  
    32  	client := newIntegrationTestClient(t)
    33  
    34  	// Test: Create
    35  	created, err := client.CreateTraceObserver(testAccountID, testTraceObserverName, testProviderRegion)
    36  
    37  	require.NoError(t, err)
    38  	require.NotNil(t, created)
    39  
    40  	// Test: List
    41  	traceObservers, err := client.ListTraceObservers(testAccountID)
    42  	require.NoError(t, err)
    43  	require.Greater(t, len(traceObservers), 0)
    44  
    45  	// Test: Delete
    46  	deleted, err := client.DeleteTraceObserver(testAccountID, created.ID)
    47  
    48  	require.NoError(t, err)
    49  	require.NotNil(t, deleted)
    50  }
    51  
    52  func newIntegrationTestClient(t *testing.T) Edge {
    53  	tc := mock.NewIntegrationTestConfig(t)
    54  
    55  	return New(tc)
    56  }