2020-02-05 22:16:58 +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.
|
|
|
|
|
|
|
|
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
|
2022-05-03 22:07:30 +00:00
|
|
|
equalHandles := []string{"LoginFinished", "LogoutFinished", "Err", "URL", "NetMap", "State", "Persist"}
|
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,
|
|
|
|
},
|
|
|
|
{
|
2020-05-27 18:46:09 +00:00
|
|
|
&Status{State: StateNew},
|
|
|
|
&Status{State: StateNew},
|
2020-02-05 22:16:58 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2020-05-27 18:46:09 +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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|