Files
3x-ui/internal/xray/process_persist_test.go
T
kaveh 3948b83405 Write config.json after a hot apply (#6686)
* 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
2026-10-03 01:23:25 +02:00

28 lines
768 B
Go

package xray
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/mhsanaei/3x-ui/v3/internal/util/json_util"
)
func TestPersistConfigWritesCurrentSnapshot(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.json")
p := NewTestProcess(&Config{RouterConfig: json_util.RawMessage(`{"rules":[]}`)}, path)
p.SetConfig(&Config{RouterConfig: json_util.RawMessage(`{"rules":[{"outboundTag":"warp"}]}`)})
if err := p.PersistConfig(); err != nil {
t.Fatalf("PersistConfig: %v", err)
}
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(data), `"outboundTag": "warp"`) && !strings.Contains(string(data), `"outboundTag":"warp"`) {
t.Fatalf("config file does not hold the new routing:\n%s", data)
}
}