Add tests for RenameFile
This commit is contained in:
parent
df6baa7116
commit
391b745584
tensorflow/c/experimental/filesystem/plugins/gcs
@ -988,8 +988,10 @@ static void RenameObject(const TF_Filesystem* filesystem,
|
||||
void RenameFile(const TF_Filesystem* filesystem, const char* src,
|
||||
const char* dst, TF_Status* status) {
|
||||
if (!IsDirectory(filesystem, src, status)) {
|
||||
if (TF_GetCode(status) == TF_FAILED_PRECONDITION)
|
||||
if (TF_GetCode(status) == TF_FAILED_PRECONDITION) {
|
||||
TF_SetStatus(status, TF_OK, "");
|
||||
RenameObject(filesystem, src, dst, status);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1095,6 +1097,18 @@ void Stat(const TF_Filesystem* filesystem, const char* path,
|
||||
}
|
||||
}
|
||||
|
||||
int64_t GetFileSize(const TF_Filesystem* filesystem, const char* path,
|
||||
TF_Status* status) {
|
||||
// Only validate the name.
|
||||
std::string bucket, object;
|
||||
ParseGCSPath(path, false, &bucket, &object, status);
|
||||
if (TF_GetCode(status) != TF_OK) return -1;
|
||||
|
||||
TF_FileStatistics stat;
|
||||
Stat(filesystem, path, &stat, status);
|
||||
return stat.length;
|
||||
}
|
||||
|
||||
static char* TranslateName(const TF_Filesystem* filesystem, const char* uri) {
|
||||
return strdup(uri);
|
||||
}
|
||||
|
@ -494,6 +494,42 @@ TEST_F(GCSFilesystemTest, StatFile) {
|
||||
EXPECT_FALSE(stat.is_directory);
|
||||
}
|
||||
|
||||
TEST_F(GCSFilesystemTest, RenameFile) {
|
||||
tf_gcs_filesystem::Init(filesystem_, status_);
|
||||
ASSERT_TF_OK(status_);
|
||||
const std::string src = GetURIForPath("RenameFileSrc");
|
||||
const std::string dst = GetURIForPath("RenameFileDst");
|
||||
WriteString(src, "test");
|
||||
ASSERT_TF_OK(status_);
|
||||
|
||||
tf_gcs_filesystem::RenameFile(filesystem_, src.c_str(), dst.c_str(), status_);
|
||||
EXPECT_TF_OK(status_);
|
||||
auto result = ReadAll(dst);
|
||||
EXPECT_TF_OK(status_);
|
||||
EXPECT_EQ("test", result);
|
||||
}
|
||||
|
||||
TEST_F(GCSFilesystemTest, RenameFileOverwrite) {
|
||||
tf_gcs_filesystem::Init(filesystem_, status_);
|
||||
ASSERT_TF_OK(status_);
|
||||
const std::string src = GetURIForPath("RenameFileOverwriteSrc");
|
||||
const std::string dst = GetURIForPath("RenameFileOverwriteDst");
|
||||
|
||||
WriteString(src, "test_old");
|
||||
ASSERT_TF_OK(status_);
|
||||
WriteString(dst, "test_new");
|
||||
ASSERT_TF_OK(status_);
|
||||
|
||||
tf_gcs_filesystem::PathExists(filesystem_, dst.c_str(), status_);
|
||||
EXPECT_TF_OK(status_);
|
||||
tf_gcs_filesystem::RenameFile(filesystem_, src.c_str(), dst.c_str(), status_);
|
||||
EXPECT_TF_OK(status_);
|
||||
|
||||
auto result = ReadAll(dst);
|
||||
EXPECT_TF_OK(status_);
|
||||
EXPECT_EQ("test_old", result);
|
||||
}
|
||||
|
||||
// These tests below are ported from
|
||||
// `//tensorflow/core/platform/cloud:gcs_file_system_test`
|
||||
TEST_F(GCSFilesystemTest, NewRandomAccessFile_NoBlockCache) {
|
||||
|
Loading…
Reference in New Issue
Block a user