Test: same folder check

This commit is contained in:
HFO4 2019-11-27 19:16:13 +08:00
parent 0982347f40
commit 7d5016ae40
2 changed files with 8 additions and 1 deletions

View file

@ -153,6 +153,13 @@ func TestFileSystem_CreateDirectory(t *testing.T) {
asserts.Equal(ErrFileExisted, err) asserts.Equal(ErrFileExisted, err)
asserts.NoError(mock.ExpectationsWereMet()) asserts.NoError(mock.ExpectationsWereMet())
// 存在同名目录
mock.ExpectQuery("SELECT(.+)folders").WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(1, "ab"))
mock.ExpectQuery("SELECT(.+)folders").WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(1, "ab"))
err = fs.CreateDirectory(ctx, "/ad/ab")
asserts.Equal(ErrFolderExisted, err)
asserts.NoError(mock.ExpectationsWereMet())
// 成功创建 // 成功创建
mock.ExpectQuery("SELECT(.+)folders").WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(1, "ab")) mock.ExpectQuery("SELECT(.+)folders").WillReturnRows(sqlmock.NewRows([]string{"id", "name"}).AddRow(1, "ab"))
mock.ExpectQuery("SELECT(.+)files").WillReturnRows(sqlmock.NewRows([]string{"id", "name"})) mock.ExpectQuery("SELECT(.+)files").WillReturnRows(sqlmock.NewRows([]string{"id", "name"}))

View file

@ -36,7 +36,7 @@ func (service *DirectoryService) ListDirectory(c *gin.Context) serializer.Respon
} }
} }
// CreateDirectory 创建目录 TODO:test // CreateDirectory 创建目录
func (service *DirectoryService) CreateDirectory(c *gin.Context) serializer.Response { func (service *DirectoryService) CreateDirectory(c *gin.Context) serializer.Response {
// 创建文件系统 // 创建文件系统
fs, err := filesystem.NewFileSystemFromContext(c) fs, err := filesystem.NewFileSystemFromContext(c)