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