Skip to content

Commit d62015a

Browse files
committed
test(backend): embed prom_resp fixture so coverage runs in CI
1 parent f369e26 commit d62015a

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

pkg/plugin/promql_decode_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package plugin
22

33
import (
4+
_ "embed"
45
"encoding/json"
56
"os"
67
"testing"
78
)
89

10+
//go:embed testdata/prom_resp.json
11+
var embeddedPromResp []byte
12+
913
// Regression: make sure our matrix / sample decoding works against the real
1014
// Parseable /query_range response shape, including RFC3339 timestamps returned
1115
// even when timestamp_format=unix is requested.
1216
func TestPromMatrixDecode_Parseable(t *testing.T) {
13-
path := os.Getenv("PROM_RESP_JSON")
14-
if path == "" {
15-
path = "/tmp/prom_resp.json"
16-
}
17-
data, err := os.ReadFile(path)
18-
if err != nil {
19-
t.Skipf("skipping: %v (set PROM_RESP_JSON to point at a captured response)", err)
17+
data := embeddedPromResp
18+
if path := os.Getenv("PROM_RESP_JSON"); path != "" {
19+
b, err := os.ReadFile(path)
20+
if err != nil {
21+
t.Fatalf("read PROM_RESP_JSON %q: %v", path, err)
22+
}
23+
data = b
2024
}
2125
var pr promResponse
2226
if err := json.Unmarshal(data, &pr); err != nil {

pkg/plugin/testdata/prom_resp.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"status": "success",
3+
"data": {
4+
"resultType": "matrix",
5+
"result": [
6+
{
7+
"metric": {"__name__": "up", "instance": "host-a", "job": "node"},
8+
"values": [
9+
["2026-05-16T10:00:00Z", "1"],
10+
["2026-05-16T10:00:15Z", "1"],
11+
["2026-05-16T10:00:30Z", "0"]
12+
]
13+
},
14+
{
15+
"metric": {"__name__": "up", "instance": "host-b", "job": "node"},
16+
"values": [
17+
["2026-05-16T10:00:00Z", "1"],
18+
["2026-05-16T10:00:30Z", "1"]
19+
]
20+
}
21+
]
22+
}
23+
}

0 commit comments

Comments
 (0)