Files
Charon/backend/internal/caddy/importer_subroute_test.go
T
GitHub Actions 3169b05156 fix: skip incomplete system log viewer tests
- Marked 12 tests as skip pending feature implementation
- Features tracked in GitHub issue #686 (system log viewer feature completion)
- Tests cover sorting by timestamp/level/method/URI/status, pagination controls, filtering by text/level, download functionality
- Unblocks Phase 2 at 91.7% pass rate to proceed to Phase 3 security enforcement validation
- TODO comments in code reference GitHub #686 for feature completion tracking
- Tests skipped: Pagination (3), Search/Filter (2), Download (2), Sorting (1), Log Display (4)
2026-02-09 21:55:55 +00:00

87 lines
1.9 KiB
Go

package caddy
import (
"encoding/json"
"testing"
)
func TestExtractHandlers_Subroute(t *testing.T) {
// Test JSON that mimics the plex.caddy structure
rawJSON := `{
"apps": {
"http": {
"servers": {
"srv0": {
"routes": [{
"match": [{"host": ["plex.hatfieldhosted.com"]}],
"handle": [{
"handler": "subroute",
"routes": [{
"handle": [{
"handler": "headers"
}, {
"handler": "reverse_proxy",
"upstreams": [{"dial": "100.99.23.57:32400"}]
}]
}]
}]
}]
}
}
}
}
}`
var config CaddyConfig
err := json.Unmarshal([]byte(rawJSON), &config)
if err != nil {
t.Fatalf("Failed to unmarshal JSON: %v", err)
}
importer := NewImporter("caddy")
route := config.Apps.HTTP.Servers["srv0"].Routes[0]
handlers := importer.extractHandlers(route.Handle)
// We should get 2 handlers: headers and reverse_proxy
if len(handlers) != 2 {
t.Fatalf("Expected 2 handlers, got %d", len(handlers))
}
if handlers[0].Handler != "headers" {
t.Errorf("Expected first handler to be 'headers', got '%s'", handlers[0].Handler)
}
if handlers[1].Handler != "reverse_proxy" {
t.Errorf("Expected second handler to be 'reverse_proxy', got '%s'", handlers[1].Handler)
}
// Check if upstreams are preserved
if handlers[1].Upstreams == nil {
t.Fatal("Upstreams should not be nil")
}
upstreams, ok := handlers[1].Upstreams.([]any)
if !ok {
t.Fatal("Upstreams should be []any")
}
if len(upstreams) == 0 {
t.Fatal("Upstreams should not be empty")
}
upstream, ok := upstreams[0].(map[string]any)
if !ok {
t.Fatal("First upstream should be map[string]any")
}
dial, ok := upstream["dial"].(string)
if !ok {
t.Fatal("Dial should be a string")
}
if dial != "100.99.23.57:32400" {
t.Errorf("Expected dial to be '100.99.23.57:32400', got '%s'", dial)
}
}