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"
|
2020-02-14 21:09:19 +00:00
|
|
|
|
|
|
|
"tailscale.com/types/empty"
|
2020-02-05 22:16:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 17:21:56 +00:00
|
|
|
equalHandles := []string{"LoginFinished", "LogoutFinished", "Err", "URL", "NetMap", "Persist", "state"}
|
2020-02-05 22:16:58 +00:00
|
|
|
if have := fieldsOf(reflect.TypeOf(Status{})); !reflect.DeepEqual(have, equalHandles) {
|
|
|
|
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-30 17:21:56 +00:00
|
|
|
&Status{state: StateNew},
|
|
|
|
&Status{state: StateNew},
|
2020-02-05 22:16:58 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2023-08-30 17:21:56 +00:00
|
|
|
&Status{state: StateNew},
|
|
|
|
&Status{state: StateAuthenticated},
|
2020-02-05 22:16:58 +00:00
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&Status{LoginFinished: nil},
|
2020-02-14 21:09:19 +00:00
|
|
|
&Status{LoginFinished: new(empty.Message)},
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|