Skip to content

Commit

Permalink
fix: test fixes for windows file restore
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Aug 27, 2024
1 parent cc173aa commit 7b0f9e9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/orchestrator/repo/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"io/ioutil"
"os"
"path"
"runtime"
"slices"
"strings"
Expand Down Expand Up @@ -90,8 +91,8 @@ func TestBackup(t *testing.T) {
func TestRestore(t *testing.T) {
t.Parallel()

testFile := t.TempDir() + "/test.txt"
if err := ioutil.WriteFile(testFile, []byte("test"), 0644); err != nil {
testFile := path.Join(t.TempDir(), "test.txt")
if err := ioutil.WriteFile(testFile, []byte("lorum ipsum"), 0644); err != nil {
t.Fatalf("failed to create test file: %v", err)
}

Expand Down Expand Up @@ -124,7 +125,8 @@ func TestRestore(t *testing.T) {

// Restore the file
restoreDir := t.TempDir()
restoreSummary, err := orchestrator.Restore(context.Background(), summary.SnapshotId, testFile, restoreDir, nil)
snapshotPath := strings.ReplaceAll(testFile, ":", "") // remove the colon from the windows path e.g. C:\test.txt -> C\test.txt
restoreSummary, err := orchestrator.Restore(context.Background(), summary.SnapshotId, snapshotPath, restoreDir, nil)
if err != nil {
t.Fatalf("restore error: %v", err)
}
Expand All @@ -135,16 +137,20 @@ func TestRestore(t *testing.T) {
t.Fatalf("expected 1 total file, got %d", restoreSummary.TotalFiles)
}

if runtime.GOOS == "windows" {
return
}

// Check the restored file
restoredFile := restoreDir + "/test.txt"
restoredFile := path.Join(restoreDir, "test.txt")
if _, err := os.Stat(restoredFile); err != nil {
t.Fatalf("failed to stat restored file: %v", err)
}
restoredData, err := ioutil.ReadFile(restoredFile)
if err != nil {
t.Fatalf("failed to read restored file: %v", err)
}
if string(restoredData) != "test" {
if string(restoredData) != "lorum ipsum" {
t.Fatalf("expected 'test', got '%s'", restoredData)
}
}
Expand Down

0 comments on commit 7b0f9e9

Please sign in to comment.