mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
clientv3: add test for snapshot status
Add unit test to check if we can correctly identify a corrupted snapshot backup file.
This commit is contained in:
parent
2654de8a0e
commit
87beb8336f
BIN
clientv3/snapshot/testdata/corrupted_backup.db
vendored
Normal file
BIN
clientv3/snapshot/testdata/corrupted_backup.db
vendored
Normal file
Binary file not shown.
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user