mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-05 04:11:59 +00:00
util/deephash: fix unexported time.Time hashing
Updates tailscale/corp#6311 Change-Id: I33cd7e4040966261c2f2eb3d32f29936aeb7f632 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
51c3d74095
commit
04cf46a762
@@ -28,6 +28,7 @@ import (
|
||||
"tailscale.com/types/ipproto"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/structs"
|
||||
"tailscale.com/util/deephash/testtype"
|
||||
"tailscale.com/util/dnsname"
|
||||
"tailscale.com/version"
|
||||
"tailscale.com/wgengine/filter"
|
||||
@@ -516,6 +517,21 @@ func TestGetTypeHasher(t *testing.T) {
|
||||
val: time.Unix(0, 0).In(time.UTC),
|
||||
out: "\x141970-01-01T00:00:00Z",
|
||||
},
|
||||
{
|
||||
name: "time_ptr", // addressable, as opposed to "time" test above
|
||||
val: ptrTo(time.Unix(0, 0).In(time.UTC)),
|
||||
out: "\x01\x141970-01-01T00:00:00Z",
|
||||
},
|
||||
{
|
||||
name: "time_ptr_via_unexported",
|
||||
val: testtype.NewUnexportedAddressableTime(time.Unix(0, 0).In(time.UTC)),
|
||||
out: "\x01\x141970-01-01T00:00:00Z",
|
||||
},
|
||||
{
|
||||
name: "time_ptr_via_unexported_value",
|
||||
val: *testtype.NewUnexportedAddressableTime(time.Unix(0, 0).In(time.UTC)),
|
||||
want: false, // neither addressable nor interface-able
|
||||
},
|
||||
{
|
||||
name: "time_custom_zone",
|
||||
val: time.Unix(1655311822, 0).In(time.FixedZone("FOO", -60*60)),
|
||||
@@ -817,6 +833,26 @@ func TestArrayAllocs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test for http://go/corp/6311 issue.
|
||||
func TestHashThroughView(t *testing.T) {
|
||||
type sshPolicyOut struct {
|
||||
Rules []tailcfg.SSHRuleView
|
||||
}
|
||||
type mapResponseOut struct {
|
||||
SSHPolicy *sshPolicyOut
|
||||
}
|
||||
// Just test we don't panic:
|
||||
_ = Hash(&mapResponseOut{
|
||||
SSHPolicy: &sshPolicyOut{
|
||||
Rules: []tailcfg.SSHRuleView{
|
||||
(&tailcfg.SSHRule{
|
||||
RuleExpires: ptrTo(time.Unix(123, 0)),
|
||||
}).View(),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkHashArray(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
type T struct {
|
||||
|
||||
Reference in New Issue
Block a user