xray_hot_apply_persist_test.go 832 B

12345678910111213141516171819202122232425
  1. package service
  2. import (
  3. "os"
  4. "path/filepath"
  5. "testing"
  6. "github.com/mhsanaei/3x-ui/v3/internal/util/json_util"
  7. "github.com/mhsanaei/3x-ui/v3/internal/xray"
  8. )
  9. // The empty-diff branch of tryHotApply makes no gRPC call, so it can prove the
  10. // hot-apply path refreshes config.json without a running core.
  11. func TestTryHotApplyWritesConfigFile(t *testing.T) {
  12. path := filepath.Join(t.TempDir(), "config.json")
  13. routing := json_util.RawMessage(`{"rules":[]}`)
  14. process := xray.NewTestProcess(&xray.Config{RouterConfig: routing}, path)
  15. if !(&XrayService{}).tryHotApply(process, &xray.Config{RouterConfig: routing}) {
  16. t.Fatal("tryHotApply = false, want true for an unchanged config")
  17. }
  18. if data, err := os.ReadFile(path); err != nil || len(data) == 0 {
  19. t.Fatalf("config.json not written after hot apply (err %v)", err)
  20. }
  21. }