broadcast_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package beacon
  16. import (
  17. "net"
  18. "testing"
  19. )
  20. var addrToBcast = []struct {
  21. addr, bcast string
  22. }{
  23. {"172.16.32.33/25", "172.16.32.127/25"},
  24. {"172.16.32.129/25", "172.16.32.255/25"},
  25. {"172.16.32.33/24", "172.16.32.255/24"},
  26. {"172.16.32.33/22", "172.16.35.255/22"},
  27. {"172.16.32.33/0", "255.255.255.255/0"},
  28. {"172.16.32.33/32", "172.16.32.33/32"},
  29. }
  30. func TestBroadcastAddr(t *testing.T) {
  31. for _, tc := range addrToBcast {
  32. _, net, err := net.ParseCIDR(tc.addr)
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. bc := bcast(net).String()
  37. if bc != tc.bcast {
  38. t.Errorf("%q != %q", bc, tc.bcast)
  39. }
  40. }
  41. }