Test: Task list / file delete

pull/247/head
HFO4 5 years ago
parent 9b3f5b0efd
commit 7dcc7a4880

@ -1,13 +1,15 @@
package authn package authn
import ( import (
"github.com/HFO4/cloudreve/pkg/cache"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing" "testing"
) )
func TestInit(t *testing.T) { func TestInit(t *testing.T) {
asserts := assert.New(t) asserts := assert.New(t)
cache.Set("setting_siteURL", "http://cloudreve.org", 0)
cache.Set("setting_siteName", "Cloudreve", 0)
asserts.NotPanics(func() { asserts.NotPanics(func() {
Init() Init()
}) })

@ -326,6 +326,8 @@ func TestFileSystem_Delete(t *testing.T) {
mock.ExpectQuery("SELECT(.+)").WillReturnRows(sqlmock.NewRows([]string{"id", "name", "source_name", "policy_id", "size"}).AddRow(1, "1.txt", "1.txt", 603, 2)) mock.ExpectQuery("SELECT(.+)").WillReturnRows(sqlmock.NewRows([]string{"id", "name", "source_name", "policy_id", "size"}).AddRow(1, "1.txt", "1.txt", 603, 2))
mock.ExpectQuery("SELECT(.+)files(.+)"). mock.ExpectQuery("SELECT(.+)files(.+)").
WillReturnRows(sqlmock.NewRows([]string{"id", "policy_id", "source_name"})) WillReturnRows(sqlmock.NewRows([]string{"id", "policy_id", "source_name"}))
// 查找软连接
mock.ExpectQuery("SELECT(.+)").WillReturnRows(sqlmock.NewRows([]string{"id"}))
// 查询上传策略 // 查询上传策略
mock.ExpectQuery("SELECT(.+)").WillReturnRows(sqlmock.NewRows([]string{"id", "type"}).AddRow(603, "local")) mock.ExpectQuery("SELECT(.+)").WillReturnRows(sqlmock.NewRows([]string{"id", "type"}).AddRow(603, "local"))
// 删除文件记录 // 删除文件记录
@ -338,29 +340,16 @@ func TestFileSystem_Delete(t *testing.T) {
mock.ExpectExec("UPDATE(.+)shares"). mock.ExpectExec("UPDATE(.+)shares").
WillReturnResult(sqlmock.NewResult(0, 3)) WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit() mock.ExpectCommit()
// 归还容量
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)users").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
// 删除目录
mock.ExpectBegin()
mock.ExpectExec("DELETE(.+)folders").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
// 删除对应分享
mock.ExpectBegin()
mock.ExpectExec("UPDATE(.+)shares").
WillReturnResult(sqlmock.NewResult(0, 3))
mock.ExpectCommit()
err := fs.Delete(ctx, []uint{1}, []uint{1}) err := fs.Delete(ctx, []uint{1}, []uint{1})
asserts.Error(err) asserts.Error(err)
asserts.Equal(203, err.(serializer.AppError).Code) asserts.Equal(203, err.(serializer.AppError).Code)
asserts.Equal(uint64(0), fs.User.Storage) asserts.Equal(uint64(3), fs.User.Storage)
asserts.NoError(mock.ExpectationsWereMet())
} }
//全部成功 //全部成功
{ {
fs.CleanTargets()
file, err := os.Create("1.txt") file, err := os.Create("1.txt")
file2, err := os.Create("2.txt") file2, err := os.Create("2.txt")
file.Close() file.Close()

@ -35,3 +35,11 @@ func TestBuildSiteConfig(t *testing.T) {
}) })
asserts.Equal(uint(5), res.Data.(SiteConfig).User.ID) asserts.Equal(uint(5), res.Data.(SiteConfig).User.ID)
} }
func TestBuildTaskList(t *testing.T) {
asserts := assert.New(t)
tasks := []model.Task{{}}
res := BuildTaskList(tasks, 1)
asserts.NotNil(res)
}

@ -5,6 +5,7 @@ import (
"github.com/DATA-DOG/go-sqlmock" "github.com/DATA-DOG/go-sqlmock"
model "github.com/HFO4/cloudreve/models" model "github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/cache" "github.com/HFO4/cloudreve/pkg/cache"
"github.com/duo-labs/webauthn/webauthn"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing" "testing"
@ -110,3 +111,10 @@ func TestBuildTagRes(t *testing.T) {
asserts.Equal("", res[0].Expression) asserts.Equal("", res[0].Expression)
asserts.Equal("exp", res[1].Expression) asserts.Equal("exp", res[1].Expression)
} }
func TestBuildWebAuthnList(t *testing.T) {
asserts := assert.New(t)
credentials := []webauthn.Credential{{}}
res := BuildWebAuthnList(credentials)
asserts.Len(res, 1)
}

@ -2,6 +2,7 @@ package thumb
import ( import (
"fmt" "fmt"
"github.com/HFO4/cloudreve/pkg/cache"
"github.com/HFO4/cloudreve/pkg/util" "github.com/HFO4/cloudreve/pkg/util"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"image" "image"
@ -99,3 +100,22 @@ func TestThumb_Save(t *testing.T) {
asserts.True(util.Exists("TestThumb_Save.png")) asserts.True(util.Exists("TestThumb_Save.png"))
} }
func TestThumb_CreateAvatar(t *testing.T) {
asserts := assert.New(t)
file := CreateTestImage()
defer file.Close()
thumb, err := NewThumbFromFile(file, "123.jpg")
asserts.NoError(err)
cache.Set("setting_avatar_path", "tests", 0)
cache.Set("setting_avatar_size_s", "50", 0)
cache.Set("setting_avatar_size_m", "130", 0)
cache.Set("setting_avatar_size_l", "200", 0)
asserts.NoError(thumb.CreateAvatar(1))
asserts.True(util.Exists("tests/avatar_1_1.png"))
asserts.True(util.Exists("tests/avatar_1_2.png"))
asserts.True(util.Exists("tests/avatar_1_0.png"))
}

Loading…
Cancel
Save