-
Notifications
You must be signed in to change notification settings - Fork 0
/
metric_exporter_test.go
37 lines (33 loc) · 1.01 KB
/
metric_exporter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package metrics_exporter
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"testing"
"github.com/prometheus/common/expfmt"
)
func fetchFromFile(filePath string) []byte {
jsonBytes, err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Printf("Failed to read JSON file: %v\n", err)
return []byte{}
}
return jsonBytes
}
func TestMetricsExporter(t *testing.T) {
queryResponse := fetchFromFile("query.json")
metadataResponse := fetchFromFile("metadata.json")
var prometheusQueryAPIResponse PrometheusQueryAPIResponse
json.Unmarshal(queryResponse, &prometheusQueryAPIResponse)
var prometheusMetadataAPIResponse PrometheusMetadataAPIResponse
json.Unmarshal(metadataResponse, &prometheusMetadataAPIResponse)
exportedMetrics := exportMetrics(prometheusQueryAPIResponse, prometheusMetadataAPIResponse)
fmt.Println(exportedMetrics)
reader := strings.NewReader(exportedMetrics)
parser := expfmt.TextParser{}
_, err := parser.TextToMetricFamilies(reader)
if err != nil {
t.Errorf("Error happened" + err.Error())
}
}