tailcfg: don't panic on clone of nil RegisterRequest

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-09-14 09:00:04 -07:00 committed by Brad Fitzpatrick
parent dabeda21e0
commit 3e2a7de2e9
2 changed files with 11 additions and 0 deletions

View File

@ -635,6 +635,9 @@ type RegisterRequest struct {
// //
// TODO: extend cmd/cloner to generate this method. // TODO: extend cmd/cloner to generate this method.
func (req *RegisterRequest) Clone() *RegisterRequest { func (req *RegisterRequest) Clone() *RegisterRequest {
if req == nil {
return nil
}
res := new(RegisterRequest) res := new(RegisterRequest)
*res = *req *res = *req
if res.Hostinfo != nil { if res.Hostinfo != nil {

View File

@ -546,3 +546,11 @@ func TestDiscoKeyAppend(t *testing.T) {
t.Errorf("got %q; want %q", got, want) t.Errorf("got %q; want %q", got, want)
} }
} }
func TestRegisterRequestNilClone(t *testing.T) {
var nilReq *RegisterRequest
got := nilReq.Clone()
if got != nil {
t.Errorf("got = %v; want nil", got)
}
}