Cloudreve/pkg/serializer/upload_test.go

64 lines
1 KiB
Go
Raw Normal View History

2019-12-27 21:15:05 +08:00
package serializer
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestDecodeUploadPolicy(t *testing.T) {
asserts := assert.New(t)
testCases := []struct {
input string
expectError bool
expectNil bool
expectRes *UploadPolicy
}{
{
"错误的base64字符",
true,
true,
&UploadPolicy{},
},
{
"6ZSZ6K+v55qESlNPTuWtl+espg==",
true,
true,
&UploadPolicy{},
},
{
"e30=",
false,
false,
&UploadPolicy{},
},
{
2019-12-28 15:50:56 +08:00
"eyJjYWxsYmFja191cmwiOiJ0ZXN0In0=",
2019-12-27 21:15:05 +08:00
false,
false,
2019-12-28 15:50:56 +08:00
&UploadPolicy{CallbackURL: "test"},
2019-12-27 21:15:05 +08:00
},
}
for _, testCase := range testCases {
res, err := DecodeUploadPolicy(testCase.input)
if testCase.expectError {
asserts.Error(err)
}
if testCase.expectNil {
asserts.Nil(res)
}
if !testCase.expectNil {
asserts.Equal(testCase.expectRes, res)
}
}
}
2019-12-28 15:50:56 +08:00
func TestUploadPolicy_EncodeUploadPolicy(t *testing.T) {
asserts := assert.New(t)
testPolicy := UploadPolicy{}
res, err := testPolicy.EncodeUploadPolicy()
asserts.NoError(err)
asserts.NotEmpty(res)
}