Test: new changes in 3.4.0
This commit is contained in:
parent
532bff820a
commit
9056ef9171
6 changed files with 112 additions and 5 deletions
2
assets
2
assets
|
@ -1 +1 @@
|
|||
Subproject commit efe29817615eed351f7432034d533e7e02b52197
|
||||
Subproject commit 18bb1b01b24c25ce070a2027fe362985d4866932
|
|
@ -190,7 +190,7 @@ func TestHandler_Source(t *testing.T) {
|
|||
|
||||
// 设定了CDN,解析失败
|
||||
{
|
||||
handler.Policy.BaseURL = string(0x7f)
|
||||
handler.Policy.BaseURL = string([]byte{0x7f})
|
||||
file := model.File{
|
||||
Model: gorm.Model{
|
||||
ID: 1,
|
||||
|
|
|
@ -3,6 +3,7 @@ package request
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/cloudreve/Cloudreve/v3/pkg/cache"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
@ -54,16 +55,19 @@ func TestWithContext(t *testing.T) {
|
|||
|
||||
func TestHTTPClient_Request(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
client := HTTPClient{}
|
||||
client := NewClient(WithSlaveMeta("test"))
|
||||
|
||||
// 正常
|
||||
{
|
||||
resp := client.Request(
|
||||
"GET",
|
||||
"http://cloudreveisnotexist.com",
|
||||
"POST",
|
||||
"/test",
|
||||
strings.NewReader(""),
|
||||
WithContentLength(0),
|
||||
WithEndpoint("http://cloudreveisnotexist.com"),
|
||||
WithTimeout(time.Duration(1)*time.Microsecond),
|
||||
WithCredential(auth.HMACAuth{SecretKey: []byte("123")}, 10),
|
||||
WithoutHeader([]string{"origin", "origin"}),
|
||||
)
|
||||
asserts.Error(resp.Err)
|
||||
asserts.Nil(resp.Response)
|
||||
|
@ -224,3 +228,11 @@ func TestNopRSCloser_SetFirstFakeChunk(t *testing.T) {
|
|||
rsc.SetContentLength(20)
|
||||
asserts.EqualValues(20, rsc.status.Size)
|
||||
}
|
||||
|
||||
func TestBlackHole(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
cache.Set("setting_reset_after_upload_failed", "true", 0)
|
||||
a.NotPanics(func() {
|
||||
BlackHole(strings.NewReader("TestBlackHole"))
|
||||
})
|
||||
}
|
||||
|
|
42
pkg/serializer/error_test.go
Normal file
42
pkg/serializer/error_test.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package serializer
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewError(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
err := NewError(400, "Bad Request", errors.New("error"))
|
||||
a.Error(err)
|
||||
a.EqualValues(400, err.Code)
|
||||
|
||||
err.WithError(errors.New("error2"))
|
||||
a.Equal("error2", err.RawError.Error())
|
||||
a.Equal("Bad Request", err.Error())
|
||||
|
||||
resp := &Response{
|
||||
Code: 400,
|
||||
Msg: "Bad Request",
|
||||
Error: "error",
|
||||
}
|
||||
err = NewErrorFromResponse(resp)
|
||||
a.Error(err)
|
||||
}
|
||||
|
||||
func TestDBErr(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
resp := DBErr("", nil)
|
||||
a.NotEmpty(resp.Msg)
|
||||
|
||||
resp = ParamErr("", nil)
|
||||
a.NotEmpty(resp.Msg)
|
||||
}
|
||||
|
||||
func TestErr(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
err := NewError(400, "Bad Request", errors.New("error"))
|
||||
resp := Err(400, "", err)
|
||||
a.Equal("Bad Request", resp.Msg)
|
||||
}
|
33
pkg/serializer/response_test.go
Normal file
33
pkg/serializer/response_test.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package serializer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewResponseWithGobData(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
type args struct {
|
||||
data interface{}
|
||||
}
|
||||
|
||||
res := NewResponseWithGobData(args{})
|
||||
a.Equal(CodeInternalSetting, res.Code)
|
||||
|
||||
res = NewResponseWithGobData("TestNewResponseWithGobData")
|
||||
a.Equal(0, res.Code)
|
||||
a.NotEmpty(res.Data)
|
||||
}
|
||||
|
||||
func TestResponse_GobDecode(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
res := NewResponseWithGobData("TestResponse_GobDecode")
|
||||
jsonContent, err := json.Marshal(res)
|
||||
a.NoError(err)
|
||||
resDecoded := &Response{}
|
||||
a.NoError(json.Unmarshal(jsonContent, resDecoded))
|
||||
var target string
|
||||
resDecoded.GobDecode(&target)
|
||||
a.Equal("TestResponse_GobDecode", target)
|
||||
}
|
20
pkg/serializer/slave_test.go
Normal file
20
pkg/serializer/slave_test.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package serializer
|
||||
|
||||
import (
|
||||
model "github.com/cloudreve/Cloudreve/v3/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSlaveTransferReq_Hash(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
s1 := &SlaveTransferReq{
|
||||
Src: "1",
|
||||
Policy: &model.Policy{},
|
||||
}
|
||||
s2 := &SlaveTransferReq{
|
||||
Src: "2",
|
||||
Policy: &model.Policy{},
|
||||
}
|
||||
a.NotEqual(s1.Hash("1"), s2.Hash("1"))
|
||||
}
|
Loading…
Add table
Reference in a new issue