inbound_util_test.go 884 B

123456789101112131415161718192021222324252627282930313233343536
  1. package service
  2. import (
  3. "math"
  4. "slices"
  5. "testing"
  6. )
  7. func TestNormalizeSubSortIndex(t *testing.T) {
  8. cases := []struct {
  9. in, want int
  10. }{
  11. {0, 1},
  12. {1, 1},
  13. {7, 7},
  14. {-1, -1},
  15. {-10, -10},
  16. }
  17. for _, tc := range cases {
  18. if got := normalizeSubSortIndex(tc.in); got != tc.want {
  19. t.Fatalf("normalizeSubSortIndex(%d) = %d, want %d", tc.in, got, tc.want)
  20. }
  21. }
  22. }
  23. // A size near MaxInt used to overflow the capacity math and panic in make (CodeQL #119).
  24. func TestChunkHugeSizeKeepsOneBatch(t *testing.T) {
  25. strs := []string{"a", "b", "c"}
  26. if got := chunkStrings(strs, math.MaxInt); len(got) != 1 || !slices.Equal(got[0], strs) {
  27. t.Fatalf("chunkStrings(MaxInt) = %v, want [%v]", got, strs)
  28. }
  29. ints := []int{1, 2, 3}
  30. if got := chunkInts(ints, math.MaxInt); len(got) != 1 || !slices.Equal(got[0], ints) {
  31. t.Fatalf("chunkInts(MaxInt) = %v, want [%v]", got, ints)
  32. }
  33. }