netlogtype_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build !ts_omit_tailnetlock
  4. package netlogtype
  5. import (
  6. "encoding/json"
  7. "math"
  8. "net/netip"
  9. "testing"
  10. "github.com/google/go-cmp/cmp"
  11. "tailscale.com/util/must"
  12. )
  13. func TestMaxSize(t *testing.T) {
  14. maxAddr := netip.AddrFrom16([16]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255})
  15. maxAddrPort := netip.AddrPortFrom(maxAddr, math.MaxUint16)
  16. cc := ConnectionCounts{
  17. // NOTE: These composite literals are deliberately unkeyed so that
  18. // added fields result in a build failure here.
  19. // Newly added fields should result in an update to both
  20. // MaxConnectionCountsJSONSize and MaxConnectionCountsCBORSize.
  21. Connection{math.MaxUint8, maxAddrPort, maxAddrPort},
  22. Counts{math.MaxUint64, math.MaxUint64, math.MaxUint64, math.MaxUint64},
  23. }
  24. outJSON := must.Get(json.Marshal(cc))
  25. if string(outJSON) != maxJSONConnCounts {
  26. t.Errorf("JSON mismatch (-got +want):\n%s", cmp.Diff(string(outJSON), maxJSONConnCounts))
  27. }
  28. }