2020-06-30 02:36:45 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-06-28 17:58:21 +00:00
|
|
|
package deepprint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"inet.af/netaddr"
|
2021-03-26 00:41:51 +00:00
|
|
|
"tailscale.com/wgengine/router"
|
2021-01-29 20:16:36 +00:00
|
|
|
"tailscale.com/wgengine/wgcfg"
|
2020-06-28 17:58:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDeepPrint(t *testing.T) {
|
|
|
|
// v contains the types of values we care about for our current callers.
|
|
|
|
// Mostly we're just testing that we don't panic on handled types.
|
|
|
|
v := getVal()
|
|
|
|
|
|
|
|
hash1 := Hash(v)
|
|
|
|
t.Logf("hash: %v", hash1)
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
hash2 := Hash(getVal())
|
|
|
|
if hash1 != hash2 {
|
|
|
|
t.Error("second hash didn't match")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getVal() []interface{} {
|
|
|
|
return []interface{}{
|
|
|
|
&wgcfg.Config{
|
2021-04-03 01:04:39 +00:00
|
|
|
Name: "foo",
|
|
|
|
Addresses: []netaddr.IPPrefix{{Bits: 5, IP: netaddr.IPFrom16([16]byte{3: 3})}},
|
2020-06-28 17:58:21 +00:00
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
{
|
2021-01-14 01:10:41 +00:00
|
|
|
Endpoints: "foo:5",
|
2020-06-28 17:58:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&router.Config{
|
2021-04-03 02:24:02 +00:00
|
|
|
Routes: []netaddr.IPPrefix{
|
|
|
|
netaddr.MustParseIPPrefix("1.2.3.0/24"),
|
|
|
|
netaddr.MustParseIPPrefix("1234::/64"),
|
2020-07-14 13:12:00 +00:00
|
|
|
},
|
2020-06-28 17:58:21 +00:00
|
|
|
},
|
|
|
|
map[string]string{
|
|
|
|
"key1": "val1",
|
|
|
|
"key2": "val2",
|
|
|
|
"key3": "val3",
|
|
|
|
"key4": "val4",
|
|
|
|
"key5": "val5",
|
|
|
|
"key6": "val6",
|
|
|
|
"key7": "val7",
|
|
|
|
"key8": "val8",
|
|
|
|
"key9": "val9",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-05-08 01:05:04 +00:00
|
|
|
|
|
|
|
func BenchmarkHash(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
v := getVal()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
Hash(v)
|
|
|
|
}
|
|
|
|
}
|