MCPcopy
hub / github.com/labstack/echo / TestStartConfig_Start

Function TestStartConfig_Start

server_test.go:80–130  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestStartConfig_Start(t *testing.T) {
81 e := New()
82 e.GET("/ok", func(c *Context) error {
83 return c.String(http.StatusOK, "OK")
84 })
85
86 addrChan := make(chan string)
87 errCh := make(chan error)
88
89 ctx, shutdown := stdContext.WithTimeout(stdContext.Background(), 200*time.Millisecond)
90 defer shutdown()
91 go func() {
92 errCh <- (&StartConfig{
93 Address: ":0",
94 ListenerAddrFunc: func(addr net.Addr) {
95 addrChan <- addr.String()
96 },
97 }).Start(ctx, e)
98 }()
99
100 addr, err := waitForServerStart(addrChan, errCh)
101 assert.NoError(t, err)
102
103 // check if server is actually up
104 code, body, err := doGet(fmt.Sprintf("http://%v/ok", addr))
105 if err != nil {
106 assert.NoError(t, err)
107 return
108 }
109 assert.Equal(t, http.StatusOK, code)
110 assert.Equal(t, "OK", body)
111
112 shutdown()
113
114 <-errCh // we will be blocking here until server returns from http.Serve
115
116 // check if server was stopped
117 code, body, err = doGet(fmt.Sprintf("http://%v/ok", addr))
118 assert.Equal(t, 0, code)
119 assert.Equal(t, "", body)
120
121 if err == nil {
122 t.Errorf("missing error")
123 return
124 }
125 expectContains := "connect: connection refused"
126 if runtime.GOOS == "windows" {
127 expectContains = "No connection could be made"
128 }
129 assert.True(t, strings.Contains(err.Error(), expectContains))
130}
131
132func TestStartConfig_GracefulShutdown(t *testing.T) {
133 var testCases = []struct {

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
waitForServerStartFunction · 0.85
doGetFunction · 0.85
GETMethod · 0.45
StringMethod · 0.45
StartMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…