2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-02-05 22:16:58 +00:00
|
|
|
|
|
|
|
package controlclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func fieldsOf(t reflect.Type) (fields []string) {
|
|
|
|
for i := 0; i < t.NumField(); i++ {
|
2020-05-03 20:58:39 +00:00
|
|
|
if name := t.Field(i).Name; name != "_" {
|
|
|
|
fields = append(fields, name)
|
|
|
|
}
|
2020-02-05 22:16:58 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStatusEqual(t *testing.T) {
|
|
|
|
// Verify that the Equal method stays in sync with reality
|
2023-08-30 18:09:36 +00:00
|
|
|
equalHandles := []string{"Err", "URL", "NetMap", "Persist", "state"}
|
2024-02-09 01:34:22 +00:00
|
|
|
if have := fieldsOf(reflect.TypeFor[Status]()); !reflect.DeepEqual(have, equalHandles) {
|
2020-02-05 22:16:58 +00:00
|
|
|
t.Errorf("Status.Equal check might be out of sync\nfields: %q\nhandled: %q\n",
|
|
|
|
have, equalHandles)
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
a, b *Status
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
&Status{},
|
|
|
|
nil,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
nil,
|
|
|
|
&Status{},
|
|
|
|
false,
|
|
|
|
},
|
2021-01-05 18:56:21 +00:00
|
|
|
{
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
true,
|
|
|
|
},
|
2020-02-05 22:16:58 +00:00
|
|
|
{
|
|
|
|
&Status{},
|
|
|
|
&Status{},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2023-08-31 01:18:10 +00:00
|
|
|
&Status{},
|
2023-08-30 17:21:56 +00:00
|
|
|
&Status{state: StateAuthenticated},
|
2020-02-05 22:16:58 +00:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for i, tt := range tests {
|
|
|
|
got := tt.a.Equal(tt.b)
|
|
|
|
if got != tt.want {
|
|
|
|
t.Errorf("%d. Equal = %v; want %v", i, got, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|