From f46ff84903f1b422f2e20cb83d3f0bcf22b27c01 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Wed, 5 Jun 2024 12:50:10 +0100 Subject: [PATCH] clean-up tests --- .../baggage/baggagetrace/processor_test.go | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/processors/baggage/baggagetrace/processor_test.go b/processors/baggage/baggagetrace/processor_test.go index 32031ef2f02..e01c91f97dd 100644 --- a/processors/baggage/baggagetrace/processor_test.go +++ b/processors/baggage/baggagetrace/processor_test.go @@ -34,14 +34,10 @@ func NewTestExporter() *testExporter { return &testExporter{} } -func TestSpanProcessorAppendsBaggageAttributes(t *testing.T) { - suitcase, err := otelbaggage.New() - require.NoError(t, err) - packingCube, err := otelbaggage.NewMemberRaw("baggage.test", "baggage value") - require.NoError(t, err) - suitcase, err = suitcase.SetMember(packingCube) - require.NoError(t, err) - ctx := otelbaggage.ContextWithBaggage(context.Background(), suitcase) +func TestSpanProcessorAppendsAllBaggageAttributes(t *testing.T) { + baggage, _ := otelbaggage.New() + baggage = addEntryToBaggage(baggage, "baggage.test", "baggage value") + ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage) // create trace provider with baggage processor and test exporter exporter := NewTestExporter() @@ -63,13 +59,9 @@ func TestSpanProcessorAppendsBaggageAttributes(t *testing.T) { } func TestSpanProcessorAppendsBaggageAttributesWithHaPrefixPredicate(t *testing.T) { - suitcase, err := otelbaggage.New() - require.NoError(t, err) - packingCube, err := otelbaggage.NewMemberRaw("baggage.test", "baggage value") - require.NoError(t, err) - suitcase, err = suitcase.SetMember(packingCube) - require.NoError(t, err) - ctx := otelbaggage.ContextWithBaggage(context.Background(), suitcase) + baggage, _ := otelbaggage.New() + baggage = addEntryToBaggage(baggage, "baggage.test", "baggage value") + ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage) baggageKeyPredicate := func(key string) bool { return strings.HasPrefix(key, "baggage.") @@ -95,13 +87,9 @@ func TestSpanProcessorAppendsBaggageAttributesWithHaPrefixPredicate(t *testing.T } func TestSpanProcessorAppendsBaggageAttributesWithRegexPredicate(t *testing.T) { - suitcase, err := otelbaggage.New() - require.NoError(t, err) - packingCube, err := otelbaggage.NewMemberRaw("baggage.test", "baggage value") - require.NoError(t, err) - suitcase, err = suitcase.SetMember(packingCube) - require.NoError(t, err) - ctx := otelbaggage.ContextWithBaggage(context.Background(), suitcase) + baggage, _ := otelbaggage.New() + baggage = addEntryToBaggage(baggage, "baggage.test", "baggage value") + ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage) expr := regexp.MustCompile(`^baggage\..*`) baggageKeyPredicate := func(key string) bool { @@ -131,7 +119,6 @@ func TestOnlyAddsBaggageEntriesThatMatchPredicate(t *testing.T) { baggage, _ := otelbaggage.New() baggage = addEntryToBaggage(baggage, "foo", "foo value") baggage = addEntryToBaggage(baggage, "bar", "bar value") - ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage) baggageKeyPredicate := func(key string) bool {