mirror of
https://github.com/photoprism/photoprism.git
synced 2025-09-26 21:01:58 +08:00
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetMetrics(t *testing.T) {
|
|
t.Run("expose count statistics", func(t *testing.T) {
|
|
app, router, _ := NewApiTest()
|
|
|
|
GetMetrics(router)
|
|
|
|
resp := PerformRequestWithStream(app, "GET", "/api/v1/metrics")
|
|
|
|
if resp.Code != http.StatusOK {
|
|
t.Fatal(resp.Body.String())
|
|
}
|
|
|
|
body := resp.Body.String()
|
|
|
|
assert.Regexp(t, regexp.MustCompile(`photoprism_statistics_media_count{stat="all"} \d+`), body)
|
|
assert.Regexp(t, regexp.MustCompile(`photoprism_statistics_media_count{stat="photos"} \d+`), body)
|
|
assert.Regexp(t, regexp.MustCompile(`photoprism_statistics_media_count{stat="videos"} \d+`), body)
|
|
assert.Regexp(t, regexp.MustCompile(`photoprism_statistics_media_count{stat="albums"} \d+`), body)
|
|
assert.Regexp(t, regexp.MustCompile(`photoprism_statistics_media_count{stat="folders"} \d+`), body)
|
|
assert.Regexp(t, regexp.MustCompile(`photoprism_statistics_media_count{stat="files"} \d+`), body)
|
|
})
|
|
t.Run("expose build information", func(t *testing.T) {
|
|
app, router, _ := NewApiTest()
|
|
|
|
GetMetrics(router)
|
|
|
|
resp := PerformRequestWithStream(app, "GET", "/api/v1/metrics")
|
|
|
|
if resp.Code != http.StatusOK {
|
|
t.Fatal(resp.Body.String())
|
|
}
|
|
|
|
body := resp.Body.String()
|
|
|
|
assert.Regexp(t, regexp.MustCompile(`photoprism_build_info{edition=".+",goversion=".+",version=".+"} 1`), body)
|
|
})
|
|
t.Run("has prometheus exposition format as content type", func(t *testing.T) {
|
|
app, router, _ := NewApiTest()
|
|
|
|
GetMetrics(router)
|
|
|
|
resp := PerformRequestWithStream(app, "GET", "/api/v1/metrics")
|
|
if resp.Code != http.StatusOK {
|
|
t.Fatal(resp.Body.String())
|
|
}
|
|
if contentType := resp.Result().Header.Get("Content-Type"); contentType != "" {
|
|
t.Fatalf("unexpected response content-type: %s", contentType)
|
|
}
|
|
})
|
|
}
|