-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
46 lines (39 loc) · 986 Bytes
/
main_test.go
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
37
38
39
40
41
42
43
44
45
46
package httpwrap
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestInternals(t *testing.T) {
t.Run("simple", func(t *testing.T) {
req := httptest.NewRequest("GET", "/test", nil)
rw := httptest.NewRecorder()
ctx := newRunCtx(rw, req, nopConstructor)
main, err := newMain(func(in error) error {
require.Nil(t, in)
return in
})
require.NoError(t, err)
res := main.run(ctx)
require.Nil(t, res)
})
t.Run("empty interface input", func(t *testing.T) {
_, err := newMain(func(in any) error {
return nil
})
require.Error(t, err)
})
t.Run("with result", func(t *testing.T) {
req := httptest.NewRequest("GET", "/test", nil)
rw := httptest.NewRecorder()
ctx := newRunCtx(rw, req, nopConstructor)
type resp struct{ i int }
main, err := newMain(func(in error) (resp, error) {
require.Nil(t, in)
return resp{1}, nil
})
require.NoError(t, err)
res := main.run(ctx)
require.NotNil(t, res)
})
}