MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / TestHandler_GoRunHttpServer

Function TestHandler_GoRunHttpServer

pkg/gotest/handler_test.go:45–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestHandler_GoRunHttpServer(t *testing.T) {
46 h := newHandler()
47 defer h.Close()
48
49 handlerFunc := func(c *gin.Context) {
50 c.String(http.StatusOK, "hello world!")
51 }
52
53 h.GoRunHTTPServer([]RouterInfo{
54 {
55 FuncName: "create",
56 Method: http.MethodPost,
57 Path: "/user",
58 HandlerFunc: handlerFunc,
59 },
60 {
61 FuncName: "deleteByID",
62 Method: http.MethodDelete,
63 Path: "/user/:id",
64 HandlerFunc: handlerFunc,
65 },
66 {
67 FuncName: "updateByID",
68 Method: http.MethodPut,
69 Path: "/user/:id",
70 HandlerFunc: handlerFunc,
71 },
72 {
73 FuncName: "updateByID2",
74 Method: http.MethodPatch,
75 Path: "/user2/:id",
76 HandlerFunc: handlerFunc,
77 },
78 {
79 FuncName: "getById",
80 Method: http.MethodGet,
81 Path: "/user/:id",
82 HandlerFunc: handlerFunc,
83 },
84 {
85 FuncName: "options",
86 Method: http.MethodOptions,
87 Path: "/user",
88 HandlerFunc: handlerFunc,
89 },
90 })
91
92 time.Sleep(time.Millisecond * 200)
93 url := h.GetRequestURL("updateByID", 1)
94 t.Log(url)
95
96 time.Sleep(time.Millisecond * 100)
97 ctx, _ := context.WithTimeout(context.Background(), time.Second)
98 _ = h.HTTPServer.Shutdown(ctx)
99}

Callers

nothing calls this directly

Calls 6

newHandlerFunction · 0.85
GoRunHTTPServerMethod · 0.80
GetRequestURLMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.65
ShutdownMethod · 0.45

Tested by

no test coverage detected