Skip to content

Commit

Permalink
recover scraperFactories var value after test
Browse files Browse the repository at this point in the history
  • Loading branch information
bsponge committed Apr 21, 2024
1 parent 8012101 commit 0eb0139
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ func (m *mockScraper) Scrape(context.Context) (pmetric.Metrics, error) {
}

func TestGatherMetrics_ScraperKeyConfigError(t *testing.T) {
tmp := scraperFactories
scraperFactories = map[string]internal.ScraperFactory{}
defer func() {
scraperFactories = tmp
}()

sink := new(consumertest.MetricsSink)
cfg := &Config{Scrapers: map[string]internal.Config{"error": &mockConfig{}}}
Expand All @@ -250,7 +254,11 @@ func TestGatherMetrics_ScraperKeyConfigError(t *testing.T) {
func TestGatherMetrics_CreateMetricsScraperError(t *testing.T) {
mFactory := &mockFactory{}
mFactory.On("CreateMetricsScraper").Return(&mockScraper{}, errors.New("err1"))
tmp := scraperFactories
scraperFactories = map[string]internal.ScraperFactory{mockTypeStr: mFactory}
defer func() {
scraperFactories = tmp
}()

sink := new(consumertest.MetricsSink)
cfg := &Config{Scrapers: map[string]internal.Config{mockTypeStr: &mockConfig{}}}
Expand Down

0 comments on commit 0eb0139

Please sign in to comment.