MCPcopy
hub / github.com/gofiber/fiber / Test_CopyContextToFiberContext

Function Test_CopyContextToFiberContext

middleware/adaptor/adaptor_test.go:873–976  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

871}
872
873func Test_CopyContextToFiberContext(t *testing.T) {
874 t.Parallel()
875
876 t.Run("unsupported context type", func(t *testing.T) {
877 t.Parallel()
878 // Test with non-struct context (should return early)
879 var fctx fasthttp.RequestCtx
880 stringContext := "not a struct"
881
882 // This should not panic and should handle the non-struct gracefully
883 CopyContextToFiberContext(&stringContext, &fctx)
884 // No assertions needed - just ensuring it doesn't panic
885 })
886
887 t.Run("context with unknown field", func(t *testing.T) {
888 t.Parallel()
889 // Test the default case (continue statement coverage)
890 type customContext struct {
891 UnknownField string
892 }
893
894 var fctx fasthttp.RequestCtx
895 ctx := customContext{UnknownField: "test"}
896
897 // This should hit the default case and continue
898 CopyContextToFiberContext(&ctx, &fctx)
899 // No assertions needed - just ensuring it doesn't panic and continues
900 })
901
902 t.Run("invalid src", func(t *testing.T) {
903 t.Parallel()
904 var fctx fasthttp.RequestCtx
905 CopyContextToFiberContext(nil, &fctx)
906 // Add assertion to ensure no panic and coverage is detected
907 assert.NotNil(t, &fctx)
908 })
909
910 t.Run("nil request context", func(t *testing.T) {
911 t.Parallel()
912 ctx := context.WithValue(context.Background(), contextKey("nil-request-context"), "value")
913 require.NotPanics(t, func() {
914 CopyContextToFiberContext(ctx, nil)
915 })
916 })
917
918 t.Run("nil pointer", func(t *testing.T) {
919 t.Parallel()
920 var nilPtr *context.Context // Nil pointer to a context
921 var fctx fasthttp.RequestCtx
922 CopyContextToFiberContext(nilPtr, &fctx)
923 // Add assertion to ensure no panic and coverage is detected
924 assert.NotNil(t, &fctx)
925 })
926
927 t.Run("copies key value pairs", func(t *testing.T) {
928 t.Parallel()
929 var fctx fasthttp.RequestCtx
930 key := contextKey("copy-key")

Callers

nothing calls this directly

Calls 3

contextKeyTypeAlias · 0.70
UserValueMethod · 0.65

Tested by

no test coverage detected