Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

fixtures: rename to testutil #479

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions cmd/trace-agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/trace-agent/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand Down
44 changes: 22 additions & 22 deletions cmd/trace-agent/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions filters/blacklister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)

Expand All @@ -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))
}
}
2 changes: 1 addition & 1 deletion fixtures/backoff.go → testutil/backoff.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fixtures
package testutil

import "time"

Expand Down
2 changes: 1 addition & 1 deletion fixtures/random.go → testutil/random.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fixtures
package testutil

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/services.go → testutil/services.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fixtures
package testutil

import (
"fmt"
Expand Down
10 changes: 4 additions & 6 deletions fixtures/span.go → testutil/span.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/span_test.go → testutil/span_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fixtures
package testutil

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/stats.go → testutil/stats.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fixtures
package testutil

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/stats_test.go → testutil/stats_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fixtures
package testutil

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/statsd.go → testutil/statsd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fixtures
package testutil

import (
"math"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/fixtures.go → testutil/testutil.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion fixtures/trace.go → testutil/trace.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fixtures
package testutil

import (
"math/rand"
Expand Down
5 changes: 2 additions & 3 deletions writer/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions writer/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading