Merge pull request #10148 from jingyih/add_unit_test_for_snapshot_file_integrity

clientv3: add test for snapshot status
release-3.4
Jingyi Hu 2018-10-03 19:52:19 -07:00 committed by GitHub
commit 6976819792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

Binary file not shown.

View File

@ -21,6 +21,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"
"testing"
"time"
@ -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
}