Skip to content

Commit cb6c822

Browse files
committed
feat:添加测试用例
添加了agent文件工具的测试用例
1 parent 3298816 commit cb6c822

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.dongtai.iast.agent.util;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class ByteUtilsTest {
7+
@Test
8+
public void testFormatByteSize() {
9+
// 测试formatByteSize方法是否返回正确的格式化字符串
10+
11+
// 测试不足1KB的情况
12+
Assert.assertEquals("0B", ByteUtils.formatByteSize(0));
13+
Assert.assertEquals("1023B", ByteUtils.formatByteSize(1023));
14+
15+
// 测试不足1MB的情况
16+
Assert.assertEquals("1KB", ByteUtils.formatByteSize(1024));
17+
Assert. assertEquals("1.5KB", ByteUtils.formatByteSize(1536));
18+
Assert.assertEquals("1023.5KB", ByteUtils.formatByteSize(1023 * 1024 + 512));
19+
20+
// 测试不足1GB的情况
21+
Assert.assertEquals("1MB", ByteUtils.formatByteSize(1024 * 1024));
22+
Assert.assertEquals("1.5MB", ByteUtils.formatByteSize(1536 * 1024));
23+
Assert.assertEquals("1023.5MB", ByteUtils.formatByteSize(1023 * 1024 * 1024 + 512 * 1024));
24+
25+
// 测试不足1TB的情况
26+
Assert.assertEquals("1GB", ByteUtils.formatByteSize(1024 * 1024 * 1024));
27+
Assert.assertEquals("1.5GB", ByteUtils.formatByteSize(1536 * 1024 * 1024));
28+
Assert.assertEquals("1023.5GB", ByteUtils.formatByteSize(1023L * 1024 * 1024 * 1024 + 512 * 1024 * 1024));
29+
30+
// 测试不足1PB的情况
31+
Assert.assertEquals("1TB", ByteUtils.formatByteSize(1024L * 1024 * 1024 * 1024));
32+
Assert.assertEquals("1.5TB", ByteUtils.formatByteSize(1536L * 1024 * 1024 * 1024));
33+
Assert.assertEquals("1023.5TB", ByteUtils.formatByteSize(1023L * 1024 * 1024 * 1024 * 1024 + 512L * 1024 * 1024 * 1024));
34+
35+
// 测试超过1PB的情况
36+
Assert.assertEquals(">PB", ByteUtils.formatByteSize(Long.MAX_VALUE));
37+
}
38+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.dongtai.iast.agent.util;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
import java.io.IOException;
7+
8+
public class FileUtilsTest {
9+
@Test
10+
public void testGetResourceToFile() {
11+
// 测试getResourceToFile方法是否能正确地将资源文件复制到指定的文件路径
12+
13+
//获取临时文件路径
14+
String tempDirectoryPath = org.apache.commons.io.FileUtils.getTempDirectoryPath();
15+
16+
String resourceName = "iast.properties.example"; // 假设存在名为test_resource.txt的资源文件
17+
String fileName = tempDirectoryPath + "test.example"; // 替换为实际的目标文件路径
18+
19+
boolean result = false;
20+
try {
21+
result = FileUtils.getResourceToFile(resourceName, fileName);
22+
} catch (IOException e) {
23+
throw new RuntimeException(e);
24+
}
25+
26+
Assert.assertTrue(result); // 验证复制操作是否成功
27+
28+
// 验证目标文件是否存在
29+
java.io.File targetFile = new java.io.File(fileName);
30+
Assert.assertTrue(targetFile.exists());
31+
32+
// 清理测试产生的文件
33+
targetFile.delete();
34+
}
35+
}

0 commit comments

Comments
 (0)