Skip to content
Snippets Groups Projects
Commit 6665bb04 authored by benjamin's avatar benjamin
Browse files

improved test documentation

parent b711c44f
No related branches found
No related tags found
5 merge requests!622Add notifications system with sync,!620Account Sychronization First Pass,!618Make it so that transaction log can run without a remote to write to, and add...,!617Project/haven beta,!523Draft: Account Synchronization Over Remote Storage
...@@ -15,6 +15,7 @@ func TestManager_SetMaxState(t *testing.T) { ...@@ -15,6 +15,7 @@ func TestManager_SetMaxState(t *testing.T) {
comms.reset() comms.reset()
// add notification registrations
for i := Mute; i <= Push; i++ { for i := Mute; i <= Push; i++ {
for x := 0; x < int(i)+1; x++ { for x := 0; x < int(i)+1; x++ {
nid := id.NewIdFromUInt(uint64(int(i)*100+x), id.User, t) nid := id.NewIdFromUInt(uint64(int(i)*100+x), id.User, t)
...@@ -24,15 +25,18 @@ func TestManager_SetMaxState(t *testing.T) { ...@@ -24,15 +25,18 @@ func TestManager_SetMaxState(t *testing.T) {
} }
} }
// test Push -> Mute
if err := m.SetMaxState(Mute); err != nil { if err := m.SetMaxState(Mute); err != nil {
t.Fatalf("errored in setMaxState: %+v", err) t.Fatalf("errored in setMaxState: %+v", err)
} }
// should unregister all 3 push registrations
unReg := comms.receivedMessage.(*pb.UnregisterTrackedIdRequest) unReg := comms.receivedMessage.(*pb.UnregisterTrackedIdRequest)
if len(unReg.Request.TrackedIntermediaryID) != expectedLen { if len(unReg.Request.TrackedIntermediaryID) != expectedLen {
t.Errorf("wrong number of ids unregistered") t.Errorf("wrong number of ids unregistered")
} }
// check that the internal data is at the right values
if mInternal.maxState != Mute { if mInternal.maxState != Mute {
t.Errorf("max state at wrong state internally") t.Errorf("max state at wrong state internally")
} }
...@@ -41,13 +45,19 @@ func TestManager_SetMaxState(t *testing.T) { ...@@ -41,13 +45,19 @@ func TestManager_SetMaxState(t *testing.T) {
t.Errorf("max state at wrong state in ekv") t.Errorf("max state at wrong state in ekv")
} }
// test push -> whenOpen
comms.reset() comms.reset()
if err := m.SetMaxState(WhenOpen); err != nil { if err := m.SetMaxState(WhenOpen); err != nil {
t.Fatalf("errored in setMaxState: %+v", err) t.Fatalf("errored in setMaxState: %+v", err)
} }
// no messages should have been sent because we were not
// moving into or out of the push state
if comms.receivedMessage != nil { if comms.receivedMessage != nil {
t.Errorf("message sent when it shouldnt be!") t.Errorf("message sent when it shouldnt be!")
} }
// check that the internal data is at the right values
if mInternal.maxState != WhenOpen { if mInternal.maxState != WhenOpen {
t.Errorf("max state at wrong state internally") t.Errorf("max state at wrong state internally")
} }
...@@ -55,16 +65,21 @@ func TestManager_SetMaxState(t *testing.T) { ...@@ -55,16 +65,21 @@ func TestManager_SetMaxState(t *testing.T) {
if loadMaxState(mInternal, t) != WhenOpen { if loadMaxState(mInternal, t) != WhenOpen {
t.Errorf("max state at wrong state in ekv") t.Errorf("max state at wrong state in ekv")
} }
// test WhenOpen -> Push
comms.reset() comms.reset()
if err := m.SetMaxState(Push); err != nil { if err := m.SetMaxState(Push); err != nil {
t.Fatalf("errored in setMaxState: %+v", err) t.Fatalf("errored in setMaxState: %+v", err)
} }
// test that the correct comm was sent, registration of
// 3 push notifications
reg := comms.receivedMessage.(*pb.RegisterTrackedIdRequest) reg := comms.receivedMessage.(*pb.RegisterTrackedIdRequest)
if len(reg.Request.TrackedIntermediaryID) != expectedLen { if len(reg.Request.TrackedIntermediaryID) != expectedLen {
t.Errorf("wrong number of ids unregistered") t.Errorf("wrong number of ids unregistered")
} }
// check that the internal data is at the right values
if mInternal.maxState != Push { if mInternal.maxState != Push {
t.Errorf("max state at wrong state internally") t.Errorf("max state at wrong state internally")
} }
...@@ -78,6 +93,8 @@ func TestManager_GetMaxState(t *testing.T) { ...@@ -78,6 +93,8 @@ func TestManager_GetMaxState(t *testing.T) {
m, _, _ := buildTestingManager(t) m, _, _ := buildTestingManager(t)
mInternal := m.(*manager) mInternal := m.(*manager)
// set to every value and get that value and see if the
// correct result returns
for i := Mute; i <= Push; i++ { for i := Mute; i <= Push; i++ {
mInternal.maxState = i mInternal.maxState = i
got := m.GetMaxState() got := m.GetMaxState()
...@@ -87,6 +104,7 @@ func TestManager_GetMaxState(t *testing.T) { ...@@ -87,6 +104,7 @@ func TestManager_GetMaxState(t *testing.T) {
} }
} }
// gets the max state from the ekv and unmarshals it for testing
func loadMaxState(m *manager, t *testing.T) NotificationState { func loadMaxState(m *manager, t *testing.T) NotificationState {
obj, err := m.remote.Get(maxStateKey, maxStateKetVersion) obj, err := m.remote.Get(maxStateKey, maxStateKetVersion)
if err != nil { if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment