Skip to content

Commit

Permalink
empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Dec 12, 2021
1 parent e662543 commit d0fc7ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 0 additions & 5 deletions snapshot.go
Expand Up @@ -41,11 +41,6 @@ func (c *Collection) WriteTo(dst io.Writer) (int64, error) {
c.lock.Lock()
defer c.lock.Unlock()

// Check if there's any data to write
if c.fill.Count() == 0 {
return 0, fmt.Errorf("column: unable to write an empty collection")
}

// Create a writer, encoder and a reusable buffer
encoder := c.codec.EncoderFor(dst)
writer := iostream.NewWriter(c.codec.EncoderFor(dst))
Expand Down
22 changes: 17 additions & 5 deletions snapshot_test.go
Expand Up @@ -225,11 +225,23 @@ func TestWriteToFailures(t *testing.T) {
}
}

func TestWriteToEmpty(t *testing.T) {
input := NewCollection()
input.CreateColumn("name", ForString())
_, err := input.WriteTo(bytes.NewBuffer(nil))
assert.Error(t, err)
func TestWriteEmpty(t *testing.T) {
buffer := bytes.NewBuffer(nil)

{ // Write the collection
input := NewCollection()
input.CreateColumn("name", ForString())
_, err := input.WriteTo(buffer)
assert.NoError(t, err)
}

{ // Read the collection back
output := NewCollection()
output.CreateColumn("name", ForString())
_, err := output.ReadFrom(buffer)
assert.NoError(t, err)
assert.Equal(t, 0, output.Count())
}
}

func TestReadFromFailures(t *testing.T) {
Expand Down

0 comments on commit d0fc7ad

Please sign in to comment.