Skip to content

feat: test generating deepcopy function #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -43,7 +43,4 @@ output/*
testdata/

# Files produced by run.sh
kitex_gen/
go.mod
go.sum
bin
84 changes: 84 additions & 0 deletions gencode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#! /bin/bash
# Copyright 2021 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.

set -e
set -x

export GO111MODULE=on
export GOBIN=$(pwd)/bin
export PATH=${GOBIN}:$PATH
mkdir -p ${GOBIN}

bits=$(getconf LONG_BIT)
if [[ $bits != 64 ]]; then
echo "this script runs on 64-bit architectures only" >&2
exit 1
fi

# Install protoc

get_protoc() {
os=$1
arch=$2
out=$3
suffix=$(echo ${os}-${arch} | sed 's/darwin/osx/' | sed 's/amd64/x86_64/' | sed 's/arm64/aarch_64/')
release=protoc-${PROTOC_VERSION#v}-${suffix}.zip
url=https://github.com/protocolbuffers/protobuf/releases/download/${PROTOC_VERSION}/${release}
wget -q $url || exit 1
python -m zipfile -e $release $os || exit 1
chmod +x $os/bin/protoc
mv $os/bin/protoc $out/protoc-${os}-${arch} && rm -rf $os $release
}

install_protoc() {
PROTOC_VERSION=v3.13.0
OUT=./bin
export PATH=$OUT:$PATH
mkdir -p $OUT

get_protoc darwin amd64 $OUT
get_protoc linux amd64 $OUT
get_protoc linux arm64 $OUT
for p in $OUT/protoc-*; do
"$p" --version 2>/dev/null && ln -s $(basename $p) $OUT/protoc || true
done
}

go_install() {
go install $@ || go get $@
}

which protoc || install_protoc

# Install thriftgo
which thriftgo || go_install github.com/cloudwego/thriftgo@latest

# Install kitex and generate codes
LOCAL_REPO=$1

if [[ -n $LOCAL_REPO ]]; then
cd ${LOCAL_REPO}
go_install ${LOCAL_REPO}/tool/cmd/kitex
cd -
else
go_install github.com/cloudwego/kitex/tool/cmd/kitex@latest
fi

test -d kitex_gen && rm -rf kitex_gen
kitex -module github.com/cloudwego/kitex-tests ./idl/stability.thrift
kitex -module github.com/cloudwego/kitex-tests ./idl/http.thrift
kitex -module github.com/cloudwego/kitex-tests ./idl/tenant.thrift
kitex -module github.com/cloudwego/kitex-tests -type protobuf -I idl ./idl/stability.proto
kitex -module github.com/cloudwego/kitex-tests -type protobuf -I idl ./idl/unknown_handler.proto
42 changes: 42 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module github.com/cloudwego/kitex-tests

go 1.18

require (
github.com/apache/thrift v0.13.0
github.com/bytedance/gopkg v0.0.0-20220824043955-beb90005fda6
github.com/cloudwego/fastpb v0.0.4
github.com/cloudwego/kitex v0.5.3-0.20230508073138-d68d41a95951
github.com/cloudwego/netpoll v0.3.2
google.golang.org/protobuf v1.28.1
)

require (
github.com/chenzhuoyu/iasm v0.0.0-20230222070914-0b1b64b0e762 // indirect
github.com/choleraehyq/pid v0.0.16 // indirect
github.com/cloudwego/frugal v0.1.6 // indirect
github.com/cloudwego/thriftgo v0.2.9 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/pprof v0.0.0-20220608213341-c488b8fa1db3 // indirect
github.com/jhump/protoreflect v1.8.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oleiade/lane v1.0.1 // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
github.com/tidwall/gjson v1.9.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 // indirect
golang.org/x/text v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/cloudwego/kitex => /Users/bytedance/go/src/github.com/jayantxie/kitex

replace github.com/apache/thrift => github.com/apache/thrift v0.13.0
326 changes: 326 additions & 0 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions idl/stability.thrift
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ struct STRequest {
14: required string flagMsg
15: required string framework = "kitex",
16: optional string mockCost,
17: map<i32, instparam.SubMessage> subMsgs,

255: optional base.Base Base,
}
736 changes: 736 additions & 0 deletions kitex_gen/protobuf/instparam/instparam.pb.fast.go

Large diffs are not rendered by default.

500 changes: 500 additions & 0 deletions kitex_gen/protobuf/instparam/instparam.pb.go

Large diffs are not rendered by default.

537 changes: 537 additions & 0 deletions kitex_gen/protobuf/stability/stability.pb.fast.go

Large diffs are not rendered by default.

432 changes: 432 additions & 0 deletions kitex_gen/protobuf/stability/stability.pb.go

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions kitex_gen/protobuf/stability/stservice/client.go
24 changes: 24 additions & 0 deletions kitex_gen/protobuf/stability/stservice/invoker.go
20 changes: 20 additions & 0 deletions kitex_gen/protobuf/stability/stservice/server.go
377 changes: 377 additions & 0 deletions kitex_gen/protobuf/stability/stservice/stservice.go
49 changes: 49 additions & 0 deletions kitex_gen/protobuf/unknown_handler/servicea/client.go
24 changes: 24 additions & 0 deletions kitex_gen/protobuf/unknown_handler/servicea/invoker.go
20 changes: 20 additions & 0 deletions kitex_gen/protobuf/unknown_handler/servicea/server.go
212 changes: 212 additions & 0 deletions kitex_gen/protobuf/unknown_handler/servicea/servicea.go
40 changes: 40 additions & 0 deletions kitex_gen/protobuf/unknown_handler/serviceb/client.go
24 changes: 24 additions & 0 deletions kitex_gen/protobuf/unknown_handler/serviceb/invoker.go
20 changes: 20 additions & 0 deletions kitex_gen/protobuf/unknown_handler/serviceb/server.go
43 changes: 43 additions & 0 deletions kitex_gen/protobuf/unknown_handler/serviceb/serviceb.go
135 changes: 135 additions & 0 deletions kitex_gen/protobuf/unknown_handler/unknown_handler.pb.fast.go
242 changes: 242 additions & 0 deletions kitex_gen/protobuf/unknown_handler/unknown_handler.pb.go
132 changes: 132 additions & 0 deletions kitex_gen/thrift/http/bizservice/bizservice.go
61 changes: 61 additions & 0 deletions kitex_gen/thrift/http/bizservice/client.go
24 changes: 24 additions & 0 deletions kitex_gen/thrift/http/bizservice/invoker.go
20 changes: 20 additions & 0 deletions kitex_gen/thrift/http/bizservice/server.go
3,636 changes: 3,636 additions & 0 deletions kitex_gen/thrift/http/http.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions kitex_gen/thrift/http/k-consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package http

// KitexUnusedProtection is used to prevent 'imported and not used' error.
var KitexUnusedProtection = struct{}{}
2,793 changes: 2,793 additions & 0 deletions kitex_gen/thrift/http/k-http.go

Large diffs are not rendered by default.

1,777 changes: 1,777 additions & 0 deletions kitex_gen/thrift/instparam/instparam.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions kitex_gen/thrift/instparam/k-consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package instparam

// KitexUnusedProtection is used to prevent 'imported and not used' error.
var KitexUnusedProtection = struct{}{}
1,652 changes: 1,652 additions & 0 deletions kitex_gen/thrift/instparam/k-instparam.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions kitex_gen/thrift/stability/k-consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package stability

// KitexUnusedProtection is used to prevent 'imported and not used' error.
var KitexUnusedProtection = struct{}{}
2,934 changes: 2,934 additions & 0 deletions kitex_gen/thrift/stability/k-stability.go

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions kitex_gen/thrift/stability/onewayservice/client.go
24 changes: 24 additions & 0 deletions kitex_gen/thrift/stability/onewayservice/invoker.go
69 changes: 69 additions & 0 deletions kitex_gen/thrift/stability/onewayservice/onewayservice.go
20 changes: 20 additions & 0 deletions kitex_gen/thrift/stability/onewayservice/server.go
3,893 changes: 3,893 additions & 0 deletions kitex_gen/thrift/stability/stability.go

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions kitex_gen/thrift/stability/stservice/client.go
24 changes: 24 additions & 0 deletions kitex_gen/thrift/stability/stservice/invoker.go
20 changes: 20 additions & 0 deletions kitex_gen/thrift/stability/stservice/server.go
196 changes: 196 additions & 0 deletions kitex_gen/thrift/stability/stservice/stservice.go
55 changes: 55 additions & 0 deletions kitex_gen/thrift/tenant/echoservice/client.go
98 changes: 98 additions & 0 deletions kitex_gen/thrift/tenant/echoservice/echoservice.go
24 changes: 24 additions & 0 deletions kitex_gen/thrift/tenant/echoservice/invoker.go
20 changes: 20 additions & 0 deletions kitex_gen/thrift/tenant/echoservice/server.go
4 changes: 4 additions & 0 deletions kitex_gen/thrift/tenant/k-consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package tenant

// KitexUnusedProtection is used to prevent 'imported and not used' error.
var KitexUnusedProtection = struct{}{}
2,295 changes: 2,295 additions & 0 deletions kitex_gen/thrift/tenant/k-tenant.go

Large diffs are not rendered by default.

2,728 changes: 2,728 additions & 0 deletions kitex_gen/thrift/tenant/tenant.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions thriftrpc/client.go
Original file line number Diff line number Diff line change
@@ -112,6 +112,11 @@ func CreateSTRequest(ctx context.Context) (context.Context, *stability.STRequest
utils.RandomString(100),
}
req.E = stability.TestEnum_FIRST
req.SubMsgs = map[int32]*instparam.SubMessage{
32: {
Id: thrift.Int64Ptr(32),
},
}

ctx = metainfo.WithValue(ctx, "TK", "TV")
ctx = metainfo.WithPersistentValue(ctx, "PK", "PV")
15 changes: 10 additions & 5 deletions thriftrpc/server.go
Original file line number Diff line number Diff line change
@@ -78,13 +78,18 @@ type STServiceHandler struct{}

// TestSTReq .
func (*STServiceHandler) TestSTReq(ctx context.Context, req *stability.STRequest) (r *stability.STResponse, err error) {
nreq := &stability.STRequest{}
err = nreq.DeepCopy(req)
if err != nil {
return nil, err
}
resp := &stability.STResponse{
Str: req.Str,
Mp: req.StringMap,
FlagMsg: req.FlagMsg,
Str: nreq.Str,
Mp: nreq.StringMap,
FlagMsg: nreq.FlagMsg,
}
if req.MockCost != nil {
if mockSleep, err := time.ParseDuration(*req.MockCost); err != nil {
if nreq.MockCost != nil {
if mockSleep, err := time.ParseDuration(*nreq.MockCost); err != nil {
return nil, err
} else {
time.Sleep(mockSleep)