MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / TestInvalidHandlers

Function TestInvalidHandlers

lambda/handler_test.go:23–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestInvalidHandlers(t *testing.T) {
24 type valuer interface {
25 Value(key interface{}) interface{}
26 }
27
28 type customContext interface {
29 context.Context
30 MyCustomMethod()
31 }
32
33 type myContext interface {
34 Deadline() (deadline time.Time, ok bool)
35 Done() <-chan struct{}
36 Err() error
37 Value(key interface{}) interface{}
38 }
39
40 testCases := []struct {
41 name string
42 handler interface{}
43 expected error
44 }{
45 {
46 name: "nil handler",
47 expected: errors.New("handler is nil"),
48 handler: nil,
49 },
50 {
51 name: "handler is not a function",
52 expected: errors.New("handler kind struct is not func"),
53 handler: struct{}{},
54 },
55 {
56 name: "handler declares too many arguments",
57 expected: errors.New("handlers may not take more than two arguments, but handler takes 3"),
58 handler: func(n context.Context, x string, y string) error {
59 return nil
60 },
61 },
62 {
63 name: "two argument handler does not context as first argument",
64 expected: errors.New("handler takes two arguments, but the first is not Context. got string"),
65 handler: func(a string, x context.Context) error {
66 return nil
67 },
68 },
69 {
70 name: "handler returns too many values",
71 expected: errors.New("handler may not return more than two values"),
72 handler: func() (error, error, error) {
73 return nil, nil, nil
74 },
75 },
76 {
77 name: "handler returning two values does not declare error as the second return value",
78 expected: errors.New("handler returns two values, but the second does not implement error"),
79 //nolint: staticcheck
80 handler: func() (error, string) {

Callers

nothing calls this directly

Calls 2

InvokeMethod · 0.95
NewHandlerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…