From 24681c81c09022f584a57006f2534b5f74723414 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 30 六月 2026 09:27:31 +0800
Subject: [PATCH] 初始化项目

---
 yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java |   65 ++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java b/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java
index 6bc8c7b..f7681f7 100644
--- a/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java
+++ b/yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/framework/file/core/local/LocalFileClientTest.java
@@ -1,15 +1,71 @@
 package cn.iocoder.yudao.module.infra.framework.file.core.local;
 
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.resource.ResourceUtil;
 import cn.hutool.core.util.IdUtil;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
 import cn.iocoder.yudao.module.infra.framework.file.core.client.local.LocalFileClient;
 import cn.iocoder.yudao.module.infra.framework.file.core.client.local.LocalFileClientConfig;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
 
 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
+import static org.junit.jupiter.api.Assertions.*;
 
 public class LocalFileClientTest {
+
+    @TempDir
+    public File tempDir;
+
+    @Test
+    public void testUpload_success() {
+        // 鍑嗗鍙傛暟
+        LocalFileClient client = createClient();
+        byte[] content = "test".getBytes(StandardCharsets.UTF_8);
+        String path = "avatar/test.txt";
+
+        // 璋冪敤
+        String url = client.upload(content, path, "text/plain");
+
+        // 鏂█
+        assertEquals("http://127.0.0.1:48080/admin-api/infra/file/0/get/avatar/test.txt", url);
+        assertArrayEquals(content, FileUtil.readBytes(new File(tempDir, path)));
+        assertArrayEquals(content, client.getContent(path));
+
+        // 鍒犻櫎
+        client.delete(path);
+        assertFalse(FileUtil.exist(new File(tempDir, path)));
+    }
+
+    @Test
+    public void testUpload_encodeUrlPath() {
+        // 鍑嗗鍙傛暟
+        LocalFileClient client = createClient();
+        byte[] content = "test".getBytes(StandardCharsets.UTF_8);
+        String path = "avatar/涓枃 100%+鏂囦欢.txt";
+
+        // 璋冪敤
+        String url = client.upload(content, path, "text/plain");
+
+        // 鏂█
+        assertEquals("http://127.0.0.1:48080/admin-api/infra/file/0/get/avatar/%E4%B8%AD%E6%96%87%20100%25+%E6%96%87%E4%BB%B6.txt", url);
+        assertArrayEquals(content, FileUtil.readBytes(new File(tempDir, path)));
+    }
+
+    @Test
+    public void testUpload_pathInvalid() {
+        // 鍑嗗鍙傛暟
+        LocalFileClient client = createClient();
+        byte[] content = "test".getBytes(StandardCharsets.UTF_8);
+
+        // 璋冪敤锛屽苟鏂█寮傚父
+        assertThrows(ServiceException.class, () -> client.upload(content, "../test.txt", "text/plain"));
+        assertFalse(FileUtil.exist(new File(tempDir.getParentFile(), "test.txt")));
+    }
 
     @Test
     @Disabled
@@ -42,4 +98,13 @@
         System.out.println();
     }
 
+    private LocalFileClient createClient() {
+        LocalFileClientConfig config = new LocalFileClientConfig();
+        config.setDomain("http://127.0.0.1:48080");
+        config.setBasePath(tempDir.getAbsolutePath());
+        LocalFileClient client = new LocalFileClient(0L, config);
+        client.init();
+        return client;
+    }
+
 }

--
Gitblit v1.9.3