You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudreve/pkg/serializer/response_test.go

34 lines
746 B

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)
}