feat(bookmark): 初始化书签服务并配置路由与权限控制
新增书签服务主程序,使用 Gin 框架搭建 HTTP 服务器,并注册书签相关接口处理器。 配置 CORS 中间件以支持跨域请求。服务监听端口为 8081。 feat(user_np): 初始化用户权限服务并注册认证接口 新增用户权限服务主程序,使用 Gin 框架搭建 HTTP 服务器,并注册登录、注册及修改密码等接口处理器。 服务监听端口为 8082。 refactor(config): 重构 OpenAPI 配置文件结构并拆分模块 将原有合并的 OpenAPI 配置文件按功能模块拆分为 bookmark 和 user_np 两个独立目录, 分别管理各自的 server、client 及 API 定义文件,便于后续维护和扩展。 refactor(vfs): 调整虚拟文件系统 API 接口路径与参数定义 更新 VFS API 配置文件,修改部分接口路径及参数结构, 如将文件路径参数由 path 转为 query 参数,并优化响应结构体定义。
This commit is contained in:
129
internal/models/vfs_test.go
Normal file
129
internal/models/vfs_test.go
Normal file
@ -0,0 +1,129 @@
|
||||
package models_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.zzyxyz.com/zzy/zzyxyz_go_api/internal/models"
|
||||
)
|
||||
|
||||
func TestParsePathComponents(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
pathStr string
|
||||
wantParent string
|
||||
wantName string
|
||||
wantNodeType models.VfsNodeType
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "directory path with trailing slash",
|
||||
pathStr: "/home/",
|
||||
wantParent: "/",
|
||||
wantName: "home",
|
||||
wantNodeType: models.VfsNodeTypeDirectory,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "file path without extension",
|
||||
pathStr: "/home",
|
||||
wantParent: "/",
|
||||
wantName: "home",
|
||||
wantNodeType: models.VfsNodeTypeFile,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "file path with extension",
|
||||
pathStr: "/home.txt",
|
||||
wantParent: "/",
|
||||
wantName: "home.txt",
|
||||
wantNodeType: models.VfsNodeTypeFile,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "nested directory path with trailing slash",
|
||||
pathStr: "/home/user/",
|
||||
wantParent: "/home",
|
||||
wantName: "user",
|
||||
wantNodeType: models.VfsNodeTypeDirectory,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "nested file path",
|
||||
pathStr: "/home/user/file.txt",
|
||||
wantParent: "/home/user",
|
||||
wantName: "file.txt",
|
||||
wantNodeType: models.VfsNodeTypeFile,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "deep nested directory path with trailing slash",
|
||||
pathStr: "/home/user/documents/",
|
||||
wantParent: "/home/user",
|
||||
wantName: "documents",
|
||||
wantNodeType: models.VfsNodeTypeDirectory,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "deep nested file path",
|
||||
pathStr: "/home/user/documents/file.txt",
|
||||
wantParent: "/home/user/documents",
|
||||
wantName: "file.txt",
|
||||
wantNodeType: models.VfsNodeTypeFile,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "relative path should error",
|
||||
pathStr: ".",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "relative path should error",
|
||||
pathStr: "home.txt",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "relative path should error",
|
||||
pathStr: "home/user/",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "path with multiple slashes",
|
||||
pathStr: "//home//user//",
|
||||
wantParent: "/home",
|
||||
wantName: "user",
|
||||
wantNodeType: models.VfsNodeTypeDirectory,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "path with multiple slashes and file",
|
||||
pathStr: "//home//user//file.txt",
|
||||
wantParent: "/home/user",
|
||||
wantName: "file.txt",
|
||||
wantNodeType: models.VfsNodeTypeFile,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
parent, name, nodeType, err := models.ParsePathComponents(tt.pathStr)
|
||||
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ParsePathComponents() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
|
||||
if !tt.wantErr {
|
||||
if parent != tt.wantParent {
|
||||
t.Errorf("ParsePathComponents() parent = %v, want %v", parent, tt.wantParent)
|
||||
}
|
||||
if name != tt.wantName {
|
||||
t.Errorf("ParsePathComponents() name = %v, want %v", name, tt.wantName)
|
||||
}
|
||||
if nodeType != tt.wantNodeType {
|
||||
t.Errorf("ParsePathComponents() nodeType = %v, want %v", nodeType, tt.wantNodeType)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user