From 43245bc5e644146714107879d2bbf0e73076de99 Mon Sep 17 00:00:00 2001 From: Gabriel Aszalos Date: Thu, 4 Oct 2018 16:27:58 -0400 Subject: [PATCH] fixtures: rename to testutil --- Makefile | 2 +- cmd/trace-agent/agent_test.go | 4 +- cmd/trace-agent/model_test.go | 4 +- cmd/trace-agent/receiver_test.go | 44 +++++++------- filters/blacklister_test.go | 7 ++- {fixtures => testutil}/backoff.go | 2 +- {fixtures => testutil}/random.go | 2 +- {fixtures => testutil}/services.go | 2 +- {fixtures => testutil}/span.go | 10 ++-- {fixtures => testutil}/span_test.go | 2 +- {fixtures => testutil}/stats.go | 2 +- {fixtures => testutil}/stats_test.go | 2 +- {fixtures => testutil}/statsd.go | 2 +- fixtures/fixtures.go => testutil/testutil.go | 4 +- {fixtures => testutil}/trace.go | 2 +- writer/fixtures_test.go | 5 +- writer/payload_test.go | 14 ++--- writer/service_writer_test.go | 20 +++---- writer/stats_writer_test.go | 60 ++++++++++---------- writer/trace_writer_test.go | 8 +-- 20 files changed, 98 insertions(+), 100 deletions(-) rename {fixtures => testutil}/backoff.go (98%) rename {fixtures => testutil}/random.go (97%) rename {fixtures => testutil}/services.go (97%) rename {fixtures => testutil}/span.go (98%) rename {fixtures => testutil}/span_test.go (95%) rename {fixtures => testutil}/stats.go (99%) rename {fixtures => testutil}/stats_test.go (94%) rename {fixtures => testutil}/statsd.go (99%) rename fixtures/fixtures.go => testutil/testutil.go (84%) rename {fixtures => testutil}/trace.go (99%) diff --git a/Makefile b/Makefile index 3ed92a23d..12af28f24 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ ci: # task used by CI GOOS=windows go build ./cmd/trace-agent # ensure windows builds go get -u github.com/golang/lint/golint/... - golint -set_exit_status=1 ./cmd/trace-agent ./filters ./fixtures ./info ./quantile ./obfuscate ./sampler ./statsd ./watchdog ./writer ./flags ./osutil + golint -set_exit_status=1 ./cmd/trace-agent ./filters ./testutil ./info ./quantile ./obfuscate ./sampler ./statsd ./watchdog ./writer ./flags ./osutil go test -v ./... windows: diff --git a/cmd/trace-agent/agent_test.go b/cmd/trace-agent/agent_test.go index dc56635dd..b8b2ab695 100644 --- a/cmd/trace-agent/agent_test.go +++ b/cmd/trace-agent/agent_test.go @@ -13,10 +13,10 @@ import ( log "github.com/cihub/seelog" "github.com/DataDog/datadog-trace-agent/config" - "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/info" "github.com/DataDog/datadog-trace-agent/model" "github.com/DataDog/datadog-trace-agent/obfuscate" + "github.com/DataDog/datadog-trace-agent/testutil" "github.com/stretchr/testify/assert" ) @@ -208,7 +208,7 @@ func runTraceProcessingBenchmark(b *testing.B, c *config.AgentConfig) { b.ResetTimer() b.ReportAllocs() for i := 0; i < b.N; i++ { - agent.Process(fixtures.RandomTrace(10, 8)) + agent.Process(testutil.RandomTrace(10, 8)) } } diff --git a/cmd/trace-agent/model_test.go b/cmd/trace-agent/model_test.go index d80a0cec0..0e93b3d52 100644 --- a/cmd/trace-agent/model_test.go +++ b/cmd/trace-agent/model_test.go @@ -6,8 +6,8 @@ package main import ( "testing" - "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/model" + "github.com/DataDog/datadog-trace-agent/testutil" ) const ( @@ -21,7 +21,7 @@ func BenchmarkHandleSpanRandom(b *testing.B) { b.ResetTimer() b.ReportAllocs() for i := 0; i < b.N; i++ { - trace := fixtures.RandomTrace(10, 8) + trace := testutil.RandomTrace(10, 8) root := trace.GetRoot() trace.ComputeTopLevel() wt := model.NewWeightedTrace(trace, root) diff --git a/cmd/trace-agent/receiver_test.go b/cmd/trace-agent/receiver_test.go index fa440bcb0..ddf1c398e 100644 --- a/cmd/trace-agent/receiver_test.go +++ b/cmd/trace-agent/receiver_test.go @@ -14,10 +14,10 @@ import ( "time" "github.com/DataDog/datadog-trace-agent/config" - "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/info" "github.com/DataDog/datadog-trace-agent/model" "github.com/DataDog/datadog-trace-agent/sampler" + "github.com/DataDog/datadog-trace-agent/testutil" "github.com/stretchr/testify/assert" "github.com/tinylib/msgp/msgp" ) @@ -113,8 +113,8 @@ func TestLegacyReceiver(t *testing.T) { contentType string traces model.Trace }{ - {"v01 with empty content-type", NewTestReceiverFromConfig(conf), v01, "", model.Trace{fixtures.GetTestSpan()}}, - {"v01 with application/json", NewTestReceiverFromConfig(conf), v01, "application/json", model.Trace{fixtures.GetTestSpan()}}, + {"v01 with empty content-type", NewTestReceiverFromConfig(conf), v01, "", model.Trace{testutil.GetTestSpan()}}, + {"v01 with application/json", NewTestReceiverFromConfig(conf), v01, "application/json", model.Trace{testutil.GetTestSpan()}}, } for _, tc := range testCases { @@ -169,15 +169,15 @@ func TestReceiverJSONDecoder(t *testing.T) { contentType string traces []model.Trace }{ - {"v02 with empty content-type", NewTestReceiverFromConfig(conf), v02, "", fixtures.GetTestTrace(1, 1, false)}, - {"v03 with empty content-type", NewTestReceiverFromConfig(conf), v03, "", fixtures.GetTestTrace(1, 1, false)}, - {"v04 with empty content-type", NewTestReceiverFromConfig(conf), v04, "", fixtures.GetTestTrace(1, 1, false)}, - {"v02 with application/json", NewTestReceiverFromConfig(conf), v02, "application/json", fixtures.GetTestTrace(1, 1, false)}, - {"v03 with application/json", NewTestReceiverFromConfig(conf), v03, "application/json", fixtures.GetTestTrace(1, 1, false)}, - {"v04 with application/json", NewTestReceiverFromConfig(conf), v04, "application/json", fixtures.GetTestTrace(1, 1, false)}, - {"v02 with text/json", NewTestReceiverFromConfig(conf), v02, "text/json", fixtures.GetTestTrace(1, 1, false)}, - {"v03 with text/json", NewTestReceiverFromConfig(conf), v03, "text/json", fixtures.GetTestTrace(1, 1, false)}, - {"v04 with text/json", NewTestReceiverFromConfig(conf), v04, "text/json", fixtures.GetTestTrace(1, 1, false)}, + {"v02 with empty content-type", NewTestReceiverFromConfig(conf), v02, "", testutil.GetTestTrace(1, 1, false)}, + {"v03 with empty content-type", NewTestReceiverFromConfig(conf), v03, "", testutil.GetTestTrace(1, 1, false)}, + {"v04 with empty content-type", NewTestReceiverFromConfig(conf), v04, "", testutil.GetTestTrace(1, 1, false)}, + {"v02 with application/json", NewTestReceiverFromConfig(conf), v02, "application/json", testutil.GetTestTrace(1, 1, false)}, + {"v03 with application/json", NewTestReceiverFromConfig(conf), v03, "application/json", testutil.GetTestTrace(1, 1, false)}, + {"v04 with application/json", NewTestReceiverFromConfig(conf), v04, "application/json", testutil.GetTestTrace(1, 1, false)}, + {"v02 with text/json", NewTestReceiverFromConfig(conf), v02, "text/json", testutil.GetTestTrace(1, 1, false)}, + {"v03 with text/json", NewTestReceiverFromConfig(conf), v03, "text/json", testutil.GetTestTrace(1, 1, false)}, + {"v04 with text/json", NewTestReceiverFromConfig(conf), v04, "text/json", testutil.GetTestTrace(1, 1, false)}, } for _, tc := range testCases { @@ -233,10 +233,10 @@ func TestReceiverMsgpackDecoder(t *testing.T) { contentType string traces model.Traces }{ - {"v01 with application/msgpack", NewTestReceiverFromConfig(conf), v01, "application/msgpack", fixtures.GetTestTrace(1, 1, false)}, - {"v02 with application/msgpack", NewTestReceiverFromConfig(conf), v02, "application/msgpack", fixtures.GetTestTrace(1, 1, false)}, - {"v03 with application/msgpack", NewTestReceiverFromConfig(conf), v03, "application/msgpack", fixtures.GetTestTrace(1, 1, false)}, - {"v04 with application/msgpack", NewTestReceiverFromConfig(conf), v04, "application/msgpack", fixtures.GetTestTrace(1, 1, false)}, + {"v01 with application/msgpack", NewTestReceiverFromConfig(conf), v01, "application/msgpack", testutil.GetTestTrace(1, 1, false)}, + {"v02 with application/msgpack", NewTestReceiverFromConfig(conf), v02, "application/msgpack", testutil.GetTestTrace(1, 1, false)}, + {"v03 with application/msgpack", NewTestReceiverFromConfig(conf), v03, "application/msgpack", testutil.GetTestTrace(1, 1, false)}, + {"v04 with application/msgpack", NewTestReceiverFromConfig(conf), v04, "application/msgpack", testutil.GetTestTrace(1, 1, false)}, } for _, tc := range testCases { @@ -492,7 +492,7 @@ func TestHandleTraces(t *testing.T) { // prepare the msgpack payload var buf bytes.Buffer - msgp.Encode(&buf, fixtures.GetTestTrace(10, 10, true)) + msgp.Encode(&buf, testutil.GetTestTrace(10, 10, true)) // prepare the receiver conf := NewTestReceiverConfig() @@ -556,7 +556,7 @@ func TestReceiverPreSamplerCancel(t *testing.T) { var buf bytes.Buffer n := 100 // Payloads need to be big enough, else bug is not triggered - msgp.Encode(&buf, fixtures.GetTestTrace(n, n, true)) + msgp.Encode(&buf, testutil.GetTestTrace(n, n, true)) conf := NewTestReceiverConfig() conf.PreSampleRate = 0.000001 // Make sure we sample aggressively @@ -598,7 +598,7 @@ func BenchmarkHandleTracesFromOneApp(b *testing.B) { // prepare the payload // msgpack payload var buf bytes.Buffer - msgp.Encode(&buf, fixtures.GetTestTrace(1, 1, true)) + msgp.Encode(&buf, testutil.GetTestTrace(1, 1, true)) // prepare the receiver conf := NewTestReceiverConfig() @@ -638,7 +638,7 @@ func BenchmarkHandleTracesFromMultipleApps(b *testing.B) { // prepare the payload // msgpack payload var buf bytes.Buffer - msgp.Encode(&buf, fixtures.GetTestTrace(1, 1, true)) + msgp.Encode(&buf, testutil.GetTestTrace(1, 1, true)) // prepare the receiver conf := NewTestReceiverConfig() @@ -676,7 +676,7 @@ func BenchmarkHandleTracesFromMultipleApps(b *testing.B) { func BenchmarkDecoderJSON(b *testing.B) { assert := assert.New(b) - traces := fixtures.GetTestTrace(150, 66, true) + traces := testutil.GetTestTrace(150, 66, true) // json payload payload, err := json.Marshal(traces) @@ -701,7 +701,7 @@ func BenchmarkDecoderMsgpack(b *testing.B) { // msgpack payload var buf bytes.Buffer - err := msgp.Encode(&buf, fixtures.GetTestTrace(150, 66, true)) + err := msgp.Encode(&buf, testutil.GetTestTrace(150, 66, true)) assert.Nil(err) // benchmark diff --git a/filters/blacklister_test.go b/filters/blacklister_test.go index 87c9065d3..d163b6f7e 100644 --- a/filters/blacklister_test.go +++ b/filters/blacklister_test.go @@ -3,7 +3,8 @@ package filters import ( "testing" - "github.com/DataDog/datadog-trace-agent/fixtures" + "github.com/DataDog/datadog-trace-agent/testutil" + "github.com/stretchr/testify/assert" ) @@ -30,7 +31,7 @@ func TestBlacklister(t *testing.T) { } for _, test := range tests { - span := fixtures.RandomSpan() + span := testutil.RandomSpan() span.Resource = test.resource filter := NewBlacklister(test.filter) @@ -41,7 +42,7 @@ func TestBlacklister(t *testing.T) { func TestCompileRules(t *testing.T) { filter := NewBlacklister([]string{"[123", "]123", "{6}"}) for i := 0; i < 100; i++ { - span := fixtures.RandomSpan() + span := testutil.RandomSpan() assert.True(t, filter.Allows(span)) } } diff --git a/fixtures/backoff.go b/testutil/backoff.go similarity index 98% rename from fixtures/backoff.go rename to testutil/backoff.go index 57cc62241..933f86627 100644 --- a/fixtures/backoff.go +++ b/testutil/backoff.go @@ -1,4 +1,4 @@ -package fixtures +package testutil import "time" diff --git a/fixtures/random.go b/testutil/random.go similarity index 97% rename from fixtures/random.go rename to testutil/random.go index fca7d1290..f878917c7 100644 --- a/fixtures/random.go +++ b/testutil/random.go @@ -1,4 +1,4 @@ -package fixtures +package testutil import ( "bytes" diff --git a/fixtures/services.go b/testutil/services.go similarity index 97% rename from fixtures/services.go rename to testutil/services.go index 0d20e0741..ccc9f02b2 100644 --- a/fixtures/services.go +++ b/testutil/services.go @@ -1,4 +1,4 @@ -package fixtures +package testutil import ( "fmt" diff --git a/fixtures/span.go b/testutil/span.go similarity index 98% rename from fixtures/span.go rename to testutil/span.go index 3a0a35191..991545c20 100644 --- a/fixtures/span.go +++ b/testutil/span.go @@ -1,10 +1,8 @@ -/* -In this file we define methods and global variables to: -* allow generation of arbitrary/random VALID spans -* pick random attributes for a span -*/ +// In this file we define methods and global variables to: +// allow generation of arbitrary/random VALID spans +// pick random attributes for a span -package fixtures +package testutil import ( "math/rand" diff --git a/fixtures/span_test.go b/testutil/span_test.go similarity index 95% rename from fixtures/span_test.go rename to testutil/span_test.go index 101cf1842..046b25519 100644 --- a/fixtures/span_test.go +++ b/testutil/span_test.go @@ -1,4 +1,4 @@ -package fixtures +package testutil import ( "testing" diff --git a/fixtures/stats.go b/testutil/stats.go similarity index 99% rename from fixtures/stats.go rename to testutil/stats.go index 94679ccef..e25a2828d 100644 --- a/fixtures/stats.go +++ b/testutil/stats.go @@ -1,4 +1,4 @@ -package fixtures +package testutil import ( "encoding/json" diff --git a/fixtures/stats_test.go b/testutil/stats_test.go similarity index 94% rename from fixtures/stats_test.go rename to testutil/stats_test.go index 0922c2432..eea717e52 100644 --- a/fixtures/stats_test.go +++ b/testutil/stats_test.go @@ -1,4 +1,4 @@ -package fixtures +package testutil import ( "testing" diff --git a/fixtures/statsd.go b/testutil/statsd.go similarity index 99% rename from fixtures/statsd.go rename to testutil/statsd.go index 1a8ea12f7..4bae35c13 100644 --- a/fixtures/statsd.go +++ b/testutil/statsd.go @@ -1,4 +1,4 @@ -package fixtures +package testutil import ( "math" diff --git a/fixtures/fixtures.go b/testutil/testutil.go similarity index 84% rename from fixtures/fixtures.go rename to testutil/testutil.go index b68697648..5456c9641 100644 --- a/fixtures/fixtures.go +++ b/testutil/testutil.go @@ -1,4 +1,4 @@ -// Package fixtures provides easy ways to generate some random +// Package testutil provides easy ways to generate some random // or deterministic data that can be use for tests or benchmarks. // // All the publicly shared trace agent model is available. @@ -8,4 +8,4 @@ // access to almost all kind of stub data needed. // It should NEVER be imported in a program, most likely in one-off // projects or fuzz modes or test suites. -package fixtures +package testutil diff --git a/fixtures/trace.go b/testutil/trace.go similarity index 99% rename from fixtures/trace.go rename to testutil/trace.go index d29a14635..749fd1756 100644 --- a/fixtures/trace.go +++ b/testutil/trace.go @@ -1,4 +1,4 @@ -package fixtures +package testutil import ( "math/rand" diff --git a/writer/fixtures_test.go b/writer/fixtures_test.go index 62f74ac22..07f707069 100644 --- a/writer/fixtures_test.go +++ b/writer/fixtures_test.go @@ -4,9 +4,8 @@ import ( "math/rand" "sync" + "github.com/DataDog/datadog-trace-agent/testutil" log "github.com/cihub/seelog" - - "github.com/DataDog/datadog-trace-agent/fixtures" ) // payloadConstructedHandlerArgs encodes the arguments passed to a PayloadConstructedHandler call. @@ -75,7 +74,7 @@ func RandomPayload() *Payload { // RandomSizedPayload creates a new payload instance using random data with the specified size. func RandomSizedPayload(size int) *Payload { - return NewPayload(fixtures.RandomSizedBytes(size), fixtures.RandomStringMap()) + return NewPayload(testutil.RandomSizedBytes(size), testutil.RandomStringMap()) } // testPayloadSender is a PayloadSender that is connected to a testEndpoint, used for testing. diff --git a/writer/payload_test.go b/writer/payload_test.go index 2c0bd6ddb..76e2ee20e 100644 --- a/writer/payload_test.go +++ b/writer/payload_test.go @@ -6,7 +6,7 @@ import ( "time" "github.com/DataDog/datadog-trace-agent/backoff" - "github.com/DataDog/datadog-trace-agent/fixtures" + "github.com/DataDog/datadog-trace-agent/testutil" writerconfig "github.com/DataDog/datadog-trace-agent/writer/config" "github.com/stretchr/testify/assert" ) @@ -68,7 +68,7 @@ func TestQueuablePayloadSender_FlakyEndpoint(t *testing.T) { flakyEndpoint := &testEndpoint{} // And a test backoff timer that can be triggered on-demand - testBackoffTimer := fixtures.NewTestBackoffTimer() + testBackoffTimer := testutil.NewTestBackoffTimer() // And a queuable sender using said endpoint and timer conf := writerconfig.DefaultQueuablePayloadSenderConf() @@ -167,7 +167,7 @@ func TestQueuablePayloadSender_MaxQueuedPayloads(t *testing.T) { flakyEndpoint.SetError(&RetriableError{err: fmt.Errorf("bleh"), endpoint: flakyEndpoint}) // And a test backoff timer that can be triggered on-demand - testBackoffTimer := fixtures.NewTestBackoffTimer() + testBackoffTimer := testutil.NewTestBackoffTimer() // And a queuable sender using said endpoint and timer and with a meager max queued payloads value of 1 conf := writerconfig.DefaultQueuablePayloadSenderConf() @@ -237,7 +237,7 @@ func TestQueuablePayloadSender_MaxQueuedBytes(t *testing.T) { flakyEndpoint.SetError(&RetriableError{err: fmt.Errorf("bleh"), endpoint: flakyEndpoint}) // And a test backoff timer that can be triggered on-demand - testBackoffTimer := fixtures.NewTestBackoffTimer() + testBackoffTimer := testutil.NewTestBackoffTimer() // And a queuable sender using said endpoint and timer and with a meager max size of 10 bytes conf := writerconfig.DefaultQueuablePayloadSenderConf() @@ -306,7 +306,7 @@ func TestQueuablePayloadSender_DropBigPayloadsOnRetry(t *testing.T) { flakyEndpoint.SetError(&RetriableError{err: fmt.Errorf("bleh"), endpoint: flakyEndpoint}) // And a test backoff timer that can be triggered on-demand - testBackoffTimer := fixtures.NewTestBackoffTimer() + testBackoffTimer := testutil.NewTestBackoffTimer() // And a queuable sender using said endpoint and timer and with a meager max size of 10 bytes conf := writerconfig.DefaultQueuablePayloadSenderConf() @@ -362,7 +362,7 @@ func TestQueuablePayloadSender_SendBigPayloadsIfNoRetry(t *testing.T) { workingEndpoint := &testEndpoint{} // And a test backoff timer that can be triggered on-demand - testBackoffTimer := fixtures.NewTestBackoffTimer() + testBackoffTimer := testutil.NewTestBackoffTimer() // And a queuable sender using said endpoint and timer and with a meager max size of 10 bytes conf := writerconfig.DefaultQueuablePayloadSenderConf() @@ -408,7 +408,7 @@ func TestQueuablePayloadSender_MaxAge(t *testing.T) { flakyEndpoint.SetError(&RetriableError{err: fmt.Errorf("bleh"), endpoint: flakyEndpoint}) // And a test backoff timer that can be triggered on-demand - testBackoffTimer := fixtures.NewTestBackoffTimer() + testBackoffTimer := testutil.NewTestBackoffTimer() // And a queuable sender using said endpoint and timer and with a meager max age of 100ms conf := writerconfig.DefaultQueuablePayloadSenderConf() diff --git a/writer/service_writer_test.go b/writer/service_writer_test.go index 878c50fd9..c4ec6f627 100644 --- a/writer/service_writer_test.go +++ b/writer/service_writer_test.go @@ -8,9 +8,9 @@ import ( "time" "github.com/DataDog/datadog-trace-agent/config" - "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/info" "github.com/DataDog/datadog-trace-agent/model" + "github.com/DataDog/datadog-trace-agent/testutil" writerconfig "github.com/DataDog/datadog-trace-agent/writer/config" "github.com/stretchr/testify/assert" ) @@ -38,20 +38,20 @@ func TestServiceWriter_ServiceHandling(t *testing.T) { serviceWriter.Start() // Given a set of service metadata - metadata1 := fixtures.RandomServices(10, 10) + metadata1 := testutil.RandomServices(10, 10) // When sending it serviceChannel <- metadata1 // And then immediately sending another set of service metadata - metadata2 := fixtures.RandomServices(10, 10) + metadata2 := testutil.RandomServices(10, 10) serviceChannel <- metadata2 // And then waiting for more than flush period time.Sleep(2 * serviceWriter.conf.FlushPeriod) // And then sending a third set of service metadata - metadata3 := fixtures.RandomServices(10, 10) + metadata3 := testutil.RandomServices(10, 10) serviceChannel <- metadata3 // And stopping service writer before flush ticker ticks (should still flush on exit though) @@ -90,7 +90,7 @@ func TestServiceWriter_UpdateInfoHandling(t *testing.T) { // When sending a set of metadata expectedNumPayloads++ - metadata1 := fixtures.RandomServices(10, 10) + metadata1 := testutil.RandomServices(10, 10) serviceChannel <- metadata1 expectedNumServices += int64(len(metadata1)) expectedNumBytes += calculateMetadataPayloadSize(metadata1) @@ -100,7 +100,7 @@ func TestServiceWriter_UpdateInfoHandling(t *testing.T) { // And then sending a second set of metadata expectedNumPayloads++ - metadata2 := fixtures.RandomServices(10, 10) + metadata2 := testutil.RandomServices(10, 10) serviceChannel <- metadata2 expectedNumServices += int64(len(metadata2)) expectedNumBytes += calculateMetadataPayloadSize(metadata2) @@ -111,7 +111,7 @@ func TestServiceWriter_UpdateInfoHandling(t *testing.T) { // And then sending a third payload with other 3 traces with an errored out endpoint with no retry testEndpoint.SetError(fmt.Errorf("non retriable error")) expectedNumErrors++ - metadata3 := fixtures.RandomServices(10, 10) + metadata3 := testutil.RandomServices(10, 10) serviceChannel <- metadata3 expectedNumServices += int64(len(metadata3)) expectedNumBytes += calculateMetadataPayloadSize(metadata3) @@ -125,7 +125,7 @@ func TestServiceWriter_UpdateInfoHandling(t *testing.T) { endpoint: testEndpoint, }) expectedMinNumRetries++ - metadata4 := fixtures.RandomServices(10, 10) + metadata4 := testutil.RandomServices(10, 10) serviceChannel <- metadata4 expectedNumServices += int64(len(metadata4)) expectedNumBytes += calculateMetadataPayloadSize(metadata4) @@ -193,7 +193,7 @@ func assertMetadata(assert *assert.Assertions, expectedHeaders map[string]string assert.Equal(expectedMetadata, servicesMetadata, "Service metadata should match expectation") } -func testServiceWriter() (*ServiceWriter, chan model.ServicesMetadata, *testEndpoint, *fixtures.TestStatsClient) { +func testServiceWriter() (*ServiceWriter, chan model.ServicesMetadata, *testEndpoint, *testutil.TestStatsClient) { serviceChannel := make(chan model.ServicesMetadata) conf := &config.AgentConfig{ ServiceWriterConfig: writerconfig.DefaultServiceWriterConfig(), @@ -201,7 +201,7 @@ func testServiceWriter() (*ServiceWriter, chan model.ServicesMetadata, *testEndp serviceWriter := NewServiceWriter(conf, serviceChannel) testEndpoint := &testEndpoint{} serviceWriter.BaseWriter.payloadSender.setEndpoint(testEndpoint) - testStatsClient := &fixtures.TestStatsClient{} + testStatsClient := &testutil.TestStatsClient{} serviceWriter.statsClient = testStatsClient return serviceWriter, serviceChannel, testEndpoint, testStatsClient diff --git a/writer/stats_writer_test.go b/writer/stats_writer_test.go index c3f0c9c6a..34af08f61 100644 --- a/writer/stats_writer_test.go +++ b/writer/stats_writer_test.go @@ -11,9 +11,9 @@ import ( "time" "github.com/DataDog/datadog-trace-agent/config" - "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/info" "github.com/DataDog/datadog-trace-agent/model" + "github.com/DataDog/datadog-trace-agent/testutil" writerconfig "github.com/DataDog/datadog-trace-agent/writer/config" "github.com/stretchr/testify/assert" ) @@ -28,14 +28,14 @@ func TestStatsWriter_StatHandling(t *testing.T) { // Given 2 slices of 3 test buckets testStats1 := []model.StatsBucket{ - fixtures.RandomStatsBucket(3), - fixtures.RandomStatsBucket(3), - fixtures.RandomStatsBucket(3), + testutil.RandomStatsBucket(3), + testutil.RandomStatsBucket(3), + testutil.RandomStatsBucket(3), } testStats2 := []model.StatsBucket{ - fixtures.RandomStatsBucket(3), - fixtures.RandomStatsBucket(3), - fixtures.RandomStatsBucket(3), + testutil.RandomStatsBucket(3), + testutil.RandomStatsBucket(3), + testutil.RandomStatsBucket(3), } // When sending those slices @@ -82,9 +82,9 @@ func TestStatsWriter_UpdateInfoHandling(t *testing.T) { // When sending 1 payload with 3 buckets expectedNumPayloads++ payload1Buckets := []model.StatsBucket{ - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), } statsChannel <- payload1Buckets expectedNumBuckets += 3 @@ -93,9 +93,9 @@ func TestStatsWriter_UpdateInfoHandling(t *testing.T) { // And another one with another 3 buckets expectedNumPayloads++ payload2Buckets := []model.StatsBucket{ - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), } statsChannel <- payload2Buckets expectedNumBuckets += 3 @@ -108,9 +108,9 @@ func TestStatsWriter_UpdateInfoHandling(t *testing.T) { testEndpoint.SetError(fmt.Errorf("non retriable error")) expectedNumErrors++ payload3Buckets := []model.StatsBucket{ - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), } statsChannel <- payload3Buckets expectedNumBuckets += 3 @@ -126,9 +126,9 @@ func TestStatsWriter_UpdateInfoHandling(t *testing.T) { }) expectedMinNumRetries++ payload4Buckets := []model.StatsBucket{ - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), } statsChannel <- payload4Buckets expectedNumBuckets += 3 @@ -180,9 +180,9 @@ func TestStatsWriter_BuildPayloads(t *testing.T) { // spans per stat bucket. Each buckets have the same // time window (start: 0, duration 1e9). stats := []model.StatsBucket{ - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), } // Remove duplicates so that we have a predictable state. In another @@ -222,9 +222,9 @@ func TestStatsWriter_BuildPayloads(t *testing.T) { // spans per stat bucket. Each buckets have the same // time window (start: 0, duration 1e9). stats := []model.StatsBucket{ - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), } // Remove duplicates so that we have a predictable @@ -286,9 +286,9 @@ func TestStatsWriter_BuildPayloads(t *testing.T) { // stat bucket. Each buckets have the same time window (start: // 0, duration 1e9). stats := []model.StatsBucket{ - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), - fixtures.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), + testutil.RandomStatsBucket(5), } payloads, nbStatBuckets, nbEntries := sw.buildPayloads(stats, 1337) @@ -384,7 +384,7 @@ func assertStatsPayload(assert *assert.Assertions, headers map[string]string, bu assert.Equal(buckets, statsPayload.Stats, "Stat buckets should match expectation") } -func testStatsWriter() (*StatsWriter, chan []model.StatsBucket, *testEndpoint, *fixtures.TestStatsClient) { +func testStatsWriter() (*StatsWriter, chan []model.StatsBucket, *testEndpoint, *testutil.TestStatsClient) { statsChannel := make(chan []model.StatsBucket) conf := &config.AgentConfig{ Hostname: testHostName, @@ -394,7 +394,7 @@ func testStatsWriter() (*StatsWriter, chan []model.StatsBucket, *testEndpoint, * statsWriter := NewStatsWriter(conf, statsChannel) testEndpoint := &testEndpoint{} statsWriter.BaseWriter.payloadSender.setEndpoint(testEndpoint) - testStatsClient := &fixtures.TestStatsClient{} + testStatsClient := &testutil.TestStatsClient{} statsWriter.statsClient = testStatsClient return statsWriter, statsChannel, testEndpoint, testStatsClient diff --git a/writer/trace_writer_test.go b/writer/trace_writer_test.go index 755a981c1..e5fcf82be 100644 --- a/writer/trace_writer_test.go +++ b/writer/trace_writer_test.go @@ -10,9 +10,9 @@ import ( "time" "github.com/DataDog/datadog-trace-agent/config" - "github.com/DataDog/datadog-trace-agent/fixtures" "github.com/DataDog/datadog-trace-agent/info" "github.com/DataDog/datadog-trace-agent/model" + "github.com/DataDog/datadog-trace-agent/testutil" writerconfig "github.com/DataDog/datadog-trace-agent/writer/config" "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/assert" @@ -335,7 +335,7 @@ func assertPayloads(assert *assert.Assertions, traceWriter *TraceWriter, expecte } } -func testTraceWriter() (*TraceWriter, chan *SampledTrace, *testEndpoint, *fixtures.TestStatsClient) { +func testTraceWriter() (*TraceWriter, chan *SampledTrace, *testEndpoint, *testutil.TestStatsClient) { payloadChannel := make(chan *SampledTrace) conf := &config.AgentConfig{ Hostname: testHostName, @@ -345,7 +345,7 @@ func testTraceWriter() (*TraceWriter, chan *SampledTrace, *testEndpoint, *fixtur traceWriter := NewTraceWriter(conf, payloadChannel) testEndpoint := &testEndpoint{} traceWriter.BaseWriter.payloadSender.setEndpoint(testEndpoint) - testStatsClient := &fixtures.TestStatsClient{} + testStatsClient := &testutil.TestStatsClient{} traceWriter.statsClient = testStatsClient return traceWriter, payloadChannel, testEndpoint, testStatsClient @@ -356,7 +356,7 @@ func randomSampledTrace(numSpans, numTransactions int) *SampledTrace { panic("can't have more transactions than spans in a RandomSampledTrace") } - trace := fixtures.GetTestTrace(1, numSpans, true)[0] + trace := testutil.GetTestTrace(1, numSpans, true)[0] return &SampledTrace{ Trace: &trace,