control/controlclient: unexport Status.state, add test-only accessor

Updates #cleanup
Updates #1909

Change-Id: I38dcde6fa0de0f58ede4529992cee2e36de33dd6
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/9167/head
Brad Fitzpatrick 1 year ago committed by Brad Fitzpatrick
parent 306b85b9a3
commit 9ce1f5c7d2

@ -666,8 +666,8 @@ func (c *Auto) sendStatus(who string, err error, url string, nm *netmap.NetworkM
URL: url, URL: url,
Persist: p, Persist: p,
NetMap: nm, NetMap: nm,
State: state,
Err: err, Err: err,
state: state,
} }
c.observer.SetControlClientStatus(new) c.observer.SetControlClientStatus(new)

@ -21,7 +21,7 @@ func fieldsOf(t reflect.Type) (fields []string) {
func TestStatusEqual(t *testing.T) { func TestStatusEqual(t *testing.T) {
// Verify that the Equal method stays in sync with reality // Verify that the Equal method stays in sync with reality
equalHandles := []string{"LoginFinished", "LogoutFinished", "Err", "URL", "NetMap", "State", "Persist"} equalHandles := []string{"LoginFinished", "LogoutFinished", "Err", "URL", "NetMap", "Persist", "state"}
if have := fieldsOf(reflect.TypeOf(Status{})); !reflect.DeepEqual(have, equalHandles) { 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", t.Errorf("Status.Equal check might be out of sync\nfields: %q\nhandled: %q\n",
have, equalHandles) have, equalHandles)
@ -52,13 +52,13 @@ func TestStatusEqual(t *testing.T) {
true, true,
}, },
{ {
&Status{State: StateNew}, &Status{state: StateNew},
&Status{State: StateNew}, &Status{state: StateNew},
true, true,
}, },
{ {
&Status{State: StateNew}, &Status{state: StateNew},
&Status{State: StateAuthenticated}, &Status{state: StateAuthenticated},
false, false,
}, },
{ {

@ -69,14 +69,18 @@ type Status struct {
URL string // interactive URL to visit to finish logging in URL string // interactive URL to visit to finish logging in
NetMap *netmap.NetworkMap // server-pushed configuration NetMap *netmap.NetworkMap // server-pushed configuration
// The internal state should not be exposed outside this Persist *persist.PersistView // locally persisted configuration
// state is the internal state. It should not be exposed outside this
// package, but we have some automated tests elsewhere that need to // package, but we have some automated tests elsewhere that need to
// use them. Please don't use these fields. // use it via the StateForTest accessor.
// TODO(apenwarr): Unexport or remove these. // TODO(apenwarr): Unexport or remove these.
State State state State
Persist *persist.PersistView // locally persisted configuration
} }
// StateForTest returns the internal state of s for tests only.
func (s *Status) StateForTest() State { return s.state }
// Equal reports whether s and s2 are equal. // Equal reports whether s and s2 are equal.
func (s *Status) Equal(s2 *Status) bool { func (s *Status) Equal(s2 *Status) bool {
if s == nil && s2 == nil { if s == nil && s2 == nil {
@ -89,7 +93,7 @@ func (s *Status) Equal(s2 *Status) bool {
s.URL == s2.URL && s.URL == s2.URL &&
reflect.DeepEqual(s.Persist, s2.Persist) && reflect.DeepEqual(s.Persist, s2.Persist) &&
reflect.DeepEqual(s.NetMap, s2.NetMap) && reflect.DeepEqual(s.NetMap, s2.NetMap) &&
s.State == s2.State s.state == s2.state
} }
func (s Status) String() string { func (s Status) String() string {
@ -97,5 +101,5 @@ func (s Status) String() string {
if err != nil { if err != nil {
panic(err) panic(err)
} }
return s.State.String() + " " + string(b) return s.state.String() + " " + string(b)
} }

Loading…
Cancel
Save