package control

import (
	"net/http"
	"testing"

	cfgpkg "github.com/jan/fm-rds-tx/internal/config"
)

func TestNewHTTPServerConfig(t *testing.T) {
	cfg := cfgpkg.Default()
	handler := http.NewServeMux()
	srv := NewHTTPServer(cfg, handler)

	if srv.Addr != cfg.Control.ListenAddress {
		t.Fatalf("expected server address %q, got %q", cfg.Control.ListenAddress, srv.Addr)
	}
	if srv.Handler != handler {
		t.Fatalf("expected handler to be preserved")
	}
	if srv.ReadTimeout != 0 {
		t.Fatalf("expected read timeout to remain disabled for streaming requests, got %s", srv.ReadTimeout)
	}
	if srv.WriteTimeout != 0 {
		t.Fatalf("expected write timeout to remain disabled for streaming requests, got %s", srv.WriteTimeout)
	}
	if srv.ReadHeaderTimeout != defaultReadHeaderTimeout {
		t.Fatalf("expected read header timeout %s, got %s", defaultReadHeaderTimeout, srv.ReadHeaderTimeout)
	}
	if srv.IdleTimeout != defaultIdleTimeout {
		t.Fatalf("expected idle timeout %s, got %s", defaultIdleTimeout, srv.IdleTimeout)
	}
	if srv.MaxHeaderBytes != defaultMaxHeaderBytes {
		t.Fatalf("expected max header bytes %d, got %d", defaultMaxHeaderBytes, srv.MaxHeaderBytes)
	}
}
