Skip to content

Commit

Permalink
test(entities): adds test cases to test errors with reserved keys mod…
Browse files Browse the repository at this point in the history
…ified in entity tags (#1188)
  • Loading branch information
shashank-reddy-nr authored Jul 12, 2024
1 parent fb8f11c commit 488ace7
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions pkg/entities/tags_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
package entities

import (
"testing"

"github.com/stretchr/testify/require"
"regexp"
"testing"

"github.com/newrelic/newrelic-client-go/v2/pkg/common"
"github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers"
Expand Down Expand Up @@ -61,6 +61,7 @@ func TestIntegrationTaggingAddTagsToEntityAndGetTags(t *testing.T) {

require.NoError(t, err)
require.Greater(t, len(actual), 0)

}

func TestIntegrationTaggingReplaceTagsOnEntity(t *testing.T) {
Expand All @@ -83,6 +84,7 @@ func TestIntegrationTaggingReplaceTagsOnEntity(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, result)
require.Equal(t, 0, len(result.Errors))

}

func TestIntegrationDeleteTags(t *testing.T) {
Expand Down Expand Up @@ -123,3 +125,39 @@ func TestIntegrationDeleteTagValues(t *testing.T) {
require.NotNil(t, result)
require.Equal(t, 0, len(result.Errors))
}

func TestIntegrationEntityTagsReservedKeysMutation(t *testing.T) {
t.Parallel()

var (
testGUID = common.EntityGUID(testhelpers.IntegrationTestApplicationEntityGUID)
)

client := newIntegrationTestClient(t)

// Test: To add a reserved key(immutable key)
tags := []TaggingTagInput{
{
Key: "account",
Values: []string{"Random-name"},
},
}
result, err := client.TaggingAddTagsToEntity(testGUID, tags)
require.NoError(t, err)
require.NotNil(t, result)
require.Greater(t, len(result.Errors), 0)
message := result.Errors[0].Message
match, er := regexp.MatchString("reserved", message)
require.NoError(t, er)
require.True(t, match)

// Test: To update a reserved key(immutable key)
result, err = client.TaggingReplaceTagsOnEntity(testGUID, tags)
require.NoError(t, err)
require.NotNil(t, result)
require.Greater(t, len(result.Errors), 0)
message = result.Errors[0].Message
match, er = regexp.MatchString("reserved", message)
require.NoError(t, er)
require.True(t, match)
}

0 comments on commit 488ace7

Please sign in to comment.