diff --git a/monitor/metrics_test.go b/monitor/metrics_test.go index 8862d75..7377ae8 100644 --- a/monitor/metrics_test.go +++ b/monitor/metrics_test.go @@ -1,6 +1,9 @@ package monitor import ( + "fmt" + "os" + "predictor/env" "predictor/observations" "predictor/predictions" "predictor/things" @@ -174,3 +177,27 @@ func TestGeneratePrometheusMetrics(t *testing.T) { t.FailNow() } } + +func TestMetricsFile(t *testing.T) { + prepareMocks() + + tempDir := t.TempDir() + env.StaticPath = tempDir + + UpdateMetricsFiles() + + filePath := fmt.Sprintf("%s/metrics.json", tempDir) + fileContent, err := os.ReadFile(filePath) + if err != nil { + t.Errorf("metrics file could not be opened") + t.FailNow() + } + fileAsStr := string(fileContent) + metrics := strings.Split(fileAsStr, "\n") + + // Just a simple check if there are metrics, the logic + // is checked in the other tests + if len(metrics) == 0 { + t.Errorf("no metrics found") + } +}