Skip to content

Commit

Permalink
feat(synthetics): add device emulation functionality (#1017)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderblue committed Apr 18, 2023
1 parent 69f5ff6 commit 856242c
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 173 deletions.
9 changes: 4 additions & 5 deletions .tutone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ packages:
- name: accountManagementUpdateAccount
max_query_field_depth: 3



- name: agentApplications
path: pkg/agentapplications
import_path: github.com/newrelic/newrelic-client-go/v2/pkg/agentapplications
Expand Down Expand Up @@ -97,7 +95,6 @@ packages:
- name: AgentApplicationSettingsBrowserPrivacyInput
field_type_override: "*AgentApplicationSettingsBrowserPrivacyInput"


- name: logconfigurations
path: pkg/logconfigurations
import_path: github.com/newrelic/newrelic-client-go/v2/pkg/logconfigurations
Expand Down Expand Up @@ -174,7 +171,6 @@ packages:
max_query_field_depth: 1
- name: "steps"
max_query_field_depth: 1

mutations:
- name: syntheticsCreateSecureCredential
max_query_field_depth: 2
Expand Down Expand Up @@ -220,7 +216,6 @@ packages:
max_query_field_depth: 2
- name: syntheticsPurgePrivateLocationQueue
max_query_field_depth: 2

types:
- name: EpochMilliseconds
field_type_override: "*nrtime.EpochMilliseconds"
Expand All @@ -229,6 +224,10 @@ packages:
- name: ID
field_type_override: string
skip_type_create: true
- name: SyntheticsDeviceEmulationInput
field_type_override: "*SyntheticsDeviceEmulationInput"
- name: SyntheticsRuntimeInput
field_type_override: "*SyntheticsRuntimeInput"

- name: common
path: pkg/common
Expand Down
11 changes: 11 additions & 0 deletions pkg/entities/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package entities
import (
"encoding/json"
"errors"
"strings"

log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -105,3 +106,13 @@ func (d *DashboardWidgetRawConfiguration) UnmarshalJSON(data []byte) error {
*d = append((*d)[0:0], data...)
return nil
}

func FindTagByKey(tags []EntityTag, key string) []string {
for _, t := range tags {
if strings.EqualFold(t.Key, key) {
return t.Values
}
}

return []string{}
}
28 changes: 27 additions & 1 deletion pkg/entities/entity_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ func TestIntegrationGetEntity_ApmEntity(t *testing.T) {
assert.NotNil(t, actual.Settings)
assert.NotNil(t, actual.Settings.ApdexTarget)
assert.NotNil(t, actual.Settings.ServerSideConfig)

}

// Looking at a Browser Application, and the result set here.
Expand Down Expand Up @@ -254,7 +253,34 @@ func TestIntegrationGetEntity_MobileEntity(t *testing.T) {
// from MobileApplicationEntity / MobileApplicationEntityOutline
assert.Equal(t, 601375901, actual.ApplicationID)
assert.Equal(t, EntityAlertSeverityTypes.NOT_CONFIGURED, actual.AlertSeverity)
}

func TestIntegrationGetEntity_SyntheticsEntity(t *testing.T) {
t.Parallel()
syntheticsEntityMonitorGUID := "MzgwNjUyNnxTWU5USHxNT05JVE9SfGVhMjA5MWE4LTM3OTktNDAxOC1iMzU5LWJiYTE0NGY3ZjViMw"
client := newIntegrationTestClient(t)

result, err := client.GetEntity(common.EntityGUID(syntheticsEntityMonitorGUID))
if err != nil || result == nil {
t.Skipf("Entity not found with GUID: %s. Skipping entity integration test for synthetics entity.", syntheticsEntityMonitorGUID)
}

if e, ok := err.(*http.GraphQLErrorResponse); ok {
if !e.IsDeprecated() {
require.NoError(t, e)
}
}
require.NotNil(t, result)

entity := (*result).(*SyntheticMonitorEntity)
require.NotNil(t, entity)

deviceOrientation := FindTagByKey(entity.Tags, "deviceOrientation")
runtimeType := FindTagByKey(entity.Tags, "runtimeType")
runtimeTypeVersion := FindTagByKey(entity.Tags, "runtimeTypeVersion")
require.Greater(t, len(deviceOrientation), 0)
require.Greater(t, len(runtimeType), 0)
require.Greater(t, len(runtimeTypeVersion), 0)
}

func newIntegrationTestClient(t *testing.T) Entities {
Expand Down
37 changes: 37 additions & 0 deletions pkg/entities/entity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//go:build unit

package entities

import (
"testing"

"github.com/stretchr/testify/require"
)

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

entityTags := []EntityTag{
{
Key: "test",
Values: []string{"someTag"},
},
}

result := FindTagByKey(entityTags, "test")
require.Equal(t, []string{"someTag"}, result)
}

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

entityTags := []EntityTag{
{
Key: "test",
Values: []string{"someTag"},
},
}

result := FindTagByKey(entityTags, "notFound")
require.Empty(t, result)
}
Loading

0 comments on commit 856242c

Please sign in to comment.