inbound_exclude_from_sub_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package service
  2. import (
  3. "testing"
  4. "github.com/mhsanaei/3x-ui/v3/internal/database"
  5. "github.com/mhsanaei/3x-ui/v3/internal/database/model"
  6. )
  7. func TestUpdateInbound_PersistsExcludeFromSub(t *testing.T) {
  8. setupConflictDB(t)
  9. ib := makeInboundWithSubSortIndex("in-7004-tcp", 7004, 1)
  10. if err := database.GetDB().Create(ib).Error; err != nil {
  11. t.Fatalf("create inbound: %v", err)
  12. }
  13. update := *ib
  14. update.ExcludeFromSub = true
  15. got, _, err := (&InboundService{}).UpdateInbound(&update)
  16. if err != nil {
  17. t.Fatalf("UpdateInbound: %v", err)
  18. }
  19. if !got.ExcludeFromSub {
  20. t.Fatal("returned ExcludeFromSub = false, want true")
  21. }
  22. var reloaded model.Inbound
  23. if err := database.GetDB().First(&reloaded, ib.Id).Error; err != nil {
  24. t.Fatalf("reload: %v", err)
  25. }
  26. if !reloaded.ExcludeFromSub {
  27. t.Fatal("persisted ExcludeFromSub = false, want true")
  28. }
  29. }
  30. func TestAddInbound_PersistsExcludeFromSub(t *testing.T) {
  31. setupConflictDB(t)
  32. ib := makeInboundWithSubSortIndex("in-7005-tcp", 7005, 1)
  33. ib.ExcludeFromSub = true
  34. got, _, err := (&InboundService{}).AddInbound(ib)
  35. if err != nil {
  36. t.Fatalf("AddInbound: %v", err)
  37. }
  38. if !got.ExcludeFromSub {
  39. t.Fatal("returned ExcludeFromSub = false, want true")
  40. }
  41. var reloaded model.Inbound
  42. if err := database.GetDB().First(&reloaded, got.Id).Error; err != nil {
  43. t.Fatalf("reload: %v", err)
  44. }
  45. if !reloaded.ExcludeFromSub {
  46. t.Fatal("persisted ExcludeFromSub = false, want true")
  47. }
  48. }