mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix: propagate allocated transport ports
This commit is contained in:
@@ -35,8 +35,9 @@ func TestAllocatedStartInjectsDynamicEndpointAndCallsReadyAfterProbe(t *testing.
|
||||
|
||||
ready = true
|
||||
path := filepath.Join(t.TempDir(), "env.txt")
|
||||
command := []string{"/bin/sh", "-c", "env > " + path}
|
||||
s, err := New(Config{Command: command, SDKBaseURL: server.URL, ReadyURL: server.URL + "/ready-probe", ReadyTimeout: time.Second, PollInterval: time.Millisecond})
|
||||
argsPath := filepath.Join(t.TempDir(), "args.txt")
|
||||
command := []string{"/bin/sh", "-c", "env > " + path + "; printf '%s' \"$@\" > " + argsPath, "shell"}
|
||||
s, err := New(Config{Command: command, SDKBaseURL: server.URL, ReadyURL: server.URL + "/ready-probe", Transport: "steam_sdr", ReadyTimeout: time.Second, PollInterval: time.Millisecond})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -53,11 +54,51 @@ func TestAllocatedStartInjectsDynamicEndpointAndCallsReadyAfterProbe(t *testing.
|
||||
if !strings.Contains(string(contents), "SDR_LISTEN_PORT=31001") || !strings.Contains(string(contents), "SDR_IP=203.0.113.9:31001") {
|
||||
t.Fatalf("dynamic endpoint not injected: %s", contents)
|
||||
}
|
||||
args, err := os.ReadFile(argsPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(args), "--port=31001") {
|
||||
t.Fatalf("dynamic port argument not injected: %s", args)
|
||||
}
|
||||
if !readyCalled {
|
||||
t.Fatal("Agones Ready was called before process-ready probe")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllocatedENetDoesNotReceiveSDRVariables(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/gameserver" {
|
||||
_, _ = w.Write([]byte(`{"status":{"address":"127.0.0.1","ports":[{"name":"game","port":31002}]}}`))
|
||||
return
|
||||
}
|
||||
if r.URL.Path == "/ready-probe" {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer server.Close()
|
||||
path := filepath.Join(t.TempDir(), "env.txt")
|
||||
s, err := New(Config{Command: []string{"/bin/sh", "-c", "env > " + path}, SDKBaseURL: server.URL, ReadyURL: server.URL + "/ready-probe", Transport: "enet", ReadyTimeout: time.Second})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.Start(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.Wait(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
contents, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(contents), "SDR_LISTEN_PORT=") || strings.Contains(string(contents), "SDR_IP=") {
|
||||
t.Fatalf("ENet received SDR variables: %s", contents)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDirectModeDoesNotRequireAgonesReadiness(t *testing.T) {
|
||||
s, err := New(Config{Command: []string{"/bin/sh", "-c", "exit 0"}})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user