| 47 | } |
| 48 | |
| 49 | func TestServer_Run_HTTP(t *testing.T) { |
| 50 | server := &http.Server{ |
| 51 | Addr: "localhost:0", // Use port 0 for automatic port assignment |
| 52 | } |
| 53 | |
| 54 | srv := New(server) |
| 55 | |
| 56 | // Start server in background |
| 57 | ctx, cancel := context.WithCancel(context.Background()) |
| 58 | defer cancel() |
| 59 | |
| 60 | go func() { |
| 61 | _ = srv.Run() |
| 62 | }() |
| 63 | |
| 64 | // Give server time to start |
| 65 | time.Sleep(200 * time.Millisecond) |
| 66 | |
| 67 | // Test shutdown |
| 68 | shutdownCtx, shutdownCancel := context.WithTimeout(ctx, 2*time.Second) |
| 69 | defer shutdownCancel() |
| 70 | |
| 71 | if err := srv.Shutdown(shutdownCtx); err != nil { |
| 72 | t.Errorf("Shutdown() error = %v", err) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func TestServer_Run_WithTLSer(t *testing.T) { |
| 77 | mockTLS := &mockTLSer{} |