scraper_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package memcachedreceiver
  4. import (
  5. "context"
  6. "path/filepath"
  7. "testing"
  8. "time"
  9. "github.com/stretchr/testify/require"
  10. "go.opentelemetry.io/collector/receiver/receivertest"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
  13. )
  14. func TestScraper(t *testing.T) {
  15. f := NewFactory()
  16. cfg := f.CreateDefaultConfig().(*Config)
  17. scraper := newMemcachedScraper(receivertest.NewNopCreateSettings(), cfg)
  18. scraper.newClient = func(endpoint string, timeout time.Duration) (client, error) {
  19. return &fakeClient{}, nil
  20. }
  21. actualMetrics, err := scraper.scrape(context.Background())
  22. require.NoError(t, err)
  23. expectedFile := filepath.Join("testdata", "scraper", "expected.yaml")
  24. expectedMetrics, err := golden.ReadMetrics(expectedFile)
  25. require.NoError(t, err)
  26. require.NoError(t, pmetrictest.CompareMetrics(expectedMetrics, actualMetrics,
  27. pmetrictest.IgnoreMetricDataPointsOrder(), pmetrictest.IgnoreStartTimestamp(), pmetrictest.IgnoreTimestamp()))
  28. }