process_persist_test.go 768 B

123456789101112131415161718192021222324252627
  1. package xray
  2. import (
  3. "os"
  4. "path/filepath"
  5. "strings"
  6. "testing"
  7. "github.com/mhsanaei/3x-ui/v3/internal/util/json_util"
  8. )
  9. func TestPersistConfigWritesCurrentSnapshot(t *testing.T) {
  10. path := filepath.Join(t.TempDir(), "config.json")
  11. p := NewTestProcess(&Config{RouterConfig: json_util.RawMessage(`{"rules":[]}`)}, path)
  12. p.SetConfig(&Config{RouterConfig: json_util.RawMessage(`{"rules":[{"outboundTag":"warp"}]}`)})
  13. if err := p.PersistConfig(); err != nil {
  14. t.Fatalf("PersistConfig: %v", err)
  15. }
  16. data, err := os.ReadFile(path)
  17. if err != nil {
  18. t.Fatal(err)
  19. }
  20. if !strings.Contains(string(data), `"outboundTag": "warp"`) && !strings.Contains(string(data), `"outboundTag":"warp"`) {
  21. t.Fatalf("config file does not hold the new routing:\n%s", data)
  22. }
  23. }