github.com/psiphon-labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/common/quic/gquic-go/mockgen_private.sh (about) 1 #!/bin/bash 2 3 # Mockgen refuses to generate mocks private types. 4 # This script copies the quic package to a temporary directory, and adds an public alias for the private type. 5 # It then creates a mock for this public (alias) type. 6 7 TEMP_DIR=$(mktemp -d) 8 mkdir -p $TEMP_DIR/src/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/ 9 10 # uppercase the name of the interface 11 INTERFACE_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${4:0:1})${4:1}" 12 13 # copy all .go files to a temporary directory 14 rsync -r --exclude 'vendor' --include='*.go' --include '*/' --exclude '*' $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/ $TEMP_DIR/src/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/ 15 16 # create a public alias for the interface, so that mockgen can process it 17 echo -e "package $1\n" > $TEMP_DIR/src/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/mockgen_interface.go 18 echo "type $INTERFACE_NAME = $4" >> $TEMP_DIR/src/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/mockgen_interface.go 19 20 export GOPATH="$TEMP_DIR:$GOPATH" 21 22 mockgen -package $1 -self_package $1 -destination $2 $3 $INTERFACE_NAME 23 24 # mockgen imports quic-go as 'import quic_go github.com/lucas_clemente/quic-go' 25 sed -i '' 's/quic_go.//g' $2 26 goimports -w $2 27 28 rm -r "$TEMP_DIR"