Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clientv3: add test for snapshot status #10148

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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