From 9ce1f5c7d228623806db5c1b1bb902be8eeb97e8 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 30 Aug 2023 10:21:56 -0700 Subject: [PATCH] control/controlclient: unexport Status.state, add test-only accessor Updates #cleanup Updates #1909 Change-Id: I38dcde6fa0de0f58ede4529992cee2e36de33dd6 Signed-off-by: Brad Fitzpatrick --- control/controlclient/auto.go | 2 +- control/controlclient/controlclient_test.go | 10 +++++----- control/controlclient/status.go | 16 ++++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/control/controlclient/auto.go b/control/controlclient/auto.go index 6f3ee95fc..38c56dee0 100644 --- a/control/controlclient/auto.go +++ b/control/controlclient/auto.go @@ -666,8 +666,8 @@ func (c *Auto) sendStatus(who string, err error, url string, nm *netmap.NetworkM URL: url, Persist: p, NetMap: nm, - State: state, Err: err, + state: state, } c.observer.SetControlClientStatus(new) diff --git a/control/controlclient/controlclient_test.go b/control/controlclient/controlclient_test.go index 086721eea..7a245cad9 100644 --- a/control/controlclient/controlclient_test.go +++ b/control/controlclient/controlclient_test.go @@ -21,7 +21,7 @@ func fieldsOf(t reflect.Type) (fields []string) { func TestStatusEqual(t *testing.T) { // 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) { t.Errorf("Status.Equal check might be out of sync\nfields: %q\nhandled: %q\n", have, equalHandles) @@ -52,13 +52,13 @@ func TestStatusEqual(t *testing.T) { true, }, { - &Status{State: StateNew}, - &Status{State: StateNew}, + &Status{state: StateNew}, + &Status{state: StateNew}, true, }, { - &Status{State: StateNew}, - &Status{State: StateAuthenticated}, + &Status{state: StateNew}, + &Status{state: StateAuthenticated}, false, }, { diff --git a/control/controlclient/status.go b/control/controlclient/status.go index 294c5dbb2..b5f478449 100644 --- a/control/controlclient/status.go +++ b/control/controlclient/status.go @@ -69,14 +69,18 @@ type Status struct { URL string // interactive URL to visit to finish logging in 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 - // use them. Please don't use these fields. + // use it via the StateForTest accessor. // TODO(apenwarr): Unexport or remove these. - State State - Persist *persist.PersistView // locally persisted configuration + state State } +// 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. func (s *Status) Equal(s2 *Status) bool { if s == nil && s2 == nil { @@ -89,7 +93,7 @@ func (s *Status) Equal(s2 *Status) bool { s.URL == s2.URL && reflect.DeepEqual(s.Persist, s2.Persist) && reflect.DeepEqual(s.NetMap, s2.NetMap) && - s.State == s2.State + s.state == s2.state } func (s Status) String() string { @@ -97,5 +101,5 @@ func (s Status) String() string { if err != nil { panic(err) } - return s.State.String() + " " + string(b) + return s.state.String() + " " + string(b) }