2022-01-06 08:28:42 -08:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2024-02-29 07:05:28 +01:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2022-01-06 08:28:42 -08:00
|
|
|
|
|
|
|
|
package zipkin
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestEnvOrWithCollectorEndpointOptionsFromEnv(t *testing.T) {
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
name string
|
|
|
|
|
envEndpoint string
|
|
|
|
|
defaultCollectorEndpoint string
|
|
|
|
|
expectedCollectorEndpoint string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "overrides value via environment variables",
|
|
|
|
|
envEndpoint: "http://localhost:19411/foo",
|
|
|
|
|
defaultCollectorEndpoint: defaultCollectorURL,
|
|
|
|
|
expectedCollectorEndpoint: "http://localhost:19411/foo",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "environment variables is empty, will not overwrite value",
|
|
|
|
|
envEndpoint: "",
|
|
|
|
|
defaultCollectorEndpoint: defaultCollectorURL,
|
|
|
|
|
expectedCollectorEndpoint: defaultCollectorURL,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
2024-08-21 09:37:56 +02:00
|
|
|
t.Setenv(envEndpoint, tc.envEndpoint)
|
2022-01-06 08:28:42 -08:00
|
|
|
|
|
|
|
|
endpoint := envOr(envEndpoint, tc.defaultCollectorEndpoint)
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, tc.expectedCollectorEndpoint, endpoint)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|