veza/veza-backend-api/internal/metrics/prometheus_test.go
2026-03-05 23:03:43 +01:00

44 lines
1.1 KiB
Go

package metrics
import (
"testing"
"veza-backend-api/internal/errors"
"github.com/stretchr/testify/assert"
)
func TestRecordErrorPrometheus(t *testing.T) {
// Enregistrer quelques erreurs
RecordErrorPrometheus(errors.ErrCodeNotFound, 404)
RecordErrorPrometheus(errors.ErrCodeValidation, 400)
RecordErrorPrometheus(errors.ErrCodeNotFound, 404)
// Les métriques Prometheus sont enregistrées automatiquement
// On vérifie juste qu'il n'y a pas de panic
// (les métriques sont vérifiées via l'endpoint /metrics dans les tests d'intégration)
}
func TestRecordErrorPrometheus_MultipleCodes(t *testing.T) {
testCases := []struct {
code errors.ErrorCode
httpStatus int
}{
{errors.ErrCodeValidation, 400},
{errors.ErrCodeUnauthorized, 401},
{errors.ErrCodeForbidden, 403},
{errors.ErrCodeNotFound, 404},
{errors.ErrCodeConflict, 409},
{errors.ErrCodeRateLimitExceeded, 429},
{errors.ErrCodeInternal, 500},
}
for _, tc := range testCases {
t.Run(string(rune(tc.code)), func(t *testing.T) {
// Vérifier qu'il n'y a pas de panic
assert.NotPanics(t, func() {
RecordErrorPrometheus(tc.code, tc.httpStatus)
})
})
}
}