-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
integration_test.go
77 lines (69 loc) · 2.62 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:build integration
package mongodbreceiver
import (
"fmt"
"path/filepath"
"testing"
"time"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confignet"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/scraperinttest"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
)
const mongoPort = "27017"
func TestIntegration(t *testing.T) {
t.Run("4.0", integrationTest("4_0", []string{"/setup.sh"}, func(*Config) {}))
t.Run("5.0", integrationTest("5_0", []string{"/setup.sh"}, func(*Config) {}))
t.Run("6.0", integrationTest("5_0", []string{"/setup.sh"}, func(*Config) {}))
t.Run("7.0", integrationTest("5_0", []string{"/setup.sh"}, func(*Config) {}))
t.Run("4.4lpu", integrationTest("4_4lpu", []string{"/lpu.sh"}, func(cfg *Config) {
cfg.Username = "otelu"
cfg.Password = "otelp"
}))
}
func integrationTest(name string, script []string, cfgMod func(*Config)) func(*testing.T) {
dockerFile := fmt.Sprintf("Dockerfile.mongodb.%s", name)
expectedFile := fmt.Sprintf("expected.%s.yaml", name)
return scraperinttest.NewIntegrationTest(
NewFactory(),
scraperinttest.WithContainerRequest(
testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: filepath.Join("testdata", "integration"),
Dockerfile: dockerFile,
},
ExposedPorts: []string{mongoPort},
WaitingFor: wait.ForListeningPort(mongoPort).WithStartupTimeout(time.Minute),
LifecycleHooks: []testcontainers.ContainerLifecycleHooks{{
PostStarts: []testcontainers.ContainerHook{
scraperinttest.RunScript(script),
},
}},
}),
scraperinttest.WithCustomConfig(
func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
rCfg := cfg.(*Config)
cfgMod(rCfg)
rCfg.CollectionInterval = 2 * time.Second
rCfg.MetricsBuilderConfig.Metrics.MongodbLockAcquireTime.Enabled = false
rCfg.Hosts = []confignet.TCPAddrConfig{
{
Endpoint: fmt.Sprintf("%s:%s", ci.Host(t), ci.MappedPort(t, mongoPort)),
},
}
rCfg.Insecure = true
}),
scraperinttest.WithExpectedFile(filepath.Join("testdata", "integration", expectedFile)),
scraperinttest.WithCompareOptions(
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreResourceAttributeValue("server.address"),
),
).Run
}