Skip to content

Commit

Permalink
test: add validate test
Browse files Browse the repository at this point in the history
  • Loading branch information
ppzqh committed Aug 8, 2024
1 parent 46d8496 commit ca3293f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 0 additions & 4 deletions pkg/remote/codec/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ func (p *crcPayloadValidator) Key(ctx context.Context) string {
return transmeta.HeaderCRC32C
}

func (p *crcPayloadValidator) Checksum(ctx context.Context, payload []byte) (value string, err error) {
return getCRC32C([][]byte{payload}), nil
}

func (p *crcPayloadValidator) Generate(ctx context.Context, outPayload []byte) (need bool, value string, err error) {
return true, getCRC32C([][]byte{outPayload}), nil
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/remote/codec/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package codec
import (
"context"
"github.com/bytedance/gopkg/util/xxhash3"
"github.com/cloudwego/kitex/internal/test"
"strconv"
"testing"
)

var _ PayloadValidator = &mockPayloadValidator{}
Expand Down Expand Up @@ -35,3 +37,16 @@ func (m *mockPayloadValidator) Validate(ctx context.Context, expectedValue strin
}
return value == expectedValue, nil
}

func TestPayloadValidator(t *testing.T) {
p := &crcPayloadValidator{}
payload := make([]byte, 0)

need, value, err := p.Generate(context.Background(), payload)
test.Assert(t, err == nil, err)
test.Assert(t, need)

pass, err := p.Validate(context.Background(), value, payload)
test.Assert(t, err == nil, err)
test.Assert(t, pass, true)
}

0 comments on commit ca3293f

Please sign in to comment.