mirror of
https://github.com/zitadel/zitadel.git
synced 2025-07-12 04:28:32 +00:00
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
![]() |
package connect_middleware
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"net/http"
|
||
|
"testing"
|
||
|
|
||
|
"connectrpc.com/connect"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
|
||
|
"github.com/zitadel/zitadel/internal/api/authz"
|
||
|
"github.com/zitadel/zitadel/internal/zerrors"
|
||
|
)
|
||
|
|
||
|
func emptyMockHandler(resp connect.AnyResponse, expectedCtxData authz.CtxData) func(*testing.T) connect.UnaryFunc {
|
||
|
return func(t *testing.T) connect.UnaryFunc {
|
||
|
return func(ctx context.Context, _ connect.AnyRequest) (connect.AnyResponse, error) {
|
||
|
assert.Equal(t, expectedCtxData, authz.GetCtxData(ctx))
|
||
|
return resp, nil
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func errorMockHandler() func(*testing.T) connect.UnaryFunc {
|
||
|
return func(t *testing.T) connect.UnaryFunc {
|
||
|
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
|
||
|
return nil, zerrors.ThrowInternal(nil, "test", "error")
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
type mockReq[t any] struct {
|
||
|
connect.Request[t]
|
||
|
|
||
|
procedure string
|
||
|
header http.Header
|
||
|
}
|
||
|
|
||
|
func (m *mockReq[T]) Spec() connect.Spec {
|
||
|
return connect.Spec{
|
||
|
Procedure: m.procedure,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *mockReq[T]) Header() http.Header {
|
||
|
if m.header == nil {
|
||
|
m.header = make(http.Header)
|
||
|
}
|
||
|
return m.header
|
||
|
}
|