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

Function TestStartConfig_WithHidePort

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

Source from the content-addressed store, hash-verified

541}
542
543func TestStartConfig_WithHidePort(t *testing.T) {
544 var testCases = []struct {
545 name string
546 hidePort bool
547 }{
548 {
549 name: "hide port on startup",
550 hidePort: true,
551 },
552 {
553 name: "show port on startup",
554 hidePort: false,
555 },
556 }
557 for _, tc := range testCases {
558 t.Run(tc.name, func(t *testing.T) {
559 e := New()
560
561 buf := new(bytes.Buffer)
562 e.Logger = slog.New(slog.NewTextHandler(buf, nil))
563
564 e.GET("/ok", func(c *Context) error {
565 return c.String(http.StatusOK, "OK")
566 })
567
568 addrChan := make(chan string)
569 errCh := make(chan error, 1)
570
571 ctx, shutdown := stdContext.WithTimeout(stdContext.Background(), 200*time.Millisecond)
572
573 go func() {
574 _, err := waitForServerStart(addrChan, errCh)
575 errCh <- err
576 shutdown()
577 }()
578
579 s := &StartConfig{
580 Address: ":0",
581 HidePort: tc.hidePort,
582 GracefulTimeout: 100 * time.Millisecond,
583 ListenerAddrFunc: func(addr net.Addr) {
584 addrChan <- addr.String()
585 },
586 }
587 if err := s.Start(ctx, e); err != http.ErrServerClosed {
588 assert.NoError(t, err)
589 }
590 assert.NoError(t, <-errCh)
591
592 contains := strings.Contains(buf.String(), "http(s) server started")
593 if tc.hidePort {
594 assert.False(t, contains)
595 } else {
596 assert.True(t, contains)
597 }
598 })
599 }
600}

Callers

nothing calls this directly

Calls 5

StartMethod · 0.95
NewFunction · 0.85
waitForServerStartFunction · 0.85
GETMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…