forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockgen_private.sh
executable file
·28 lines (19 loc) · 1.1 KB
/
mockgen_private.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/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)
mkdir -p $TEMP_DIR/src/github.com/boisjacques/qed/
# uppercase the name of the interface
INTERFACE_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${4:0:1})${4:1}"
# copy all .go files to a temporary directory
rsync -r --exclude 'vendor' --include='*.go' --include '*/' --exclude '*' $GOPATH/src/github.com/boisjacques/qed/ $TEMP_DIR/src/github.com/boisjacques/qed/
# create a public alias for the interface, so that mockgen can process it
echo -e "package $1\n" > $TEMP_DIR/src/github.com/boisjacques/qed/mockgen_interface.go
echo "type $INTERFACE_NAME = $4" >> $TEMP_DIR/src/github.com/boisjacques/qed/mockgen_interface.go
export GOPATH="$TEMP_DIR:$GOPATH"
mockgen -package $1 -self_package $1 -destination $2 $3 $INTERFACE_NAME
# mockgen imports quic-go as 'import quic_go github.com/lucas_clemente/quic-go'
sed -i '' 's/quic_go.//g' $2
goimports -w $2
rm -r "$TEMP_DIR"