Debian Codegraph @

exporters/zipkin/env_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package zipkin
5
6 import (
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 func TestEnvOrWithCollectorEndpointOptionsFromEnv(t *testing.T) {
13 testCases := []struct {
14 name string
15 envEndpoint string
16 defaultCollectorEndpoint string
17 expectedCollectorEndpoint string
18 }{
19 {
20 name: "overrides value via environment variables",
21 envEndpoint: "http://localhost:19411/foo",
22 defaultCollectorEndpoint: defaultCollectorURL,
23 expectedCollectorEndpoint: "http://localhost:19411/foo",
24 },
25 {
26 name: "environment variables is empty, will not overwrite value",
27 envEndpoint: "",
28 defaultCollectorEndpoint: defaultCollectorURL,
29 expectedCollectorEndpoint: defaultCollectorURL,
30 },
31 }
32
33 for _, tc := range testCases {
34 t.Run(tc.name, func(t *testing.T) {
35 t.Setenv(envEndpoint, tc.envEndpoint)
36
37 endpoint := envOr(envEndpoint, tc.defaultCollectorEndpoint)
38
39 assert.Equal(t, tc.expectedCollectorEndpoint, endpoint)
40 })
41 }
42 }