mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-19 20:35:01 +03:00
3948b83405
* Write config.json after a hot apply tryHotApply only updated the in-memory snapshot, so bin/config.json stayed stale until the next cold start and the Telegram/Discord config backups uploaded old rules. Persist the new config once the API calls succeed; a write failure is logged and does not restart the running core. * Test that a hot apply refreshes config.json
26 lines
832 B
Go
26 lines
832 B
Go
package service
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/util/json_util"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/xray"
|
|
)
|
|
|
|
// The empty-diff branch of tryHotApply makes no gRPC call, so it can prove the
|
|
// hot-apply path refreshes config.json without a running core.
|
|
func TestTryHotApplyWritesConfigFile(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "config.json")
|
|
routing := json_util.RawMessage(`{"rules":[]}`)
|
|
process := xray.NewTestProcess(&xray.Config{RouterConfig: routing}, path)
|
|
|
|
if !(&XrayService{}).tryHotApply(process, &xray.Config{RouterConfig: routing}) {
|
|
t.Fatal("tryHotApply = false, want true for an unchanged config")
|
|
}
|
|
if data, err := os.ReadFile(path); err != nil || len(data) == 0 {
|
|
t.Fatalf("config.json not written after hot apply (err %v)", err)
|
|
}
|
|
}
|