github.com/newrelic/newrelic-client-go@v1.1.0/pkg/apm/labels_integration_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package apm
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/require"
    11  
    12  	nr "github.com/newrelic/newrelic-client-go/pkg/testhelpers"
    13  )
    14  
    15  func TestIntegrationLabels(t *testing.T) {
    16  	t.Parallel()
    17  
    18  	client := newIntegrationTestClient(t)
    19  
    20  	// Setup
    21  	appFilterName := "tf_" // Filter for integration test applications
    22  	appQueryParams := ListApplicationsParams{
    23  		Name: appFilterName,
    24  	}
    25  	applications, err := client.ListApplications(&appQueryParams)
    26  
    27  	if err != nil {
    28  		t.Skipf("Skipped Labels integration test due error fetching applications: %s", err)
    29  		return
    30  	}
    31  
    32  	if len(applications) == 0 {
    33  		t.Skipf("Skipped Labels integration test due to no applications being found for filter by name: %s", appFilterName)
    34  		return
    35  	}
    36  
    37  	application := applications[0]
    38  	labelName := nr.RandSeq(5)
    39  	newLabel := Label{
    40  		Category: "Project",
    41  		Name:     fmt.Sprintf("label-%s", labelName),
    42  		Links: LabelLinks{
    43  			Applications: []int{application.ID},
    44  			Servers:      []int{},
    45  		},
    46  	}
    47  
    48  	t.Logf("applying label %s linked to application %s", labelName, application.Name)
    49  
    50  	// Test: Create
    51  	label, err := client.CreateLabel(newLabel)
    52  
    53  	require.NoError(t, err)
    54  	require.NotNil(t, label)
    55  
    56  	// Test: List
    57  	listResult, err := client.ListLabels()
    58  
    59  	require.NoError(t, err)
    60  	require.Greater(t, len(listResult), 0)
    61  
    62  	// Test: Get
    63  	getResult, err := client.GetLabel(label.Key)
    64  
    65  	require.NoError(t, err)
    66  	require.NotNil(t, getResult)
    67  
    68  	// Test: Delete
    69  	deleteResult, err := client.DeleteLabel(label.Key)
    70  
    71  	require.NoError(t, err)
    72  	require.NotNil(t, deleteResult)
    73  }