github.com/letsencrypt/boulder@v0.20251208.0/web/server_test.go (about)

     1  package web
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"net/http"
     7  	"sync"
     8  	"testing"
     9  
    10  	blog "github.com/letsencrypt/boulder/log"
    11  	"github.com/letsencrypt/boulder/test"
    12  )
    13  
    14  func TestNewServer(t *testing.T) {
    15  	srv := NewServer(":0", nil, blog.NewMock())
    16  
    17  	var wg sync.WaitGroup
    18  	wg.Go(func() {
    19  		err := srv.ListenAndServe()
    20  		test.Assert(t, errors.Is(err, http.ErrServerClosed), "Could not start server")
    21  	})
    22  
    23  	err := srv.Shutdown(context.TODO())
    24  	test.AssertNotError(t, err, "Could not shut down server")
    25  	wg.Wait()
    26  }
    27  
    28  func TestUnorderedShutdownIsFine(t *testing.T) {
    29  	srv := NewServer(":0", nil, blog.NewMock())
    30  	err := srv.Shutdown(context.TODO())
    31  	test.AssertNotError(t, err, "Could not shut down server")
    32  	err = srv.ListenAndServe()
    33  	test.Assert(t, errors.Is(err, http.ErrServerClosed), "Could not start server")
    34  }