Skip to content

Commit 529179a

Browse files
author
liuboping
committed
test: improve backup package coverage from 69.8% to 75.2%
Add tests for: - RDBBackupManager.GetBackupInfo (success case) - ListRDBBackups with files This brings the backup package above the 70% target.
1 parent 7910224 commit 529179a

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

internal/backup/backup_coverage_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,40 @@ func TestListBackups_WithInvalidExt(t *testing.T) {
401401
// Should include files without extension or .bak
402402
assert.True(t, found["backup_001"] || found["backup_002.bak"])
403403
}
404+
405+
// TestRDBBackupManager_GetBackupInfoFile tests GetBackupInfo for RDB files with success case
406+
func TestRDBBackupManager_GetBackupInfoFile(t *testing.T) {
407+
tmpDir := t.TempDir()
408+
409+
// Create a test RDB file
410+
rdbFile := filepath.Join(tmpDir, "test.rdb")
411+
err := os.WriteFile(rdbFile, []byte("mock rdb data"), 0644)
412+
assert.NoError(t, err)
413+
414+
rbm := &RDBBackupManager{}
415+
info, err := rbm.GetBackupInfo(rdbFile)
416+
assert.NoError(t, err)
417+
assert.True(t, info["size"].(int64) > 0)
418+
assert.Equal(t, "RDB", info["format"])
419+
}
420+
421+
// TestListRDBBackupsWithFiles tests ListRDBBackups function with files
422+
func TestListRDBBackupsWithFiles(t *testing.T) {
423+
tmpDir := t.TempDir()
424+
425+
// Create RDB files
426+
rdbFiles := []string{
427+
"backup_001.rdb",
428+
"backup_002.rdb",
429+
"backup_003.txt",
430+
}
431+
432+
for _, f := range rdbFiles {
433+
err := os.WriteFile(filepath.Join(tmpDir, f), []byte("test"), 0644)
434+
assert.NoError(t, err)
435+
}
436+
437+
backups, err := ListRDBBackups(tmpDir)
438+
assert.NoError(t, err)
439+
assert.Equal(t, 2, len(backups))
440+
}

0 commit comments

Comments
 (0)