Skip to content

Commit

Permalink
Start empty to avoid returning len > 0 on List()
Browse files Browse the repository at this point in the history
  • Loading branch information
kyhavlov committed Oct 29, 2016
1 parent 4e73a38 commit fcbbf35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion inmem_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
// InmemSnapshotStore implements the SnapshotStore interface and
// retains only the most recent snapshot
type InmemSnapshotStore struct {
latest *InmemSnapshotSink
latest *InmemSnapshotSink
hasSnapshot bool
}

// InmemSnapshotSink implements SnapshotSink in memory
Expand Down Expand Up @@ -49,12 +50,16 @@ func (m *InmemSnapshotStore) Create(version SnapshotVersion, index, term uint64,
ConfigurationIndex: configurationIndex,
}
sink.contents = &bytes.Buffer{}
m.hasSnapshot = true

return sink, nil
}

// List returns the latest snapshot taken
func (m *InmemSnapshotStore) List() ([]*SnapshotMeta, error) {
if !m.hasSnapshot {
return []*SnapshotMeta{}, nil
}
return []*SnapshotMeta{&m.latest.meta}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions inmem_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestInmemSS_CreateSnapshot(t *testing.T) {
if err != nil {
t.Fatalf("err: %v", err)
}
if len(snaps) != 1 {
t.Fatalf("should always be 1 snapshot: %v", snaps)
if len(snaps) != 0 {
t.Fatalf("did not expect any snapshots: %v", snaps)
}

// Create a new sink
Expand Down

0 comments on commit fcbbf35

Please sign in to comment.