photoprism/internal/api/metrics_test.go
Michael Mayer 467f7b1585 OAuth2: Add Client Credentials Authentication #213 #782 #808 #3730 #3943
This adds standard OAuth2 client credentials and bearer token support as
well as scope-based authorization checks for REST API clients. Note that
this initial implementation should not be used in production and that
the access token limit has not been implemented yet.

Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-12-12 18:42:50 +01:00

47 lines
1.4 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)
})
}