From e77cabe5e19fc3fd0300f4b6b954bf986214fece Mon Sep 17 00:00:00 2001 From: Michael Fulbright Date: Fri, 1 Mar 2024 13:41:51 -0500 Subject: [PATCH 1/2] feat(testing): Extends EXPECT_METRICS_EXIST, EXPECT_METRICS_DONT_EXIST This commit adds support for "__FILE__" in the metrics supplied. --- src/newrelic/integration/test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/newrelic/integration/test.go b/src/newrelic/integration/test.go index 89a7326af..91dd9f945 100644 --- a/src/newrelic/integration/test.go +++ b/src/newrelic/integration/test.go @@ -657,18 +657,18 @@ func (t *Test) Compare(harvest *newrelic.Harvest) { if nil != t.metricsExist { for _, name := range strings.Split(strings.TrimSpace(string(t.metricsExist)), "\n") { - name = strings.TrimSpace(name) - if !harvest.Metrics.Has(name) { - t.Fail(fmt.Errorf("metric does not exist: %s\n\nactual metric table: %s", name, harvest.Metrics.DebugJSON())) + actual := strings.Replace(name, "__FILE__", t.Path, -1) + if !harvest.Metrics.Has(actual) { + t.Fail(fmt.Errorf("metric does not exist: %s\n\nactual metric table: %s", actual, harvest.Metrics.DebugJSON())) } } } if nil != t.metricsDontExist { for _, name := range strings.Split(strings.TrimSpace(string(t.metricsDontExist)), "\n") { - name = strings.TrimSpace(name) - if harvest.Metrics.Has(name) { - t.Fail(fmt.Errorf("unexpected metric in harvest: %s\n\nactual metric table: %s", name, harvest.Metrics.DebugJSON())) + actual := strings.Replace(name, "__FILE__", t.Path, -1) + if harvest.Metrics.Has(actual) { + t.Fail(fmt.Errorf("unexpected metric in harvest: %s\n\nactual metric table: %s", actual, harvest.Metrics.DebugJSON())) } } } From 8483c6ed4b8e4791880c89515aad1d44c37168ce Mon Sep 17 00:00:00 2001 From: Michael Fulbright Date: Fri, 1 Mar 2024 13:45:51 -0500 Subject: [PATCH 2/2] fix(testing): Restores trimming of spaces in name --- src/newrelic/integration/test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/newrelic/integration/test.go b/src/newrelic/integration/test.go index 91dd9f945..0bf8ff112 100644 --- a/src/newrelic/integration/test.go +++ b/src/newrelic/integration/test.go @@ -657,6 +657,7 @@ func (t *Test) Compare(harvest *newrelic.Harvest) { if nil != t.metricsExist { for _, name := range strings.Split(strings.TrimSpace(string(t.metricsExist)), "\n") { + name = strings.TrimSpace(name) actual := strings.Replace(name, "__FILE__", t.Path, -1) if !harvest.Metrics.Has(actual) { t.Fail(fmt.Errorf("metric does not exist: %s\n\nactual metric table: %s", actual, harvest.Metrics.DebugJSON())) @@ -666,6 +667,7 @@ func (t *Test) Compare(harvest *newrelic.Harvest) { if nil != t.metricsDontExist { for _, name := range strings.Split(strings.TrimSpace(string(t.metricsDontExist)), "\n") { + name = strings.TrimSpace(name) actual := strings.Replace(name, "__FILE__", t.Path, -1) if harvest.Metrics.Has(actual) { t.Fail(fmt.Errorf("unexpected metric in harvest: %s\n\nactual metric table: %s", actual, harvest.Metrics.DebugJSON()))