From 0f2998d895770c530c6681146d9aaf75b558e89f Mon Sep 17 00:00:00 2001 From: Mirac Kara Date: Mon, 27 Jun 2022 14:17:18 -0500 Subject: [PATCH] Added tests for custom events configuration --- app_run.go | 3 ++- v3/newrelic/app_run_test.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app_run.go b/app_run.go index ae0fb00dd..928ec026a 100644 --- a/app_run.go +++ b/app_run.go @@ -7,7 +7,6 @@ import ( "encoding/json" "strings" "time" - "github.com/newrelic/go-agent/internal" ) @@ -181,6 +180,8 @@ func (run *appRun) MaxErrorEvents() int { return run.limit(internal.MaxErrorEvents, run.ptrErrorEvents) } func (run *appRun) MaxSpanEvents() int { return run.limit(internal.MaxSpanEvents, run.ptrSpanEvents) } +func (run *appRun) MaxSamplesStored() int { return run.limit(internal.MaxSamplesStored, run.ptrCustomEvents) } + func (run *appRun) limit(dflt int, field func() *uint) int { if nil != field() { diff --git a/v3/newrelic/app_run_test.go b/v3/newrelic/app_run_test.go index 56bd33c2f..2f2f46488 100644 --- a/v3/newrelic/app_run_test.go +++ b/v3/newrelic/app_run_test.go @@ -324,6 +324,27 @@ func TestConfigurableTxnEvents_withCollResponse(t *testing.T) { } } +func TestConfigurableMaxCustomEventsDefault(t *testing.T) { + reply := internal.ConnectReplyDefaults() + expected := 10000 + cfg := config{Config: defaultConfig()} + result := newAppRun(cfg, reply).MaxCustomEvents() + if result != expected { + t.Errorf("Unexpected max number of custom events, expected %d but got %d", expected, result) + } +} + +func TestConfigurableMaxCustomEvents(t *testing.T) { + reply := internal.ConnectReplyDefaults() + expected := 1000 + cfg := config{Config: defaultConfig()} + cfg.CustomInsightsEvents.MaxSamplesStored = expected + result := newAppRun(cfg, reply).MaxCustomEvents() + if result != expected { + t.Errorf("Unexpected max number of custom events, expected %d but got %d", expected, result) + } +} + func TestConfigurableTxnEvents_notInCollResponse(t *testing.T) { reply, err := internal.UnmarshalConnectReply([]byte( `{"return_value":{