-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_definition_test.go
More file actions
36 lines (27 loc) · 1.03 KB
/
Copy pathrequest_definition_test.go
File metadata and controls
36 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package httpserver
import (
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
// Tests for registration-time panics: non-struct request types and anonymous
// non-struct fields are rejected by createTags/checkRecursively.
// AnonInt is an exported non-struct type used to test that anonymous non-struct
// fields are rejected at registration.
type AnonInt int
// ============ createTags: non-struct request type ============
func TestPanic_NonStructRequestType(t *testing.T) {
require.Panics(t, func() {
_ = RequestParser(func(ctx *Context, _ int) { ctx.NewResponse(http.StatusOK) })
})
}
// ============ checkRecursively: anonymous non-struct field ============
func TestPanic_AnonymousNonStructField(t *testing.T) {
type Req struct{ AnonInt }
require.Panics(t, func() { _ = RequestParser(captureHandler[Req]) })
}