| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package x |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
"github.com/stretchr/testify/require" |
| 11 |
) |
| 12 |
|
| 13 |
func TestDeprecatedRuntimeMetrics(t *testing.T) { |
| 14 |
const key = "OTEL_GO_X_DEPRECATED_RUNTIME_METRICS" |
| 15 |
require.Equal(t, key, DeprecatedRuntimeMetrics.Key()) |
| 16 |
|
| 17 |
t.Run("true", run(setenv(key, "true"), assertEnabled(DeprecatedRuntimeMetrics, true))) |
| 18 |
t.Run("True", run(setenv(key, "True"), assertEnabled(DeprecatedRuntimeMetrics, true))) |
| 19 |
t.Run("TRUE", run(setenv(key, "TRUE"), assertEnabled(DeprecatedRuntimeMetrics, true))) |
| 20 |
t.Run("false", run(setenv(key, "false"), assertEnabled(DeprecatedRuntimeMetrics, false))) |
| 21 |
t.Run("False", run(setenv(key, "False"), assertEnabled(DeprecatedRuntimeMetrics, false))) |
| 22 |
t.Run("FALSE", run(setenv(key, "FALSE"), assertEnabled(DeprecatedRuntimeMetrics, false))) |
| 23 |
t.Run("1", run(setenv(key, "1"), assertEnabled(DeprecatedRuntimeMetrics, true))) |
| 24 |
t.Run("empty", run(assertEnabled(DeprecatedRuntimeMetrics, false))) |
| 25 |
} |
| 26 |
|
| 27 |
func run(steps ...func(*testing.T)) func(*testing.T) { |
| 28 |
return func(t *testing.T) { |
| 29 |
t.Helper() |
| 30 |
for _, step := range steps { |
| 31 |
step(t) |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
func setenv(k, v string) func(t *testing.T) { //nolint:unparam // ignore linter |
| 37 |
return func(t *testing.T) { t.Setenv(k, v) } |
| 38 |
} |
| 39 |
|
| 40 |
func assertEnabled(f BoolFeature, enabled bool) func(*testing.T) { |
| 41 |
return func(t *testing.T) { |
| 42 |
t.Helper() |
| 43 |
assert.Equal(t, enabled, f.Enabled(), "not enabled") |
| 44 |
} |
| 45 |
} |