2019-11-20 17:21:30 +08:00
|
|
|
package filesystem
|
|
|
|
|
|
|
|
import (
|
|
|
|
model "github.com/HFO4/cloudreve/models"
|
2019-11-24 16:28:41 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2019-11-20 17:21:30 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-11-24 16:28:41 +08:00
|
|
|
"net/http/httptest"
|
2019-11-22 14:56:46 +08:00
|
|
|
|
2019-11-20 17:21:30 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewFileSystem(t *testing.T) {
|
|
|
|
asserts := assert.New(t)
|
|
|
|
user := model.User{
|
|
|
|
Policy: model.Policy{
|
|
|
|
Type: "local",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fs, err := NewFileSystem(&user)
|
|
|
|
asserts.NoError(err)
|
|
|
|
asserts.NotNil(fs.Handler)
|
|
|
|
|
|
|
|
user.Policy.Type = "unknown"
|
|
|
|
fs, err = NewFileSystem(&user)
|
|
|
|
asserts.Error(err)
|
|
|
|
}
|
2019-11-24 16:28:41 +08:00
|
|
|
|
|
|
|
func TestNewFileSystemFromContext(t *testing.T) {
|
|
|
|
asserts := assert.New(t)
|
|
|
|
c, _ := gin.CreateTestContext(httptest.NewRecorder())
|
|
|
|
c.Set("user", &model.User{
|
|
|
|
Policy: model.Policy{
|
|
|
|
Type: "local",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
fs, err := NewFileSystemFromContext(c)
|
|
|
|
asserts.NotNil(fs)
|
|
|
|
asserts.NoError(err)
|
|
|
|
|
|
|
|
c, _ = gin.CreateTestContext(httptest.NewRecorder())
|
|
|
|
fs, err = NewFileSystemFromContext(c)
|
|
|
|
asserts.Nil(fs)
|
|
|
|
asserts.Error(err)
|
|
|
|
}
|