integration_test.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. //go:build integration
  4. // +build integration
  5. package vcenterreceiver // import github.com/open-telemetry/opentelemetry-collector-contrib/receiver/vcenterreceiver
  6. import (
  7. "context"
  8. "fmt"
  9. "testing"
  10. "time"
  11. "github.com/stretchr/testify/require"
  12. "github.com/vmware/govmomi"
  13. "github.com/vmware/govmomi/find"
  14. "github.com/vmware/govmomi/session"
  15. "github.com/vmware/govmomi/simulator"
  16. "github.com/vmware/govmomi/vim25"
  17. "go.opentelemetry.io/collector/component"
  18. "go.opentelemetry.io/collector/config/configopaque"
  19. "go.opentelemetry.io/collector/config/configtls"
  20. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/scraperinttest"
  21. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
  22. )
  23. func TestIntegration(t *testing.T) {
  24. simulator.Test(func(ctx context.Context, c *vim25.Client) {
  25. pw, set := simulator.DefaultLogin.Password()
  26. require.True(t, set)
  27. s := session.NewManager(c)
  28. newVcenterClient = func(cfg *Config) *vcenterClient {
  29. client := &vcenterClient{
  30. cfg: cfg,
  31. moClient: &govmomi.Client{
  32. Client: c,
  33. SessionManager: s,
  34. },
  35. }
  36. require.NoError(t, client.EnsureConnection(context.Background()))
  37. client.vimDriver = c
  38. client.finder = find.NewFinder(c)
  39. // Performance metrics rely on time based publishing so this is inherently flaky for an
  40. // integration test, so setting the performance manager to nil to not attempt to compare
  41. // performance metrics. Coverage for this is encompassed in ./scraper_test.go
  42. client.pm = nil
  43. return client
  44. }
  45. defer func() {
  46. newVcenterClient = defaultNewVcenterClient
  47. }()
  48. scraperinttest.NewIntegrationTest(
  49. NewFactory(),
  50. scraperinttest.WithCustomConfig(
  51. func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
  52. rCfg := cfg.(*Config)
  53. rCfg.CollectionInterval = 2 * time.Second
  54. rCfg.Endpoint = fmt.Sprintf("%s://%s", c.URL().Scheme, c.URL().Host)
  55. rCfg.Username = simulator.DefaultLogin.Username()
  56. rCfg.Password = configopaque.String(pw)
  57. rCfg.TLSClientSetting = configtls.TLSClientSetting{
  58. Insecure: true,
  59. }
  60. }),
  61. scraperinttest.WithCompareOptions(
  62. pmetrictest.IgnoreResourceAttributeValue("vcenter.host.name"),
  63. pmetrictest.IgnoreTimestamp(),
  64. pmetrictest.IgnoreResourceMetricsOrder(),
  65. pmetrictest.IgnoreMetricsOrder(),
  66. pmetrictest.IgnoreStartTimestamp(),
  67. pmetrictest.IgnoreMetricValues(),
  68. ),
  69. ).Run(t)
  70. })
  71. }