feat: add bounded observability and verified SLO incident alerts

This commit is contained in:
Vladislav Agapov
2026-10-29 18:01:11 +03:00
parent 470d9d6f1e
commit 6c7601802d
325 changed files with 24988 additions and 44 deletions
@@ -0,0 +1,43 @@
package fiber
import (
"errors"
"fmt"
"testing"
"go.lab260.ru/fielderr"
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/service"
)
// TestPublicErrorSafety maps wrapped application failures without exposing internal details.
func TestPublicErrorSafety(t *testing.T) {
t.Run("wrapped application error", func(t *testing.T) {
err := publicError(fmt.Errorf("private database detail: %w", service.ErrConflict))
response := errorResponse(err, "request")
if response.Error.Code != codeConflict || response.Error.Message != "username already exists" {
t.Fatalf("unexpected response: %+v", response)
}
})
t.Run("unknown error", func(t *testing.T) {
err := publicError(errors.New("private database detail"))
if err != errInternal {
t.Fatalf("unexpected public error: %v", err)
}
})
t.Run("foreign public status", func(t *testing.T) {
err := fielderr.WithStatus(errors.New("private detail"), fielderr.NewStatusCode(codeInvalid), "private detail")
if publicError(err) != errInternal {
t.Fatal("untrusted error metadata reached the public response")
}
})
}
// TestPublicErrorUnavailable keeps dependency details out of the public envelope.
func TestPublicErrorUnavailable(t *testing.T) {
err := publicError(fmt.Errorf("private database detail: %w", service.ErrUnavailable))
response := errorResponse(err, "request")
if response.Error.Code != codeUnavailable || response.Error.Message != "dependency unavailable" {
t.Fatalf("unexpected response: %+v", response)
}
}