go:generate mockgen -destination=logger_mock_test.go -package $GOPACKAGE github.com/qdm12/gluetun/internal/httpserver Logger
(t *testing.T)
| 16 | //go:generate mockgen -destination=logger_mock_test.go -package $GOPACKAGE github.com/qdm12/gluetun/internal/httpserver Logger |
| 17 | |
| 18 | func Test_Server(t *testing.T) { |
| 19 | t.Parallel() |
| 20 | ctrl := gomock.NewController(t) |
| 21 | |
| 22 | const address = "127.0.0.1:0" |
| 23 | logger := NewMockLogger(ctrl) |
| 24 | |
| 25 | logger.EXPECT().Info(newRegexMatcher("^http server listening on 127.0.0.1:[1-9][0-9]{0,4}$")) |
| 26 | |
| 27 | const httpServerShutdownTimeout = 10 * time.Second // 10s in case test worker is slow |
| 28 | settings := Settings{ |
| 29 | BlockProfileRate: intPtr(0), |
| 30 | MutexProfileRate: intPtr(0), |
| 31 | HTTPServer: httpserver.Settings{ |
| 32 | Address: address, |
| 33 | Logger: logger, |
| 34 | ShutdownTimeout: httpServerShutdownTimeout, |
| 35 | }, |
| 36 | } |
| 37 | |
| 38 | server, err := New(settings) |
| 39 | require.NoError(t, err) |
| 40 | require.NotNil(t, server) |
| 41 | |
| 42 | ctx, cancel := context.WithCancel(context.Background()) |
| 43 | ready := make(chan struct{}) |
| 44 | done := make(chan struct{}) |
| 45 | |
| 46 | go server.Run(ctx, ready, done) |
| 47 | |
| 48 | select { |
| 49 | case <-ready: |
| 50 | case err := <-done: |
| 51 | t.Fatalf("server crashed before being ready: %s", err) |
| 52 | } |
| 53 | |
| 54 | serverAddress := server.GetAddress() |
| 55 | |
| 56 | const clientTimeout = 2 * time.Second |
| 57 | httpClient := &http.Client{Timeout: clientTimeout} |
| 58 | |
| 59 | pathsToCheck := []string{ |
| 60 | "debug/pprof/", |
| 61 | "debug/pprof/cmdline", |
| 62 | "debug/pprof/profile?seconds=1", |
| 63 | "debug/pprof/symbol", |
| 64 | "debug/pprof/trace?seconds=1", |
| 65 | "debug/pprof/block", |
| 66 | "debug/pprof/goroutine", |
| 67 | "debug/pprof/heap", |
| 68 | "debug/pprof/threadcreate", |
| 69 | } |
| 70 | |
| 71 | type httpResult struct { |
| 72 | url string |
| 73 | response *http.Response |
| 74 | err error |
| 75 | } |
nothing calls this directly
no test coverage detected