Skip to content

Commit

Permalink
refactored testing, removed HttpMessage.ToError()
Browse files Browse the repository at this point in the history
  • Loading branch information
ivcosla committed May 20, 2019
1 parent bebafeb commit 43197f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
7 changes: 0 additions & 7 deletions pkg/messaging-discovery/client/http_message.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"errors"
"fmt"
"net/http"
)
Expand All @@ -21,9 +20,3 @@ type HTTPMessage struct {
func (h HTTPMessage) String() string {
return fmt.Sprintf("status code: %d. message: %s", h.Code, h.Message)
}

// ToError returns an error representing the httpMessage for error comparisons, this is preferred for this type instead
// of implementing error
func (h HTTPMessage) ToError() error {
return errors.New(h.String())
}
37 changes: 18 additions & 19 deletions pkg/messaging-discovery/client/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,26 @@ func (m *mockClient) UpdateEntry(ctx context.Context, sk cipher.SecKey, e *Entry

for {
err = m.SetEntry(ctx, e)
if err == nil {
return nil
}
if err != ErrValidationWrongSequence {
e.Sequence--
return err
}
rE, entryErr := m.Entry(ctx, e.Static)
if entryErr != nil {
return err
}
if rE.Timestamp > e.Timestamp { // If there is a more up to date entry drop update
e.Sequence = rE.Sequence
return nil
}
e.Sequence = rE.Sequence + 1
err := e.Sign(sk)
if err != nil {
if err != ErrValidationWrongSequence {
e.Sequence--
return err
}
rE, entryErr := m.Entry(ctx, e.Static)
if entryErr != nil {
return err
}
if rE.Timestamp > e.Timestamp { // If there is a more up to date entry drop update
e.Sequence = rE.Sequence
return nil
}
e.Sequence = rE.Sequence + 1
err := e.Sign(sk)
if err != nil {
return err
}
continue
return err
}
return nil
}
}

Expand Down

0 comments on commit 43197f9

Please sign in to comment.