github.com/cloudreve/Cloudreve/v3@v3.0.0-20240224133659-3edb00a6484c/pkg/serializer/response_test.go (about)

     1  package serializer
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/stretchr/testify/assert"
     6  	"testing"
     7  )
     8  
     9  func TestNewResponseWithGobData(t *testing.T) {
    10  	a := assert.New(t)
    11  	type args struct {
    12  		data interface{}
    13  	}
    14  
    15  	res := NewResponseWithGobData(args{})
    16  	a.Equal(CodeInternalSetting, res.Code)
    17  
    18  	res = NewResponseWithGobData("TestNewResponseWithGobData")
    19  	a.Equal(0, res.Code)
    20  	a.NotEmpty(res.Data)
    21  }
    22  
    23  func TestResponse_GobDecode(t *testing.T) {
    24  	a := assert.New(t)
    25  	res := NewResponseWithGobData("TestResponse_GobDecode")
    26  	jsonContent, err := json.Marshal(res)
    27  	a.NoError(err)
    28  	resDecoded := &Response{}
    29  	a.NoError(json.Unmarshal(jsonContent, resDecoded))
    30  	var target string
    31  	resDecoded.GobDecode(&target)
    32  	a.Equal("TestResponse_GobDecode", target)
    33  }