Skip to content

Commit

Permalink
Add test for metrics file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippMatthes committed Apr 29, 2024
1 parent d5225a8 commit c9275a6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions monitor/metrics_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package monitor

import (
"fmt"
"os"
"predictor/env"
"predictor/observations"
"predictor/predictions"
"predictor/things"
Expand Down Expand Up @@ -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")
}
}

0 comments on commit c9275a6

Please sign in to comment.