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 21:58:39 +01: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
|
2020-05-27 19:46:09 +01:00
|
|
|
equalHandles := []string{"LoginFinished", "Err", "URL", "Persist", "NetMap", "Hostinfo", "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,
|
|
|
|
},
|
|
|
|
{
|
2020-05-27 19:46:09 +01:00
|
|
|
&Status{State: StateNew},
|
|
|
|
&Status{State: StateNew},
|
2020-02-05 22:16:58 +00:00
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2020-05-27 19:46:09 +01: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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-28 05:14:28 +01:00
|
|
|
|
|
|
|
func TestOSVersion(t *testing.T) {
|
|
|
|
if osVersion == nil {
|
|
|
|
t.Skip("not available for OS")
|
|
|
|
}
|
|
|
|
t.Logf("Got: %#q", osVersion())
|
|
|
|
}
|