Skip to content

Commit

Permalink
Merge pull request #10148 from jingyih/add_unit_test_for_snapshot_fil…
Browse files Browse the repository at this point in the history
…e_integrity

clientv3: add test for snapshot status
  • Loading branch information
jingyih authored Oct 4, 2018
2 parents 2654de8 + 87beb83 commit 6976819
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Binary file added clientv3/snapshot/testdata/corrupted_backup.db
Binary file not shown.
26 changes: 26 additions & 0 deletions clientv3/snapshot/v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -161,6 +162,31 @@ func TestSnapshotFilePermissions(t *testing.T) {
}
}

// TestCorruptedBackupFileCheck tests if we can correctly identify a corrupted backup file.
func TestCorruptedBackupFileCheck(t *testing.T) {
dbPath := "testdata/corrupted_backup.db"
if _, err := os.Stat(dbPath); err != nil {
t.Fatalf("test file [%s] does not exist: %v", dbPath, err)
}

sp := NewV3(zap.NewExample())
_, err := sp.Status(dbPath)
expectedErrKeywords := "snapshot file integrity check failed"
/* example error message:
snapshot file integrity check failed. 2 errors found.
page 3: already freed
page 4: unreachable unfreed
*/
if err == nil {
t.Error("expected error due to corrupted snapshot file, got no error")
}
if !strings.Contains(err.Error(), expectedErrKeywords) {
t.Errorf("expected error message to contain the following keywords:\n%s\n"+
"actual error message:\n%s",
expectedErrKeywords, err.Error())
}
}

type kv struct {
k, v string
}
Expand Down

0 comments on commit 6976819

Please sign in to comment.