parent
532bff820a
commit
9056ef9171
@ -1 +1 @@
|
||||
Subproject commit efe29817615eed351f7432034d533e7e02b52197
|
||||
Subproject commit 18bb1b01b24c25ce070a2027fe362985d4866932
|
@ -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)
|
||||
}
|
@ -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)
|
||||
}
|
@ -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…
Reference in new issue