package wal import ( "os" "strings" "testing" ) func TestDirFsyncSuccess(t *testing.T) { dir := t.TempDir() if err := dirFsync(dir); err != nil { t.Errorf("dirFsync on valid dir: %v", err) } } func TestDirFsyncNonExistentDir(t *testing.T) { err := dirFsync("/nonexistent/path/that/should/not/exist") if err == nil { t.Fatal("expected error on non-existent dir") } if !strings.Contains(err.Error(), "open dir") { t.Errorf("error should mention 'open dir', got: %v", err) } } func TestDirFsyncNotADirectory(t *testing.T) { dir := t.TempDir() filePath := dir + "/notadir" if err := os.WriteFile(filePath, []byte("x"), 0o644); err != nil { t.Fatalf("WriteFile: %v", err) } err := dirFsync(filePath) if err == nil { t.Fatal("expected error when fsyncing a file as dir") } if !strings.Contains(err.Error(), "not a directory") { t.Errorf("error should mention 'not a directory', got: %v", err) } }