summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/prometheus/common/expfmt/decode_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-02-02 09:32:00 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2017-02-02 09:32:00 -0500
commit701d1ab638b23c24877fc41824add66232446676 (patch)
treeec120c88d38ac9d38d9eabdd3270b52bb6ac9d96 /vendor/github.com/prometheus/common/expfmt/decode_test.go
parentca3211bc04f6dea34e8168217182637d1419f998 (diff)
downloadchat-701d1ab638b23c24877fc41824add66232446676.tar.gz
chat-701d1ab638b23c24877fc41824add66232446676.tar.bz2
chat-701d1ab638b23c24877fc41824add66232446676.zip
Updating server dependancies (#5249)
Diffstat (limited to 'vendor/github.com/prometheus/common/expfmt/decode_test.go')
-rw-r--r--vendor/github.com/prometheus/common/expfmt/decode_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/github.com/prometheus/common/expfmt/decode_test.go b/vendor/github.com/prometheus/common/expfmt/decode_test.go
index c27325a9d..82c1130c9 100644
--- a/vendor/github.com/prometheus/common/expfmt/decode_test.go
+++ b/vendor/github.com/prometheus/common/expfmt/decode_test.go
@@ -21,6 +21,9 @@ import (
"strings"
"testing"
+ "github.com/golang/protobuf/proto"
+ dto "github.com/prometheus/client_model/go"
+
"github.com/prometheus/common/model"
)
@@ -365,3 +368,68 @@ func BenchmarkDiscriminatorHTTPHeader(b *testing.B) {
testDiscriminatorHTTPHeader(b)
}
}
+
+func TestExtractSamples(t *testing.T) {
+ var (
+ goodMetricFamily1 = &dto.MetricFamily{
+ Name: proto.String("foo"),
+ Help: proto.String("Help for foo."),
+ Type: dto.MetricType_COUNTER.Enum(),
+ Metric: []*dto.Metric{
+ &dto.Metric{
+ Counter: &dto.Counter{
+ Value: proto.Float64(4711),
+ },
+ },
+ },
+ }
+ goodMetricFamily2 = &dto.MetricFamily{
+ Name: proto.String("bar"),
+ Help: proto.String("Help for bar."),
+ Type: dto.MetricType_GAUGE.Enum(),
+ Metric: []*dto.Metric{
+ &dto.Metric{
+ Gauge: &dto.Gauge{
+ Value: proto.Float64(3.14),
+ },
+ },
+ },
+ }
+ badMetricFamily = &dto.MetricFamily{
+ Name: proto.String("bad"),
+ Help: proto.String("Help for bad."),
+ Type: dto.MetricType(42).Enum(),
+ Metric: []*dto.Metric{
+ &dto.Metric{
+ Gauge: &dto.Gauge{
+ Value: proto.Float64(2.7),
+ },
+ },
+ },
+ }
+
+ opts = &DecodeOptions{
+ Timestamp: 42,
+ }
+ )
+
+ got, err := ExtractSamples(opts, goodMetricFamily1, goodMetricFamily2)
+ if err != nil {
+ t.Error("Unexpected error from ExtractSamples:", err)
+ }
+ want := model.Vector{
+ &model.Sample{Metric: model.Metric{model.MetricNameLabel: "foo"}, Value: 4711, Timestamp: 42},
+ &model.Sample{Metric: model.Metric{model.MetricNameLabel: "bar"}, Value: 3.14, Timestamp: 42},
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("unexpected samples extracted, got: %v, want: %v", got, want)
+ }
+
+ got, err = ExtractSamples(opts, goodMetricFamily1, badMetricFamily, goodMetricFamily2)
+ if err == nil {
+ t.Error("Expected error from ExtractSamples")
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Errorf("unexpected samples extracted, got: %v, want: %v", got, want)
+ }
+}