Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhulston committed Oct 8, 2024
1 parent 0b69656 commit 5920275
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions contrib/aws/aws-sdk-go-v2/aws/eventbridge/eventbridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"encoding/json"
"strconv"
"strings"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -159,3 +160,53 @@ func TestInjectTraceContext(t *testing.T) {
})
}
}

func TestInjectTraceContextSizeLimit(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()

ctx := context.Background()
_, ctx = tracer.StartSpanFromContext(ctx, "test-span")

tests := []struct {
name string
entry types.PutEventsRequestEntry
expected func(*testing.T, *types.PutEventsRequestEntry)
}{
{
name: "Do not inject when payload is too large",
entry: types.PutEventsRequestEntry{
Detail: aws.String(`{"large": "` + strings.Repeat("a", maxSizeBytes-15) + `"}`),
EventBusName: aws.String("test-bus"),
},
expected: func(t *testing.T, entry *types.PutEventsRequestEntry) {
assert.GreaterOrEqual(t, len(*entry.Detail), maxSizeBytes-15)
assert.NotContains(t, *entry.Detail, datadogKey)
assert.True(t, strings.HasPrefix(*entry.Detail, `{"large": "`))
assert.True(t, strings.HasSuffix(*entry.Detail, `"}`))
},
},
{
name: "Inject when payload is just under the limit",
entry: types.PutEventsRequestEntry{
Detail: aws.String(`{"large": "` + strings.Repeat("a", maxSizeBytes-1000) + `"}`),
EventBusName: aws.String("test-bus"),
},
expected: func(t *testing.T, entry *types.PutEventsRequestEntry) {
assert.Less(t, len(*entry.Detail), maxSizeBytes)
var detail map[string]interface{}
err := json.Unmarshal([]byte(*entry.Detail), &detail)
require.NoError(t, err)
assert.Contains(t, detail, datadogKey)
assert.Contains(t, detail, "large")
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
injectTraceContext(ctx, &tt.entry)
tt.expected(t, &tt.entry)
})
}
}

0 comments on commit 5920275

Please sign in to comment.