Skip to content

Commit 4b18dd3

Browse files
authored
Organize integration test cases by type (#461)
* Move test fixtures into organized folders * Organize test cases * Update header year * Move protos * Fix typo and unexported vars * make precommit
1 parent 7831d54 commit 4b18dd3

68 files changed

Lines changed: 320 additions & 270 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

exporter/collector/integrationtest/cmd/recordfixtures/main.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525

2626
"github.com/stretchr/testify/require"
2727

28+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/protos"
29+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/testcases"
30+
2831
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest"
2932
)
3033

@@ -63,7 +66,7 @@ func recordTraces(ctx context.Context, t *FakeTesting, startTime, endTime time.T
6366
go testServer.Serve()
6467
defer testServer.Shutdown()
6568

66-
for _, test := range integrationtest.TracesTestCases {
69+
for _, test := range testcases.TracesTestCases {
6770
if test.Skip {
6871
continue
6972
}
@@ -76,7 +79,7 @@ func recordTraces(ctx context.Context, t *FakeTesting, startTime, endTime time.T
7679
require.NoError(t, testServerExporter.Shutdown(ctx))
7780

7881
require.NoError(t, err)
79-
fixture := &integrationtest.TraceExpectFixture{
82+
fixture := &protos.TraceExpectFixture{
8083
BatchWriteSpansRequest: testServer.CreateBatchWriteSpansRequests(),
8184
}
8285
test.SaveRecordedTraceFixtures(t, fixture)
@@ -92,7 +95,7 @@ func recordLogs(ctx context.Context, t *FakeTesting, timestamp time.Time) {
9295
go testServer.Serve()
9396
defer testServer.Shutdown()
9497

95-
for _, test := range integrationtest.LogsTestCases {
98+
for _, test := range testcases.LogsTestCases {
9699
if test.Skip {
97100
continue
98101
}
@@ -104,7 +107,7 @@ func recordLogs(ctx context.Context, t *FakeTesting, timestamp time.Time) {
104107
require.NoError(t, testServerExporter.Shutdown(ctx))
105108

106109
require.NoError(t, err)
107-
fixture := &integrationtest.LogExpectFixture{
110+
fixture := &protos.LogExpectFixture{
108111
WriteLogEntriesRequests: testServer.CreateWriteLogEntriesRequests(),
109112
}
110113
test.SaveRecordedLogFixtures(t, fixture)
@@ -120,7 +123,7 @@ func recordMetrics(ctx context.Context, t *FakeTesting, startTime, endTime time.
120123
go testServer.Serve()
121124
defer testServer.Shutdown()
122125

123-
for _, test := range integrationtest.MetricsTestCases {
126+
for _, test := range testcases.MetricsTestCases {
124127
if test.Skip {
125128
continue
126129
}
@@ -141,7 +144,7 @@ func recordMetrics(ctx context.Context, t *FakeTesting, startTime, endTime time.
141144

142145
selfObsMetrics, err := inMemoryOCExporter.Proto(ctx)
143146
require.NoError(t, err)
144-
fixture := &integrationtest.MetricExpectFixture{
147+
fixture := &protos.MetricExpectFixture{
145148
CreateMetricDescriptorRequests: testServer.CreateMetricDescriptorRequests(),
146149
CreateTimeSeriesRequests: testServer.CreateTimeSeriesRequests(),
147150
CreateServiceTimeSeriesRequests: testServer.CreateServiceTimeSeriesRequests(),

exporter/collector/integrationtest/diff.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import (
2121
"github.com/google/go-cmp/cmp/cmpopts"
2222
"google.golang.org/protobuf/proto"
2323
"google.golang.org/protobuf/testing/protocmp"
24+
25+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/protos"
26+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/testcases"
2427
)
2528

2629
var (
@@ -31,31 +34,31 @@ var (
3134
)
3235

3336
// Diff uses cmp.Diff(), protocmp, and some custom options to compare two protobuf messages.
34-
func DiffMetricProtos(t testing.TB, x, y *MetricExpectFixture) string {
35-
x = proto.Clone(x).(*MetricExpectFixture)
36-
y = proto.Clone(y).(*MetricExpectFixture)
37-
normalizeMetricFixture(t, x)
38-
normalizeMetricFixture(t, y)
37+
func DiffMetricProtos(t testing.TB, x, y *protos.MetricExpectFixture) string {
38+
x = proto.Clone(x).(*protos.MetricExpectFixture)
39+
y = proto.Clone(y).(*protos.MetricExpectFixture)
40+
testcases.NormalizeMetricFixture(t, x)
41+
testcases.NormalizeMetricFixture(t, y)
3942

4043
return cmp.Diff(x, y, cmpOptions...)
4144
}
4245

4346
// Diff uses cmp.Diff(), protocmp, and some custom options to compare two protobuf messages.
44-
func DiffLogProtos(t testing.TB, x, y *LogExpectFixture) string {
45-
x = proto.Clone(x).(*LogExpectFixture)
46-
y = proto.Clone(y).(*LogExpectFixture)
47-
normalizeLogFixture(t, x)
48-
normalizeLogFixture(t, y)
47+
func DiffLogProtos(t testing.TB, x, y *protos.LogExpectFixture) string {
48+
x = proto.Clone(x).(*protos.LogExpectFixture)
49+
y = proto.Clone(y).(*protos.LogExpectFixture)
50+
testcases.NormalizeLogFixture(t, x)
51+
testcases.NormalizeLogFixture(t, y)
4952

5053
return cmp.Diff(x, y, cmpOptions...)
5154
}
5255

5356
// Diff uses cmp.Diff(), protocmp, and some custom options to compare two protobuf messages.
54-
func DiffTraceProtos(t testing.TB, x, y *TraceExpectFixture) string {
55-
x = proto.Clone(x).(*TraceExpectFixture)
56-
y = proto.Clone(y).(*TraceExpectFixture)
57-
normalizeTraceFixture(t, x)
58-
normalizeTraceFixture(t, y)
57+
func DiffTraceProtos(t testing.TB, x, y *protos.TraceExpectFixture) string {
58+
x = proto.Clone(x).(*protos.TraceExpectFixture)
59+
y = proto.Clone(y).(*protos.TraceExpectFixture)
60+
testcases.NormalizeTraceFixture(t, x)
61+
testcases.NormalizeTraceFixture(t, y)
5962

6063
return cmp.Diff(x, y, cmpOptions...)
6164
}

exporter/collector/integrationtest/inmemoryocexporter.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"google.golang.org/grpc"
2727
"google.golang.org/grpc/credentials/insecure"
2828

29+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/protos"
30+
2931
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
3032
)
3133

@@ -43,7 +45,7 @@ func getViews() []*view.View {
4345
return views
4446
}
4547

46-
func (i *InMemoryOCExporter) Proto(ctx context.Context) (*SelfObservabilityMetric, error) {
48+
func (i *InMemoryOCExporter) Proto(ctx context.Context) (*protos.SelfObservabilityMetric, error) {
4749
// Hack to flush stats, see https://tinyurl.com/5hfcxzk2
4850
view.SetReportingPeriod(time.Minute)
4951
i.reader.ReadAndExport(i.stackdriverExporter)
@@ -62,7 +64,7 @@ func (i *InMemoryOCExporter) Proto(ctx context.Context) (*SelfObservabilityMetri
6264
case <-done:
6365
}
6466

65-
return &SelfObservabilityMetric{
67+
return &protos.SelfObservabilityMetric{
6668
CreateTimeSeriesRequests: i.testServer.CreateTimeSeriesRequests(),
6769
CreateMetricDescriptorRequests: i.testServer.CreateMetricDescriptorRequests(),
6870
},

exporter/collector/integrationtest/logs_integration_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"testing"
2424
"time"
2525

26+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/testcases"
2627
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping"
2728
"github.com/stretchr/testify/require"
2829
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -35,7 +36,7 @@ import (
3536
func createLogsExporter(
3637
ctx context.Context,
3738
t *testing.T,
38-
test *TestCase,
39+
test *testcases.TestCase,
3940
) *collector.LogsExporter {
4041
logger, _ := zap.NewProduction()
4142
cfg := test.CreateLogConfig()
@@ -56,7 +57,7 @@ func TestIntegrationLogs(t *testing.T) {
5657
endTime := time.Now()
5758
startTime := endTime.Add(-time.Second)
5859

59-
for _, test := range LogsTestCases {
60+
for _, test := range testcases.LogsTestCases {
6061
test := test
6162

6263
t.Run(test.Name, func(t *testing.T) {
@@ -79,7 +80,7 @@ func TestIntegrationLogs(t *testing.T) {
7980
// the integration test send those logs with a gcp.project.id attribute to the
8081
// specified second project.
8182
func setSecondProjectInLogs(t *testing.T, logs plog.Logs) {
82-
secondProject := os.Getenv(secondProjectEnv)
83+
secondProject := os.Getenv(testcases.SecondProjectEnv)
8384
require.NotEmpty(t, secondProject, "set the SECOND_PROJECT_ID environment to run this test")
8485
for i := 0; i < logs.ResourceLogs().Len(); i++ {
8586
logs.ResourceLogs().At(i).Resource().Attributes().Update(

exporter/collector/integrationtest/logs_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ import (
2020
"time"
2121

2222
"github.com/stretchr/testify/require"
23+
24+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/protos"
25+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/testcases"
2326
)
2427

2528
func TestLogs(t *testing.T) {
2629

2730
ctx := context.Background()
2831
timestamp := time.Now()
2932

30-
for _, test := range LogsTestCases {
33+
for _, test := range testcases.LogsTestCases {
3134
test := test
3235

3336
t.Run(test.Name, func(t *testing.T) {
@@ -53,7 +56,7 @@ func TestLogs(t *testing.T) {
5356

5457
diff := DiffLogProtos(
5558
t,
56-
&LogExpectFixture{
59+
&protos.LogExpectFixture{
5760
WriteLogEntriesRequests: testServer.CreateWriteLogEntriesRequests(),
5861
},
5962
expectFixture,

exporter/collector/integrationtest/metrics_integration_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"testing"
2424
"time"
2525

26+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/testcases"
2627
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping"
2728
"github.com/stretchr/testify/require"
2829
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -35,7 +36,7 @@ import (
3536
func createMetricsExporter(
3637
ctx context.Context,
3738
t *testing.T,
38-
test *TestCase,
39+
test *testcases.TestCase,
3940
) *collector.MetricsExporter {
4041
logger, _ := zap.NewProduction()
4142
cfg := test.CreateMetricConfig()
@@ -58,7 +59,7 @@ func TestIntegrationMetrics(t *testing.T) {
5859
endTime := time.Now()
5960
startTime := endTime.Add(-time.Second)
6061

61-
for _, test := range MetricsTestCases {
62+
for _, test := range testcases.MetricsTestCases {
6263
test := test
6364

6465
t.Run(test.Name, func(t *testing.T) {
@@ -82,7 +83,7 @@ func TestIntegrationMetrics(t *testing.T) {
8283
// the integration test send those metrics with a gcp.project.id attribute to
8384
// the specified second project.
8485
func setSecondProjectInMetrics(t *testing.T, metrics pmetric.Metrics) {
85-
secondProject := os.Getenv(secondProjectEnv)
86+
secondProject := os.Getenv(testcases.SecondProjectEnv)
8687
require.NotEmpty(t, secondProject, "set the SECOND_PROJECT_ID environment to run this test")
8788
for i := 0; i < metrics.ResourceMetrics().Len(); i++ {
8889
metrics.ResourceMetrics().At(i).Resource().Attributes().Update(

exporter/collector/integrationtest/metrics_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ import (
2121
"time"
2222

2323
"github.com/stretchr/testify/require"
24+
25+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/protos"
26+
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/testcases"
2427
)
2528

2629
func TestMetrics(t *testing.T) {
2730
ctx := context.Background()
2831
endTime := time.Now()
2932
startTime := endTime.Add(-time.Second)
3033

31-
for _, test := range MetricsTestCases {
34+
for _, test := range testcases.MetricsTestCases {
3235
test := test
3336

3437
t.Run(test.Name, func(t *testing.T) {
@@ -71,7 +74,7 @@ func TestMetrics(t *testing.T) {
7174

7275
selfObsMetrics, err := inMemoryOCExporter.Proto(ctx)
7376
require.NoError(t, err)
74-
fixture := &MetricExpectFixture{
77+
fixture := &protos.MetricExpectFixture{
7578
CreateTimeSeriesRequests: testServer.CreateTimeSeriesRequests(),
7679
CreateMetricDescriptorRequests: testServer.CreateMetricDescriptorRequests(),
7780
CreateServiceTimeSeriesRequests: testServer.CreateServiceTimeSeriesRequests(),

exporter/collector/integrationtest/fixtures.go renamed to exporter/collector/integrationtest/protos/fixtures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717

1818
//go:generate protoc -I=. --go_opt=paths=source_relative --go_out=. fixtures.proto
1919

20-
package integrationtest
20+
package protos

exporter/collector/integrationtest/fixtures.pb.go renamed to exporter/collector/integrationtest/protos/fixtures.pb.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/collector/integrationtest/fixtures.proto renamed to exporter/collector/integrationtest/protos/fixtures.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
syntax = "proto3";
1616
package fixtures;
17-
option go_package = "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest";
17+
option go_package = "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/internal/integrationtest/protos";
1818

1919
import "metric_service.proto";
2020
import "logging_service.proto";

0 commit comments

Comments
 (0)