Files
GaCy-GO/internal/sdkserver/runtime_config_test.go
T

44 lines
1.4 KiB
Go

package sdkserver
import (
"encoding/base64"
"net/http/httptest"
"testing"
"gac-hkrpg-go/internal/common"
goproto "gac-hkrpg-go/protocol/proto"
"google.golang.org/protobuf/proto"
)
func TestConfiguredDispatchAndGateway(t *testing.T) {
// Fixture endpoints must appear on the wire instead of any local defaults.
cfg := common.RuntimeConfig{PublicSDKURL: "https://sdk.example.invalid/prefix", PublicGameHost: "game.example.invalid", GamePort: 32123}
w := httptest.NewRecorder()
queryDispatch(w, httptest.NewRequest("GET", "/query_dispatch", nil), cfg)
raw, err := base64.StdEncoding.DecodeString(w.Body.String())
if err != nil {
t.Fatal(err)
}
var dispatch goproto.Dispatch
if err := proto.Unmarshal(raw, &dispatch); err != nil {
t.Fatal(err)
}
if len(dispatch.RegionList) != 1 || dispatch.RegionList[0].DispatchUrl != cfg.PublicSDKURL+"/query_gateway" {
t.Fatalf("wrong dispatch: %v", &dispatch)
}
state := &appState{runtime: cfg, hotfixMap: map[string]VersionConfig{"fixture": {}}}
w = httptest.NewRecorder()
queryGateway(state)(w, httptest.NewRequest("GET", "/query_gateway?version=fixture", nil))
raw, err = base64.StdEncoding.DecodeString(w.Body.String())
if err != nil {
t.Fatal(err)
}
var gateway goproto.Gateserver
if err := proto.Unmarshal(raw, &gateway); err != nil {
t.Fatal(err)
}
if gateway.Ip != cfg.PublicGameHost || gateway.Port != uint32(cfg.GamePort) {
t.Fatalf("wrong gateway: %v", &gateway)
}
}