broadcast_test.go 853 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package beacon
  7. import (
  8. "net"
  9. "testing"
  10. )
  11. var addrToBcast = []struct {
  12. addr, bcast string
  13. }{
  14. {"172.16.32.33/25", "172.16.32.127/25"},
  15. {"172.16.32.129/25", "172.16.32.255/25"},
  16. {"172.16.32.33/24", "172.16.32.255/24"},
  17. {"172.16.32.33/22", "172.16.35.255/22"},
  18. {"172.16.32.33/0", "255.255.255.255/0"},
  19. {"172.16.32.33/32", "172.16.32.33/32"},
  20. }
  21. func TestBroadcastAddr(t *testing.T) {
  22. for _, tc := range addrToBcast {
  23. _, net, err := net.ParseCIDR(tc.addr)
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. bc := bcast(net).String()
  28. if bc != tc.bcast {
  29. t.Errorf("%q != %q", bc, tc.bcast)
  30. }
  31. }
  32. }