mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Test: new changes in 3.4.0
This commit is contained in:
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"))
|
||||
}
|
||||
Reference in New Issue
Block a user