spark-server/internal/pkg/reqctx/reqctx_test.go
zhr ae9a71034d feat: implement Spark IM V3 modular monolith
Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 19:52:11 +08:00

39 lines
969 B
Go

package reqctx
import "testing"
func TestParseHTTPRealIP(t *testing.T) {
got := ParseHTTPRealIP(" 203.0.113.10 ", "198.51.100.1, 192.0.2.1", "192.0.2.1:1234")
if got != "203.0.113.10" {
t.Fatalf("x-real-ip %q", got)
}
got = ParseHTTPRealIP("", "198.51.100.1, 192.0.2.1", "192.0.2.1:1234")
if got != "198.51.100.1" {
t.Fatalf("xff %q", got)
}
got = ParseHTTPRealIP("", "", "192.0.2.1:1234")
if got != "192.0.2.1" {
t.Fatalf("remote %q", got)
}
}
func TestRealIPFromContext(t *testing.T) {
ctx := With(t.Context(), &RequestContext{RealIP: "203.0.113.10"})
if RealIP(ctx) != "203.0.113.10" {
t.Fatalf("got %q", RealIP(ctx))
}
if RealIP(t.Context()) != "" {
t.Fatal("empty ctx")
}
}
func TestLangFromContext(t *testing.T) {
ctx := With(t.Context(), &RequestContext{Language: "en-US"})
if Language(ctx) != "en" {
t.Fatalf("got %q", Language(ctx))
}
if Language(t.Context()) != "zh-CN" {
t.Fatalf("default %q", Language(t.Context()))
}
}