Skip to content

Commit

Permalink
Test Exemplars and CardinalityLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Nov 30, 2023
1 parent 4e99d1b commit 9d6b55b
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions sdk/metric/internal/x/x_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package x

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestExemplars(t *testing.T) {
const key = "OTEL_GO_X_EXEMPLAR"
require.Equal(t, key, Exemplars.Key())

t.Run("true", func(t *testing.T) {
t.Setenv(key, "true")
assert.True(t, Exemplars.Enabled())

v, ok := Exemplars.Lookup()
assert.True(t, ok)
assert.Equal(t, "true", v)
})

t.Run("false", func(t *testing.T) {
t.Setenv(key, "false")
assert.False(t, Exemplars.Enabled())

v, ok := Exemplars.Lookup()
assert.False(t, ok)
assert.Equal(t, "", v)
})

t.Run("empty", func(t *testing.T) {
assert.False(t, Exemplars.Enabled())

v, ok := Exemplars.Lookup()
assert.False(t, ok)
assert.Equal(t, "", v)
})
}

func TestCardinalityLimit(t *testing.T) {
const key = "OTEL_GO_X_CARDINALITY_LIMIT"
require.Equal(t, key, CardinalityLimit.Key())

t.Run("100", func(t *testing.T) {
t.Setenv(key, "100")
assert.True(t, CardinalityLimit.Enabled())

v, ok := CardinalityLimit.Lookup()
assert.True(t, ok)
assert.Equal(t, 100, v)
})

t.Run("-1", func(t *testing.T) {
t.Setenv(key, "-1")
assert.True(t, CardinalityLimit.Enabled())

v, ok := CardinalityLimit.Lookup()
assert.True(t, ok)
assert.Equal(t, -1, v)
})

t.Run("false", func(t *testing.T) {
t.Setenv(key, "false")
assert.False(t, CardinalityLimit.Enabled())

v, ok := CardinalityLimit.Lookup()
assert.False(t, ok)
assert.Equal(t, 0, v)
})

t.Run("empty", func(t *testing.T) {
t.Setenv(key, "false")
assert.False(t, CardinalityLimit.Enabled())

v, ok := CardinalityLimit.Lookup()
assert.False(t, ok)
assert.Equal(t, 0, v)
})
}

0 comments on commit 9d6b55b

Please sign in to comment.