Skip to content
Permalink
Browse files
新增异构测试
  • Loading branch information
Changeden committed Sep 23, 2021
1 parent 8f630f5 commit b701ba18522852664a1db7c2a2843a74eb5bf7d8
Showing 1 changed file with 49 additions and 13 deletions.
@@ -85,24 +85,33 @@ func TestDupStructNameRequest(t *testing.T) {
}

func TestDupStructNameResponse(t *testing.T) {
packageType := hessian.PackageResponse
responseStatus := hessian.Response_OK
defer func() {
if err := recover(); err != nil {
if errStr, ok := err.(string); ok {
assert.Equal(t, EXPECTED_ERROR_MSG, errStr)
}
}
}()

var body interface{}
body = &CaseZ{Name: "TestDupStructNameResponse"}
resp, err := doTestHessianEncodeHeader(t, packageType, responseStatus, body)
assert.Nil(t, err)
err, codecR, h := doTestHeader(t, body)

codecR := hessian.NewHessianCodec(bufio.NewReader(bytes.NewReader(resp)))
decodedResponse := &hessian.Response{}
decodedResponse.RspObj = &dup.CaseZ{}
err = codecR.ReadBody(decodedResponse)
assert.NotNil(t, err)
assert.Equal(t, EXPECTED_ERROR_MSG, err.Error())

h := &hessian.DubboHeader{}
err = codecR.ReadHeader(h)
decodedResponse = &hessian.Response{}
decodedResponse.RspObj = &CaseZ{}
err = codecR.ReadBody(decodedResponse)
assert.Nil(t, err)

assert.Equal(t, byte(2), h.SerialID)
assert.Equal(t, packageType, h.Type&(hessian.PackageRequest|hessian.PackageResponse|hessian.PackageHeartbeat))
assert.Equal(t, int64(1), h.ID)
assert.Equal(t, responseStatus, h.ResponseStatus)
checkResponseBody(t, decodedResponse, h, body)
}

func TestDupStructNameResponse2(t *testing.T) {
defer func() {
if err := recover(); err != nil {
if errStr, ok := err.(string); ok {
@@ -111,17 +120,44 @@ func TestDupStructNameResponse(t *testing.T) {
}
}()

var body interface{}
body = &dup.CaseZ{Name: "TestDupStructNameResponse"}
err, codecR, h := doTestHeader(t, body)

decodedResponse := &hessian.Response{}
decodedResponse.RspObj = &dup.CaseZ{}
decodedResponse.RspObj = &CaseZ{}
err = codecR.ReadBody(decodedResponse)
assert.NotNil(t, err)
assert.Equal(t, EXPECTED_ERROR_MSG, err.Error())

decodedResponse = &hessian.Response{}
decodedResponse.RspObj = &CaseZ{}
decodedResponse.RspObj = &dup.CaseZ{}
err = codecR.ReadBody(decodedResponse)
assert.Nil(t, err)

checkResponseBody(t, decodedResponse, h, body)
}

func doTestHeader(t *testing.T, body interface{}) (error, *hessian.HessianCodec, *hessian.DubboHeader) {
packageType := hessian.PackageResponse
responseStatus := hessian.Response_OK
resp, err := doTestHessianEncodeHeader(t, packageType, responseStatus, body)
assert.Nil(t, err)

codecR := hessian.NewHessianCodec(bufio.NewReader(bytes.NewReader(resp)))

h := &hessian.DubboHeader{}
err = codecR.ReadHeader(h)
assert.Nil(t, err)

assert.Equal(t, byte(2), h.SerialID)
assert.Equal(t, packageType, h.Type&(hessian.PackageRequest|hessian.PackageResponse|hessian.PackageHeartbeat))
assert.Equal(t, int64(1), h.ID)
assert.Equal(t, responseStatus, h.ResponseStatus)
return err, codecR, h
}

func checkResponseBody(t *testing.T, decodedResponse *hessian.Response, h *hessian.DubboHeader, body interface{}) {
t.Log(decodedResponse)

if h.ResponseStatus != hessian.Zero && h.ResponseStatus != hessian.Response_OK {

0 comments on commit b701ba1

Please sign in to comment.