@@ -33,7 +33,8 @@ TEST(LocalFileTest, TestReadWriteEmptyContent) {
3333 if (dir.Exists ().ok ()) {
3434 ASSERT_TRUE (dir.Delete ().ok ());
3535 }
36- ASSERT_TRUE (dir.Mkdir ().ok ());
36+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
37+ ASSERT_TRUE (success);
3738 std::string path = test_root + " /test.txt" ;
3839 LocalFile file = LocalFile (path);
3940 if (file.Exists ().ok ()) {
@@ -69,7 +70,8 @@ TEST(LocalFileTest, TestSimple) {
6970 if (dir.Exists ().ok ()) {
7071 ASSERT_OK (dir.Delete ());
7172 }
72- ASSERT_OK (dir.Mkdir ());
73+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
74+ ASSERT_TRUE (success);
7375 std::string path = test_root + " /test.txt" ;
7476 LocalFile file = LocalFile (path);
7577 if (file.Exists ().ok ()) {
@@ -127,21 +129,27 @@ TEST(LocalFileTest, TestSimple) {
127129 ASSERT_EQ (strcmp (str_read, " test_data" ), 0 );
128130 }
129131
132+ // dir already exists
133+ ASSERT_OK_AND_ASSIGN (success, dir.Mkdir ());
134+ ASSERT_FALSE (success);
135+
130136 ASSERT_OK (file2.Delete ());
131137 ASSERT_FALSE (file2.Exists ().value ());
132138}
133139
134140TEST (LocalFileTest, TestUsage) {
135- std::string test_root = " tmp/ local_file_test_usage" ;
141+ std::string test_root = " local_file_test_usage" ;
136142 LocalFile dir = LocalFile (test_root);
137- ASSERT_OK (dir.Mkdir ());
143+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
144+ ASSERT_TRUE (success);
138145 std::vector<std::string> file_list;
139146 ASSERT_OK (dir.List (&file_list));
140- std::string path_deep_dir = test_root + " /tmp2/tmp3 " ;
147+ std::string path_deep_dir = test_root + " /tmp2" ;
141148 LocalFile deep_dir = LocalFile (path_deep_dir);
142- ASSERT_OK (deep_dir.Mkdir ());
149+ ASSERT_OK_AND_ASSIGN (success, deep_dir.Mkdir ());
150+ ASSERT_TRUE (success);
143151 LocalFile parent_deep_dir = deep_dir.GetParentFile ();
144- ASSERT_EQ (parent_deep_dir.GetAbsolutePath (), test_root + " /tmp2 " );
152+ ASSERT_EQ (parent_deep_dir.GetAbsolutePath (), test_root);
145153 ASSERT_OK (deep_dir.Delete ());
146154 ASSERT_OK (parent_deep_dir.Delete ());
147155 ASSERT_OK (dir.Delete ());
@@ -155,7 +163,8 @@ TEST(LocalFileTest, TestOpenFile) {
155163 if (dir.Exists ().ok ()) {
156164 ASSERT_OK (dir.Delete ());
157165 }
158- ASSERT_OK (dir.Mkdir ());
166+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
167+ ASSERT_TRUE (success);
159168 std::string path = test_root + " /test.txt" ;
160169 LocalFile file = LocalFile (path);
161170 if (file.Exists ().ok ()) {
@@ -167,20 +176,49 @@ TEST(LocalFileTest, TestOpenFile) {
167176 ASSERT_NOK_WITH_MSG (file.OpenFile (/* is_read_file=*/ true ), " file not exist" );
168177 ASSERT_NOK_WITH_MSG (dir.OpenFile (/* is_read_file=*/ true ), " cannot open a directory" );
169178
170- std::string path2 = test_root + " /foo/test.txt" ;
171- LocalFile file2 = LocalFile (path2);
172- ASSERT_OK (file2.OpenFile (/* is_read_file=*/ false ));
173-
174179 std::string path3 = " test.txt" ;
175180 LocalFile file3 = LocalFile (path3);
176181 ASSERT_OK (file3.OpenFile (/* is_read_file=*/ false ));
177182 ASSERT_OK_AND_ASSIGN (int64_t modify_time, file3.LastModifiedTimeMs ());
178183 ASSERT_GE (modify_time, -1 );
179184
180185 LocalFile dir2 = LocalFile (" /" );
181- ASSERT_NOK_WITH_MSG (dir2.Mkdir (), " directory '/' already exist" );
186+ ASSERT_OK_AND_ASSIGN (success, dir2.Mkdir ());
187+ ASSERT_FALSE (success);
182188 LocalFile dir3 = LocalFile (test_root + " /" );
183- ASSERT_NOK_WITH_MSG (dir3.Mkdir (), " already exist" );
189+ ASSERT_OK_AND_ASSIGN (success, dir3.Mkdir ());
190+ ASSERT_FALSE (success);
191+ }
192+
193+ TEST (LocalFileTest, TestMkdir) {
194+ auto test_root_dir = UniqueTestDirectory::Create ();
195+ ASSERT_TRUE (test_root_dir);
196+ std::string test_root = test_root_dir->Str ();
197+ {
198+ LocalFile dir = LocalFile (test_root + " tmp/local/f/1" );
199+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
200+ ASSERT_FALSE (success);
201+ }
202+ {
203+ LocalFile dir = LocalFile (test_root + " tmp1" );
204+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
205+ ASSERT_TRUE (success);
206+ }
207+ {
208+ LocalFile dir = LocalFile (test_root + " tmp1/f2/" );
209+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
210+ ASSERT_TRUE (success);
211+ }
212+ {
213+ LocalFile dir = LocalFile (" /" );
214+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
215+ ASSERT_FALSE (success);
216+ }
217+ {
218+ LocalFile dir = LocalFile (" " );
219+ ASSERT_OK_AND_ASSIGN (bool success, dir.Mkdir ());
220+ ASSERT_FALSE (success);
221+ }
184222}
185223
186224} // namespace paimon::test
0 commit comments