github.com/thanos-io/thanos@v0.32.5/pkg/tracing/lightstep/lightstep_test.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package lightstep 5 6 import ( 7 "os" 8 "testing" 9 10 "github.com/efficientgo/core/testutil" 11 12 "github.com/opentracing/opentracing-go" 13 ) 14 15 func TestParseTags(t *testing.T) { 16 type testData struct { 17 input string 18 description string 19 expectedOutput opentracing.Tags 20 } 21 22 testingData := []testData{ 23 { 24 description: `A very simple case, key "foo" and value "bar"`, 25 input: "foo=bar", 26 expectedOutput: opentracing.Tags{"foo": "bar"}, 27 }, 28 { 29 description: `A simple case multiple keys, keys ["foo", "bar"] and values ["foo", "bar"]`, 30 input: "foo=foo,bar=bar", 31 expectedOutput: opentracing.Tags{"foo": "foo", "bar": "bar"}, 32 }, 33 { 34 description: `A case with empty environment variable, key "foo" and value ""`, 35 input: "foo=${TEST:}", 36 expectedOutput: opentracing.Tags{"foo": ""}, 37 }, 38 { 39 description: `A case with empty environment variable, key "foo" and value ""`, 40 input: "foo=${TEST:}", 41 expectedOutput: opentracing.Tags{"foo": ""}, 42 }, 43 { 44 description: `A case with default environment variable, key "foo" and value "default"`, 45 input: "foo=${TEST:default}", 46 expectedOutput: opentracing.Tags{"foo": "default"}, 47 }, 48 { 49 description: `A case with real environment variable, key "foo" and value "env-bar"`, 50 input: "foo=${_TEST_PARSE_TAGS:default}", 51 expectedOutput: opentracing.Tags{"foo": "env-bar"}, 52 }, 53 } 54 55 os.Setenv("_TEST_PARSE_TAGS", "env-bar") 56 for _, test := range testingData { 57 t.Logf("testing %s\n", test.description) 58 testutil.Equals(t, test.expectedOutput, parseTags(test.input)) 59 } 60 }