This repository has been archived on 2026-10-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Ananta-ps/internal/gateway/gateway_test.go
T

52 lines
1.2 KiB
Go

package gateway
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"ananta-ps/internal/config"
)
func TestGatewayDispatch(t *testing.T) {
cfg := &config.Config{
Client: config.ClientConfig{
ServerID: 801,
},
Network: config.NetworkConfig{
AdvertisedHost: "127.0.0.1",
LoginPorts: []int{5200, 5201},
Proxy: config.ProxyConfig{
LoginListPort: 5801,
},
},
}
gw := New(cfg, "../../public", "../../certs")
// Test LoginList
req := httptest.NewRequest("GET", "/LoginList", nil)
w := httptest.NewRecorder()
gw.handleDispatch(w, req)
resp := w.Result()
if resp.StatusCode != http.StatusOK {
t.Fatalf("expected 200, got %d", resp.StatusCode)
}
body := w.Body.String()
if !strings.Contains(body, "127.0.0.1:5200") {
t.Fatalf("expected 127.0.0.1:5200 in LoginList, got %s", body)
}
// Test ServerList
req = httptest.NewRequest("GET", "/OuterTest1/serverlist.txt", nil)
w = httptest.NewRecorder()
gw.handleDispatch(w, req)
if w.Result().StatusCode != http.StatusOK {
t.Fatalf("expected 200 for serverlist.txt, got %d", w.Result().StatusCode)
}
if !strings.Contains(w.Body.String(), "QA101,Outer,http://127.0.0.1:5801/LoginList,1,14") {
t.Fatalf("unexpected serverlist body: %s", w.Body.String())
}
}