integration_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. //go:build integration
  4. // +build integration
  5. package redisreceiver
  6. import (
  7. "fmt"
  8. "testing"
  9. "github.com/testcontainers/testcontainers-go"
  10. "github.com/testcontainers/testcontainers-go/wait"
  11. "go.opentelemetry.io/collector/component"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/scraperinttest"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
  14. )
  15. const redisPort = "6379"
  16. func TestIntegration(t *testing.T) {
  17. scraperinttest.NewIntegrationTest(
  18. NewFactory(),
  19. scraperinttest.WithContainerRequest(
  20. testcontainers.ContainerRequest{
  21. Image: "redis:6.0.3",
  22. ExposedPorts: []string{redisPort},
  23. WaitingFor: wait.ForListeningPort(redisPort),
  24. }),
  25. scraperinttest.WithCustomConfig(
  26. func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
  27. rCfg := cfg.(*Config)
  28. rCfg.Endpoint = fmt.Sprintf("%s:%s", ci.Host(t), ci.MappedPort(t, redisPort))
  29. }),
  30. scraperinttest.WithCompareOptions(
  31. pmetrictest.IgnoreMetricValues(),
  32. pmetrictest.IgnoreMetricDataPointsOrder(),
  33. pmetrictest.IgnoreStartTimestamp(),
  34. pmetrictest.IgnoreTimestamp(),
  35. pmetrictest.ChangeResourceAttributeValue("server.address", func(_ string) string {
  36. return "localhost"
  37. }),
  38. pmetrictest.ChangeResourceAttributeValue("server.port", func(_ string) string {
  39. return redisPort
  40. }),
  41. ),
  42. ).Run(t)
  43. }