Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hexbee
Cloudreve
提交
588514b4
C
Cloudreve
项目概览
hexbee
/
Cloudreve
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cloudreve
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
588514b4
编写于
1月 22, 2020
作者:
H
HFO4
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test: get filesystem from callback context
上级
8672042d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
125 addition
and
1 deletion
+125
-1
models/policy.go
models/policy.go
+0
-1
models/policy_test.go
models/policy_test.go
+35
-0
pkg/filesystem/filesystem_test.go
pkg/filesystem/filesystem_test.go
+90
-0
未找到文件。
models/policy.go
浏览文件 @
588514b4
...
...
@@ -212,7 +212,6 @@ func (policy *Policy) GetUploadURL() string {
}
// UpdateAccessKey 更新 AccessKey
// TODO 测试
func
(
policy
*
Policy
)
UpdateAccessKey
(
key
string
)
error
{
policy
.
AccessKey
=
key
err
:=
DB
.
Save
(
policy
)
.
Error
...
...
models/policy_test.go
浏览文件 @
588514b4
...
...
@@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/DATA-DOG/go-sqlmock"
"github.com/HFO4/cloudreve/pkg/cache"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
"strconv"
"testing"
...
...
@@ -196,3 +197,37 @@ func TestPolicy_IsPathGenerateNeeded(t *testing.T) {
policy
.
Type
=
"remote"
asserts
.
False
(
policy
.
IsPathGenerateNeeded
())
}
func
TestPolicy_ClearCache
(
t
*
testing
.
T
)
{
asserts
:=
assert
.
New
(
t
)
cache
.
Set
(
"policy_202"
,
1
,
0
)
policy
:=
Policy
{
Model
:
gorm
.
Model
{
ID
:
202
}}
policy
.
ClearCache
()
_
,
ok
:=
cache
.
Get
(
"policy_202"
)
asserts
.
False
(
ok
)
}
func
TestPolicy_UpdateAccessKey
(
t
*
testing
.
T
)
{
asserts
:=
assert
.
New
(
t
)
policy
:=
Policy
{
Model
:
gorm
.
Model
{
ID
:
202
}}
mock
.
ExpectBegin
()
mock
.
ExpectExec
(
"UPDATE(.+)"
)
.
WillReturnResult
(
sqlmock
.
NewResult
(
1
,
1
))
mock
.
ExpectCommit
()
err
:=
policy
.
UpdateAccessKey
(
"123"
)
asserts
.
NoError
(
mock
.
ExpectationsWereMet
())
asserts
.
NoError
(
err
)
}
func
TestPolicy_Props
(
t
*
testing
.
T
)
{
asserts
:=
assert
.
New
(
t
)
policy
:=
Policy
{
Type
:
"onedrive"
}
asserts
.
True
(
policy
.
IsMockThumbNeeded
())
asserts
.
False
(
policy
.
IsThumbGenerateNeeded
())
asserts
.
True
(
policy
.
IsPathGenerateNeeded
())
asserts
.
True
(
policy
.
IsTransitUpload
(
4
))
asserts
.
False
(
policy
.
IsTransitUpload
(
5
*
1024
*
1024
))
policy
.
Type
=
"local"
asserts
.
False
(
policy
.
IsMockThumbNeeded
())
asserts
.
True
(
policy
.
IsThumbGenerateNeeded
())
asserts
.
True
(
policy
.
IsPathGenerateNeeded
())
}
pkg/filesystem/filesystem_test.go
浏览文件 @
588514b4
...
...
@@ -3,8 +3,10 @@ package filesystem
import
(
"github.com/DATA-DOG/go-sqlmock"
model
"github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/cache"
"github.com/HFO4/cloudreve/pkg/filesystem/driver/local"
"github.com/HFO4/cloudreve/pkg/filesystem/driver/remote"
"github.com/HFO4/cloudreve/pkg/serializer"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"net/http/httptest"
...
...
@@ -72,6 +74,94 @@ func TestDispatchHandler(t *testing.T) {
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"unknown"
}
err
=
fs
.
DispatchHandler
()
asserts
.
Error
(
err
)
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"mock"
}
err
=
fs
.
DispatchHandler
()
asserts
.
NoError
(
err
)
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"local"
}
err
=
fs
.
DispatchHandler
()
asserts
.
NoError
(
err
)
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"remote"
}
err
=
fs
.
DispatchHandler
()
asserts
.
NoError
(
err
)
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"qiniu"
}
err
=
fs
.
DispatchHandler
()
asserts
.
NoError
(
err
)
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"oss"
}
err
=
fs
.
DispatchHandler
()
asserts
.
NoError
(
err
)
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"upyun"
}
err
=
fs
.
DispatchHandler
()
asserts
.
NoError
(
err
)
fs
.
Policy
=
&
model
.
Policy
{
Type
:
"onedrive"
}
err
=
fs
.
DispatchHandler
()
asserts
.
NoError
(
err
)
}
func
TestNewFileSystemFromCallback
(
t
*
testing
.
T
)
{
asserts
:=
assert
.
New
(
t
)
// 用户上下文不存在
{
c
,
_
:=
gin
.
CreateTestContext
(
httptest
.
NewRecorder
())
fs
,
err
:=
NewFileSystemFromCallback
(
c
)
asserts
.
Nil
(
fs
)
asserts
.
Error
(
err
)
}
// 找不到回调会话
{
c
,
_
:=
gin
.
CreateTestContext
(
httptest
.
NewRecorder
())
c
.
Set
(
"user"
,
&
model
.
User
{
Policy
:
model
.
Policy
{
Type
:
"local"
,
},
})
fs
,
err
:=
NewFileSystemFromCallback
(
c
)
asserts
.
Nil
(
fs
)
asserts
.
Error
(
err
)
}
// 找不到上传策略
{
c
,
_
:=
gin
.
CreateTestContext
(
httptest
.
NewRecorder
())
c
.
Set
(
"user"
,
&
model
.
User
{
Policy
:
model
.
Policy
{
Type
:
"local"
,
},
})
c
.
Set
(
"callbackSession"
,
&
serializer
.
UploadSession
{
PolicyID
:
138
})
cache
.
Deletes
([]
string
{
"138"
},
"policy_"
)
mock
.
ExpectQuery
(
"SELECT(.+)"
)
.
WillReturnRows
(
sqlmock
.
NewRows
([]
string
{
"id"
}))
fs
,
err
:=
NewFileSystemFromCallback
(
c
)
asserts
.
NoError
(
mock
.
ExpectationsWereMet
())
asserts
.
Nil
(
fs
)
asserts
.
Error
(
err
)
}
// 成功
{
c
,
_
:=
gin
.
CreateTestContext
(
httptest
.
NewRecorder
())
c
.
Set
(
"user"
,
&
model
.
User
{
Policy
:
model
.
Policy
{
Type
:
"local"
,
},
})
c
.
Set
(
"callbackSession"
,
&
serializer
.
UploadSession
{
PolicyID
:
138
})
cache
.
Deletes
([]
string
{
"138"
},
"policy_"
)
mock
.
ExpectQuery
(
"SELECT(.+)"
)
.
WillReturnRows
(
sqlmock
.
NewRows
([]
string
{
"id"
,
"type"
,
"options"
})
.
AddRow
(
138
,
"local"
,
"{}"
))
fs
,
err
:=
NewFileSystemFromCallback
(
c
)
asserts
.
NoError
(
mock
.
ExpectationsWereMet
())
asserts
.
NotNil
(
fs
)
asserts
.
NoError
(
err
)
}
}
func
TestFileSystem_SetTargetFileByIDs
(
t
*
testing
.
T
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录