forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
60 lines (52 loc) · 1.96 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:build integration
package elasticsearchreceiver
import (
"fmt"
"path/filepath"
"testing"
"time"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
"go.opentelemetry.io/collector/component"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/scraperinttest"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
)
const elasticPort = "9200"
func TestIntegration(t *testing.T) {
t.Run("7.9.3", integrationTest("7_9_3"))
t.Run("7.16.3", integrationTest("7_16_3"))
}
func integrationTest(name string) func(*testing.T) {
dockerFile := fmt.Sprintf("Dockerfile.elasticsearch.%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{elasticPort},
WaitingFor: wait.ForListeningPort(elasticPort).WithStartupTimeout(2 * time.Minute),
}),
scraperinttest.WithCustomConfig(
func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
rCfg := cfg.(*Config)
rCfg.CollectionInterval = 2 * time.Second
rCfg.Endpoint = fmt.Sprintf("http://%s:%s", ci.Host(t), ci.MappedPort(t, elasticPort))
}),
scraperinttest.WithExpectedFile(filepath.Join("testdata", "integration", expectedFile)),
scraperinttest.WithCompareOptions(
pmetrictest.IgnoreResourceAttributeValue("elasticsearch.node.name"),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
),
).Run
}