github.com/mier85/go-sensor@v1.30.1-0.20220920111756-9bf41b3bc7e0/propagation_internal_test.go (about) 1 // (c) Copyright IBM Corp. 2021 2 // (c) Copyright Instana Inc. 2020 3 4 package instana 5 6 import ( 7 "testing" 8 9 "github.com/instana/testify/assert" 10 "github.com/instana/testify/require" 11 ) 12 13 func TestParseLevel(t *testing.T) { 14 examples := map[string]struct { 15 Value string 16 ExpectedSuppressed bool 17 ExpectedCorrelation EUMCorrelationData 18 }{ 19 "empty header": {}, 20 "level=0, no correlation id": { 21 Value: "0", 22 ExpectedSuppressed: true, 23 }, 24 "level=1, no correlation id": { 25 Value: "1", 26 }, 27 "level=0, with correlation id": { 28 Value: "0 , correlationType=web ;\t correlationId=Test Value", 29 ExpectedSuppressed: true, 30 ExpectedCorrelation: EUMCorrelationData{ 31 Type: "web", 32 ID: "Test Value", 33 }, 34 }, 35 "level=1, with correlation id": { 36 Value: "1,correlationType=mobile;correlationId=Test Value", 37 ExpectedCorrelation: EUMCorrelationData{ 38 Type: "mobile", 39 ID: "Test Value", 40 }, 41 }, 42 } 43 44 for name, example := range examples { 45 t.Run(name, func(t *testing.T) { 46 suppressed, corrData, err := parseLevel(example.Value) 47 require.NoError(t, err) 48 assert.Equal(t, example.ExpectedSuppressed, suppressed) 49 assert.Equal(t, example.ExpectedCorrelation, corrData) 50 }) 51 } 52 }