2026-09-23 09:40:59 +08:00
|
|
|
package nginx
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-10-01 16:54:35 +08:00
|
|
|
"github.com/havline/havline/internal/config"
|
|
|
|
|
"github.com/havline/havline/internal/proxy"
|
2026-09-23 09:40:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGenerateIncludesWebSocketAndProxy(t *testing.T) {
|
|
|
|
|
cfg := config.Config{
|
|
|
|
|
DataDir: t.TempDir(),
|
|
|
|
|
NginxPIDFile: t.TempDir() + "/nginx.pid",
|
|
|
|
|
NginxMimeTypes: t.TempDir() + "/mime.types",
|
|
|
|
|
}
|
|
|
|
|
rules := []proxy.Rule{{
|
|
|
|
|
ID: 1,
|
|
|
|
|
Upstream: "http://192.168.1.10:5666",
|
|
|
|
|
ListenPort: 80,
|
|
|
|
|
ListenIPv4: true,
|
|
|
|
|
Hosts: []proxy.Host{{Hostname: "nas.example.com"}},
|
|
|
|
|
HTTPSEnabled: false,
|
|
|
|
|
HTTPRedirect: false,
|
|
|
|
|
Enabled: true,
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
content, err := Generate(cfg, rules, nil, GenerateOptions{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("generate failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
for _, want := range []string{
|
|
|
|
|
"client_max_body_size 50m;",
|
|
|
|
|
"listen 80;",
|
|
|
|
|
"server_name nas.example.com",
|
|
|
|
|
"proxy_pass http://192.168.1.10:5666",
|
|
|
|
|
"proxy_set_header Upgrade $http_upgrade",
|
|
|
|
|
"proxy_buffering off",
|
|
|
|
|
} {
|
|
|
|
|
if !strings.Contains(content, want) {
|
|
|
|
|
t.Fatalf("missing %q in generated config", want)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|