Skip to content

Commit

Permalink
[receiver/hostmetrics] Fix failing tests (#32583)
Browse files Browse the repository at this point in the history
Fixing failing tests - recover `scraperFactories` var
value after `TestGatherMetrics_ScraperKeyConfigError` and
`TestGatherMetrics_CreateMetricsScraperError` tests

Fixes #32536
  • Loading branch information
bsponge authored Apr 22, 2024
1 parent 78b852c commit 1a5e38b
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 1a5e38b

Please sign in to comment.