(t testing.TB)
| 53 | } |
| 54 | |
| 55 | func testHandler(t testing.TB) { |
| 56 | // TODO(beorn7): This test is a bit too "end-to-end". It tests quite a |
| 57 | // few moving parts that are not strongly coupled. They could/should be |
| 58 | // tested separately. However, the changes planned for v2 will |
| 59 | // require a major rework of this test anyway, at which time I will |
| 60 | // structure it in a better way. |
| 61 | |
| 62 | metricVec := prometheus.NewCounterVec( |
| 63 | prometheus.CounterOpts{ |
| 64 | Name: "name", |
| 65 | Help: "docstring", |
| 66 | ConstLabels: prometheus.Labels{"constname": "constvalue"}, |
| 67 | }, |
| 68 | []string{"labelname"}, |
| 69 | ) |
| 70 | |
| 71 | metricVec.WithLabelValues("val1").Inc() |
| 72 | metricVec.WithLabelValues("val2").Inc() |
| 73 | |
| 74 | externalMetricFamily := &dto.MetricFamily{ |
| 75 | Name: proto.String("externalname"), |
| 76 | Help: proto.String("externaldocstring"), |
| 77 | Type: dto.MetricType_COUNTER.Enum(), |
| 78 | Metric: []*dto.Metric{ |
| 79 | { |
| 80 | Label: []*dto.LabelPair{ |
| 81 | { |
| 82 | Name: proto.String("externalconstname"), |
| 83 | Value: proto.String("externalconstvalue"), |
| 84 | }, |
| 85 | { |
| 86 | Name: proto.String("externallabelname"), |
| 87 | Value: proto.String("externalval1"), |
| 88 | }, |
| 89 | }, |
| 90 | Counter: &dto.Counter{ |
| 91 | Value: proto.Float64(1), |
| 92 | }, |
| 93 | }, |
| 94 | }, |
| 95 | } |
| 96 | externalBuf := &bytes.Buffer{} |
| 97 | enc := expfmt.NewEncoder(externalBuf, expfmt.NewFormat(expfmt.TypeProtoDelim)) |
| 98 | if err := enc.Encode(externalMetricFamily); err != nil { |
| 99 | t.Fatal(err) |
| 100 | } |
| 101 | externalMetricFamilyAsBytes := externalBuf.Bytes() |
| 102 | externalMetricFamilyAsText := []byte(`# HELP externalname externaldocstring |
| 103 | # TYPE externalname counter |
| 104 | externalname{externalconstname="externalconstvalue",externallabelname="externalval1"} 1 |
| 105 | `) |
| 106 | externalMetricFamilyAsProtoText := []byte(`name: "externalname" |
| 107 | help: "externaldocstring" |
| 108 | type: COUNTER |
| 109 | metric: < |
| 110 | label: < |
| 111 | name: "externalconstname" |
| 112 | value: "externalconstvalue" |
no test coverage detected