ldap_auto_delete_guard_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. package job
  2. import "testing"
  3. // A bind that succeeds with an unusable search returns (empty, nil); the only
  4. // guard was `err != nil`, so that answer detached the entire inbound.
  5. func TestAutoDeleteAllowed(t *testing.T) {
  6. cases := []struct {
  7. name string
  8. previous int64
  9. fetched int
  10. want bool
  11. }{
  12. {"empty fetch on a fresh job is refused", 0, 0, false},
  13. {"empty fetch after a healthy sync is refused", 500, 0, false},
  14. {"full fetch on a fresh job is allowed", 0, 500, true},
  15. {"steady fetch is allowed", 500, 500, true},
  16. {"growth is allowed", 500, 900, true},
  17. {"shrink above the retention floor is allowed", 500, 250, true},
  18. {"shrink below the retention floor is refused", 500, 249, false},
  19. {"collapse to a single user is refused", 500, 1, false},
  20. {"single user with no history is allowed", 0, 1, true},
  21. }
  22. for _, c := range cases {
  23. t.Run(c.name, func(t *testing.T) {
  24. j := NewLdapSyncJob()
  25. j.lastFlagCount.Store(c.previous)
  26. if got := j.autoDeleteSafeForFetch(c.fetched); got != c.want {
  27. t.Fatalf("autoDeleteSafeForFetch(previous=%d, fetched=%d) = %v, want %v",
  28. c.previous, c.fetched, got, c.want)
  29. }
  30. })
  31. }
  32. }