From 724915c0e9a8edfed584317a1764ab09d5be066a Mon Sep 17 00:00:00 2001 From: aeddi Date: Thu, 6 Jun 2019 17:03:47 +0200 Subject: [PATCH] fix: fix Difference with empty log --- log/log.go | 12 ++++++------ test/entry_io_test.go | 4 ---- test/utils.go | 4 ++++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/log/log.go b/log/log.go index 4cc3972..c2bc259 100644 --- a/log/log.go +++ b/log/log.go @@ -2,9 +2,7 @@ package log import ( "bytes" - "encoding/hex" "encoding/json" - "fmt" "sort" "strconv" "strings" @@ -386,10 +384,12 @@ func (l *Log) Join(otherLog *Log, size int) (*Log, error) { } func Difference(logA, logB *Log) *entry.OrderedMap { - if logA == nil || logA.Entries == nil || len(logA.Entries.Keys()) == 0 { - return logB.Entries - } else if logB == nil || logB.Entries == nil || len(logB.Entries.Keys()) == 0 { - return logA.Entries + if logA == nil || logA.Entries == nil || logA.Entries.Len() == 0 || logB == nil { + return entry.NewOrderedMap() + } + + if logB.Entries == nil { + logB.Entries = entry.NewOrderedMap() } stack := logA.heads.Keys() diff --git a/test/entry_io_test.go b/test/entry_io_test.go index 3f792da..7a2c38d 100644 --- a/test/entry_io_test.go +++ b/test/entry_io_test.go @@ -19,10 +19,6 @@ import ( . "github.com/smartystreets/goconvey/convey" ) -func intPtr(val int) *int { - return &val -} - func TestEntryPersistence(t *testing.T) { _, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() diff --git a/test/utils.go b/test/utils.go index 199ea62..b502db5 100644 --- a/test/utils.go +++ b/test/utils.go @@ -14,3 +14,7 @@ func minInt(a, b int) int { } return b } + +func intPtr(val int) *int { + return &val +}