1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-02 01:07:28 -04:00
v2fly/external/github.com/lucas-clemente/quic-go/mockgen_private.sh

29 lines
1.3 KiB
Bash
Raw Normal View History

2018-11-20 17:51:25 -05:00
#!/bin/bash
# Mockgen refuses to generate mocks private types.
# This script copies the quic package to a temporary directory, and adds an public alias for the private type.
# It then creates a mock for this public (alias) type.
TEMP_DIR=$(mktemp -d)
2019-01-17 09:33:18 -05:00
mkdir -p $TEMP_DIR/src/v2ray.com/core/external/github.com/lucas-clemente/quic-go/
2018-11-20 17:51:25 -05:00
# uppercase the name of the interface
INTERFACE_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${4:0:1})${4:1}"
# copy all .go files to a temporary directory
2019-01-17 09:33:18 -05:00
rsync -r --exclude 'vendor' --include='*.go' --include '*/' --exclude '*' $GOPATH/src/v2ray.com/core/external/github.com/lucas-clemente/quic-go/ $TEMP_DIR/src/v2ray.com/core/external/github.com/lucas-clemente/quic-go/
2018-11-20 17:51:25 -05:00
# create a public alias for the interface, so that mockgen can process it
2019-01-17 09:33:18 -05:00
echo -e "package $1\n" > $TEMP_DIR/src/v2ray.com/core/external/github.com/lucas-clemente/quic-go/mockgen_interface.go
echo "type $INTERFACE_NAME = $4" >> $TEMP_DIR/src/v2ray.com/core/external/github.com/lucas-clemente/quic-go/mockgen_interface.go
2018-11-20 17:51:25 -05:00
export GOPATH="$TEMP_DIR:$GOPATH"
mockgen -package $1 -self_package $1 -destination $2 $3 $INTERFACE_NAME
2019-01-17 09:33:18 -05:00
# mockgen imports quic-go as 'import quic_go v2ray.com/core/external/github.com/lucas_clemente/quic-go'
2018-11-20 17:51:25 -05:00
sed -i '' 's/quic_go.//g' $2
goimports -w $2
rm -r "$TEMP_DIR"