deepprint_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package deepprint
  5. import (
  6. "bytes"
  7. "testing"
  8. "inet.af/netaddr"
  9. "tailscale.com/net/dns"
  10. "tailscale.com/wgengine/router"
  11. "tailscale.com/wgengine/wgcfg"
  12. )
  13. func TestDeepPrint(t *testing.T) {
  14. // v contains the types of values we care about for our current callers.
  15. // Mostly we're just testing that we don't panic on handled types.
  16. v := getVal()
  17. var buf bytes.Buffer
  18. Print(&buf, v)
  19. t.Logf("Got: %s", buf.Bytes())
  20. hash1 := Hash(v)
  21. t.Logf("hash: %v", hash1)
  22. for i := 0; i < 20; i++ {
  23. hash2 := Hash(getVal())
  24. if hash1 != hash2 {
  25. t.Error("second hash didn't match")
  26. }
  27. }
  28. }
  29. func getVal() []interface{} {
  30. return []interface{}{
  31. &wgcfg.Config{
  32. Name: "foo",
  33. Addresses: []netaddr.IPPrefix{{Bits: 5, IP: netaddr.IPFrom16([16]byte{3: 3})}},
  34. ListenPort: 5,
  35. Peers: []wgcfg.Peer{
  36. {
  37. Endpoints: "foo:5",
  38. },
  39. },
  40. },
  41. &router.Config{
  42. DNS: dns.Config{
  43. Nameservers: []netaddr.IP{netaddr.IPv4(8, 8, 8, 8)},
  44. Domains: []string{"tailscale.net"},
  45. },
  46. },
  47. map[string]string{
  48. "key1": "val1",
  49. "key2": "val2",
  50. "key3": "val3",
  51. "key4": "val4",
  52. "key5": "val5",
  53. "key6": "val6",
  54. "key7": "val7",
  55. "key8": "val8",
  56. "key9": "val9",
  57. },
  58. }
  59. }