Browse Source

wal: test save empty state

Xiang Li 11 years ago
parent
commit
6f06923e96
1 changed files with 15 additions and 0 deletions
  1. 15 0
      wal/wal_test.go

+ 15 - 0
wal/wal_test.go

@@ -17,6 +17,7 @@ limitations under the License.
 package wal
 
 import (
+	"bytes"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -322,3 +323,17 @@ func TestRecoverAfterCut(t *testing.T) {
 		}
 	}
 }
+
+func TestSaveEmpty(t *testing.T) {
+	var buf bytes.Buffer
+	var est raftpb.State
+	w := WAL{
+		encoder: newEncoder(&buf, 0),
+	}
+	if err := w.SaveState(&est); err != nil {
+		t.Errorf("err = %v, want nil", err)
+	}
+	if len(buf.Bytes()) != 0 {
+		t.Errorf("buf.Bytes = %d, want 0", len(buf.Bytes()))
+	}
+}