github.com/newrelic/newrelic-client-go@v1.1.0/pkg/entities/entity_integration_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package entities 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 12 "github.com/newrelic/newrelic-client-go/internal/http" 13 "github.com/newrelic/newrelic-client-go/pkg/common" 14 mock "github.com/newrelic/newrelic-client-go/pkg/testhelpers" 15 ) 16 17 func TestIntegrationSearchEntities(t *testing.T) { 18 t.Parallel() 19 20 client := newIntegrationTestClient(t) 21 22 params := EntitySearchQueryBuilder{ 23 Name: "Dummy App", 24 } 25 26 actual, err := client.GetEntitySearch( 27 EntitySearchOptions{}, 28 "", 29 params, 30 []EntitySearchSortCriteria{}, 31 ) 32 33 require.NoError(t, err) 34 require.Greater(t, len(actual.Results.Entities), 0) 35 36 params = EntitySearchQueryBuilder{ 37 Name: "WebPortal", 38 } 39 40 actual, err = client.GetEntitySearch( 41 EntitySearchOptions{}, 42 "", 43 params, 44 []EntitySearchSortCriteria{}, 45 ) 46 47 require.NoError(t, err) 48 require.Greater(t, len(actual.Results.Entities), 0) 49 } 50 51 func TestIntegrationSearchEntitiesByQuery(t *testing.T) { 52 t.Parallel() 53 54 client := newIntegrationTestClient(t) 55 56 query := "domain = 'APM' AND type = 'APPLICATION' and name = 'Dummy App'" 57 58 actual, err := client.GetEntitySearchByQuery( 59 EntitySearchOptions{}, 60 query, 61 []EntitySearchSortCriteria{}, 62 ) 63 64 require.NoError(t, err) 65 require.Greater(t, len(actual.Results.Entities), 0) 66 } 67 68 func TestIntegrationSearchEntities_domain(t *testing.T) { 69 t.Parallel() 70 71 client := newIntegrationTestClient(t) 72 73 domains := []EntitySearchQueryBuilderDomain{ 74 EntitySearchQueryBuilderDomainTypes.APM, 75 EntitySearchQueryBuilderDomainTypes.BROWSER, 76 EntitySearchQueryBuilderDomainTypes.INFRA, 77 EntitySearchQueryBuilderDomainTypes.MOBILE, 78 EntitySearchQueryBuilderDomainTypes.SYNTH, 79 } 80 81 for _, d := range domains { 82 params := EntitySearchQueryBuilder{ 83 Domain: d, 84 } 85 86 result, err := client.GetEntitySearch( 87 EntitySearchOptions{}, 88 "", 89 params, 90 []EntitySearchSortCriteria{}, 91 ) 92 93 require.NoError(t, err) 94 require.Greater(t, len(result.Results.Entities), 0) 95 } 96 } 97 98 func TestIntegrationSearchEntitiesByTags(t *testing.T) { 99 t.Parallel() 100 101 client := newIntegrationTestClient(t) 102 103 params := EntitySearchQueryBuilder{ 104 Tags: []EntitySearchQueryBuilderTag{ 105 { 106 Key: "language", 107 Value: "nodejs", 108 }, 109 }, 110 } 111 112 actual, err := client.GetEntitySearch( 113 EntitySearchOptions{}, 114 "", 115 params, 116 []EntitySearchSortCriteria{}, 117 ) 118 119 require.NoError(t, err) 120 require.NotNil(t, actual) 121 } 122 123 func TestIntegrationGetEntities(t *testing.T) { 124 t.Parallel() 125 126 client := newIntegrationTestClient(t) 127 128 // GUID of Dummy App 129 guids := []common.EntityGUID{"MjUyMDUyOHxBUE18QVBQTElDQVRJT058MjE1MDM3Nzk1"} 130 actual, err := client.GetEntities(guids) 131 132 if e, ok := err.(*http.GraphQLErrorResponse); ok { 133 if !e.IsDeprecated() { 134 require.NoError(t, e) 135 } 136 } 137 require.Greater(t, len((*actual)), 0) 138 } 139 140 func TestIntegrationGetEntity(t *testing.T) { 141 t.Parallel() 142 143 // GUID of Dummy App 144 entityGUID := common.EntityGUID("MjUyMDUyOHxBUE18QVBQTElDQVRJT058MjE1MDM3Nzk1") 145 client := newIntegrationTestClient(t) 146 147 result, err := client.GetEntity(entityGUID) 148 149 if e, ok := err.(*http.GraphQLErrorResponse); ok { 150 if !e.IsDeprecated() { 151 require.NoError(t, e) 152 } 153 } 154 require.NotNil(t, result) 155 156 actual := (*result).(*ApmApplicationEntity) 157 158 // These are a bit fragile, if the above GUID ever changes... 159 assert.Equal(t, 2520528, actual.AccountID) 160 assert.Equal(t, "APM", actual.Domain) 161 assert.Equal(t, EntityType("APM_APPLICATION_ENTITY"), actual.EntityType) 162 assert.Equal(t, entityGUID, actual.GUID) 163 assert.Equal(t, "Dummy App", actual.Name) 164 assert.Equal(t, "https://one.newrelic.com/redirect/entity/"+string(entityGUID), actual.Permalink) 165 assert.Equal(t, true, actual.Reporting) 166 } 167 168 // Looking at an APM Application, and the result set here. 169 func TestIntegrationGetEntity_ApmEntity(t *testing.T) { 170 t.Parallel() 171 172 client := newIntegrationTestClient(t) 173 174 // GUID of Dummy App 175 result, err := client.GetEntity("MjUyMDUyOHxBUE18QVBQTElDQVRJT058MjE1MDM3Nzk1") 176 177 if e, ok := err.(*http.GraphQLErrorResponse); ok { 178 if !e.IsDeprecated() { 179 require.NoError(t, e) 180 } 181 } 182 require.NotNil(t, result) 183 184 actual := (*result).(*ApmApplicationEntity) 185 186 // NOT_ALERTING or CRITICAL alert status can be expected 187 acceptableAlertStatuses := []EntityAlertSeverity{ 188 EntityAlertSeverityTypes.NOT_ALERTING, 189 EntityAlertSeverityTypes.CRITICAL, 190 } 191 192 // These are a bit fragile, if the above GUID ever changes... 193 // from ApmApplicationEntity / ApmApplicationEntityOutline 194 assert.Equal(t, 215037795, actual.ApplicationID) 195 assert.Contains(t, acceptableAlertStatuses, actual.AlertSeverity) 196 assert.Equal(t, "nodejs", actual.Language) 197 assert.NotNil(t, actual.RunningAgentVersions) 198 assert.NotNil(t, actual.RunningAgentVersions.MinVersion) 199 assert.NotNil(t, actual.RunningAgentVersions.MaxVersion) 200 assert.NotNil(t, actual.Settings) 201 assert.NotNil(t, actual.Settings.ApdexTarget) 202 assert.NotNil(t, actual.Settings.ServerSideConfig) 203 204 } 205 206 // Looking at a Browser Application, and the result set here. 207 func TestIntegrationGetEntity_BrowserEntity(t *testing.T) { 208 t.Parallel() 209 210 client := newIntegrationTestClient(t) 211 212 result, err := client.GetEntity("MjUwODI1OXxCUk9XU0VSfEFQUExJQ0FUSU9OfDIwNDI2MTYyOA") 213 214 if e, ok := err.(*http.GraphQLErrorResponse); ok { 215 if !e.IsDeprecated() { 216 require.NoError(t, e) 217 } 218 } 219 require.NotNil(t, result) 220 221 ref := *result 222 actual, ok := ref.(*BrowserApplicationEntity) 223 224 if actual == nil || !ok { 225 t.Skip("Skipping `TestIntegrationGetEntity_BrowserEntity` integration test due to missing test entity. This entity might have been deleted from this test account.") 226 return 227 } 228 229 // These are a bit fragile, if the above GUID ever changes... 230 // from BrowserApplicationEntity / BrowserApplicationEntityOutline 231 assert.Equal(t, 204261628, actual.ApplicationID) 232 assert.Equal(t, 204261368, actual.ServingApmApplicationID) 233 assert.Equal(t, EntityAlertSeverityTypes.NOT_CONFIGURED, actual.AlertSeverity) 234 } 235 236 // Looking at a Mobile Application, and the result set here. 237 func TestIntegrationGetEntity_MobileEntity(t *testing.T) { 238 t.Parallel() 239 240 client := newIntegrationTestClient(t) 241 242 result, err := client.GetEntity("NDQ0NTN8TU9CSUxFfEFQUExJQ0FUSU9OfDE3ODg1NDI") 243 244 if e, ok := err.(*http.GraphQLErrorResponse); ok { 245 if !e.IsDeprecated() { 246 require.NoError(t, e) 247 } 248 } 249 require.NotNil(t, (*result)) 250 251 actual := (*result).(*MobileApplicationEntity) 252 253 // These are a bit fragile, if the above GUID ever changes... 254 // from MobileApplicationEntity / MobileApplicationEntityOutline 255 assert.Equal(t, 1788542, actual.ApplicationID) 256 assert.Equal(t, EntityAlertSeverityTypes.NOT_CONFIGURED, actual.AlertSeverity) 257 258 } 259 260 func newIntegrationTestClient(t *testing.T) Entities { 261 tc := mock.NewIntegrationTestConfig(t) 262 263 return New(tc) 264 }