Skip to content

Commit

Permalink
chore: lint and test
Browse files Browse the repository at this point in the history
  • Loading branch information
ppzqh committed Aug 19, 2024
1 parent 33481ac commit 76af0f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/remote/codec/default_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
"context"
"encoding/binary"
"fmt"
netpolltrans "github.com/cloudwego/kitex/pkg/remote/trans/netpoll"
"github.com/cloudwego/netpoll"
"sync/atomic"

"github.com/cloudwego/netpoll"

"github.com/cloudwego/kitex/pkg/kerrors"
"github.com/cloudwego/kitex/pkg/remote"
"github.com/cloudwego/kitex/pkg/remote/codec/perrors"
netpolltrans "github.com/cloudwego/kitex/pkg/remote/trans/netpoll"
"github.com/cloudwego/kitex/pkg/retry"
"github.com/cloudwego/kitex/pkg/rpcinfo"
"github.com/cloudwego/kitex/pkg/serviceinfo"
Expand Down
29 changes: 29 additions & 0 deletions pkg/remote/codec/validate_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package codec

import (
Expand All @@ -7,6 +23,7 @@ import (
"testing"

"github.com/bytedance/gopkg/util/xxhash3"

"github.com/cloudwego/kitex/internal/test"
"github.com/cloudwego/kitex/pkg/kerrors"
"github.com/cloudwego/kitex/pkg/remote"
Expand All @@ -18,6 +35,7 @@ var _ PayloadValidator = &mockPayloadValidator{}
type mockPayloadValidator struct{}

const (
mockGenerateSkipKey = "mockGenerateSkip"
mockGenerateErrorKey = "mockGenerateError"
mockExceedLimitKey = "mockExceedLimit"
)
Expand All @@ -27,6 +45,9 @@ func (m *mockPayloadValidator) Key(ctx context.Context) string {
}

func (m *mockPayloadValidator) Generate(ctx context.Context, outPayload []byte) (need bool, value string, err error) {
if l := ctx.Value(mockGenerateSkipKey); l != nil {
return false, "", nil
}
if l := ctx.Value(mockExceedLimitKey); l != nil {
// return value with length exceeding the limit
return true, string(make([]byte, maxPayloadChecksumLength+1)), nil
Expand Down Expand Up @@ -75,6 +96,14 @@ func TestPayloadChecksumGenerate(t *testing.T) {
test.Assert(t, len(strInfo) != 0)
test.Assert(t, strInfo[getValidatorKey(ctx, pv)] != "")

// success, no need to generate
message = initClientSendMsg(transport.TTHeader)
strInfo = message.TransInfo().TransStrInfo()
ctx = context.WithValue(context.Background(), mockGenerateSkipKey, "true")
err = payloadChecksumGenerate(ctx, pv, payload, message)
test.Assert(t, err == nil, err)
test.Assert(t, len(strInfo) == 0) // no checksum in strinfo

// failed, generate error
message = initClientSendMsg(transport.TTHeader)
ctx = context.WithValue(context.Background(), mockGenerateErrorKey, "true")
Expand Down

0 comments on commit 76af0f3

Please sign in to comment.