Skip to content

Commit

Permalink
Add descriptions to test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
damemi committed Sep 12, 2022
1 parent b05f8f5 commit 38f428c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions exporters/prometheus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/sdk/metric"

"go.opentelemetry.io/otel/attribute"
Expand All @@ -46,7 +47,7 @@ func TestPrometheusExporter(t *testing.T) {
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
}
counter, err := meter.SyncFloat64().Counter("foo")
counter, err := meter.SyncFloat64().Counter("foo", instrument.WithDescription("a simple counter"))
require.NoError(t, err)
counter.Add(ctx, 5, labels...)
counter.Add(ctx, 10.3, labels...)
Expand All @@ -61,7 +62,7 @@ func TestPrometheusExporter(t *testing.T) {
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
}
gauge, err := meter.SyncFloat64().UpDownCounter("bar")
gauge, err := meter.SyncFloat64().UpDownCounter("bar", instrument.WithDescription("a fun little gauge"))
require.NoError(t, err)
gauge.Add(ctx, 100, labels...)
gauge.Add(ctx, -25, labels...)
Expand All @@ -75,7 +76,7 @@ func TestPrometheusExporter(t *testing.T) {
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
}
histogram, err := meter.SyncFloat64().Histogram("baz")
histogram, err := meter.SyncFloat64().Histogram("baz", instrument.WithDescription("a very nice histogram"))
require.NoError(t, err)
histogram.Record(ctx, 23, labels...)
histogram.Record(ctx, 7, labels...)
Expand Down Expand Up @@ -106,6 +107,9 @@ func TestPrometheusExporter(t *testing.T) {

err = testutil.GatherAndCompare(registry, file)
require.NoError(t, err)

err = file.Close()
require.NoError(t, err)
})
}
}
2 changes: 1 addition & 1 deletion exporters/prometheus/testdata/counter.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# HELP foo
# HELP foo a simple counter
# TYPE foo counter
foo{A="B",C="D"} 24.3
2 changes: 1 addition & 1 deletion exporters/prometheus/testdata/gauge.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# HELP bar
# HELP bar a fun little gauge
# TYPE bar counter
bar{A="B",C="D"} 75
2 changes: 1 addition & 1 deletion exporters/prometheus/testdata/histogram.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# HELP baz
# HELP baz a very nice histogram
# TYPE baz histogram
baz_bucket{A="B",C="D",le="0"} 0
baz_bucket{A="B",C="D",le="5"} 0
Expand Down

0 comments on commit 38f428c

Please sign in to comment.