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 != defaultReadTimeout {
		t.Fatalf("expected read timeout %s, got %s", defaultReadTimeout, srv.ReadTimeout)
	}
	if srv.WriteTimeout != defaultWriteTimeout {
		t.Fatalf("expected write timeout %s, got %s", defaultWriteTimeout, srv.WriteTimeout)
	}
	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)
	}
}
