From 5b63199f46acfc1b54602376bf3cf10b3ac83d72 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 30 Sep 2022 10:20:51 +0200 Subject: [PATCH] e2e storage: add Rename to PodIO This is useful for atomic file creation: first create a temporary file, then rename it. --- test/e2e/storage/drivers/csi-test/mock/service/service.go | 7 +++++++ test/e2e/storage/drivers/proxy/io.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/test/e2e/storage/drivers/csi-test/mock/service/service.go b/test/e2e/storage/drivers/csi-test/mock/service/service.go index c486f9aa2a2..1c96ddc2982 100644 --- a/test/e2e/storage/drivers/csi-test/mock/service/service.go +++ b/test/e2e/storage/drivers/csi-test/mock/service/service.go @@ -71,6 +71,9 @@ type DirIO interface { Mkdir(path string) error // RemoveAll removes the path and everything contained inside it. It's not an error if the path does not exist. RemoveAll(path string) error + // Rename changes the name of a file or directory. The parent directory + // of newPath must exist. + Rename(oldPath, newPath string) error } type OSDirIO struct{} @@ -97,6 +100,10 @@ func (o OSDirIO) RemoveAll(path string) error { return os.RemoveAll(path) } +func (o OSDirIO) Rename(oldPath, newPath string) error { + return os.Rename(oldPath, newPath) +} + // Service is the CSI Mock service provider. type Service interface { csi.ControllerServer diff --git a/test/e2e/storage/drivers/proxy/io.go b/test/e2e/storage/drivers/proxy/io.go index 296ed882b11..8e58518384b 100644 --- a/test/e2e/storage/drivers/proxy/io.go +++ b/test/e2e/storage/drivers/proxy/io.go @@ -70,6 +70,14 @@ func (p PodDirIO) CreateFile(path string, content io.Reader) error { return nil } +func (p PodDirIO) Rename(oldPath, newPath string) error { + _, stderr, err := p.execute([]string{"mv", oldPath, newPath}, nil) + if err != nil { + return fmt.Errorf("rename %q -> %q: stderr=%q, %v", oldPath, newPath, stderr, err) + } + return nil +} + func (p PodDirIO) RemoveAll(path string) error { _, stderr, err := p.execute([]string{"rm", "-rf", path}, nil) if err != nil {