github.com/ericwq/aprilsh@v0.0.0-20240517091432-958bc568daa0/frontend/client/itest.sh (about) 1 #!/bin/sh 2 3 # 4 # https://go.dev/testing/coverage/#running 5 # https://go.dev/blog/integration-test-coverage 6 # https://dustinspecker.com/posts/go-combined-unit-integration-code-coverage/ 7 # 8 # BUILDARGS="$*" 9 # 10 # comma seperated package list 11 # 12 PKGC="github.com/ericwq/aprilsh/frontend/aprilsh-client" 13 PKGS="github.com/ericwq/aprilsh/frontend/aprilsh-server" 14 PKG="$PKGC,$PKGS" 15 # 16 # Terminate the test if any command below does not complete successfully. 17 # 18 set -e 19 # 20 # Build server binary for testing purposes. 21 # 22 cd ../aprilsh-server/ 23 go build -cover -coverpkg=$PKGS -o ../aprilsh-client/server . 24 echo "---build server" 25 # 26 # Build client binary for testing purposes. 27 # 28 cd ../aprilsh-client/ 29 go build -cover -coverpkg=$PKGC -o client . 30 echo "---build client" 31 # 32 # Setup 33 # 34 rm -rf coverage 35 mkdir -p coverage/unit -p coverage/int 36 # 37 # Run unit test to collect coverage 38 # 39 go test -cover . -args -test.gocoverdir=./coverage/unit 40 echo "---perform unit test" 41 # 42 # start the server 43 # 44 GOCOVERDIR=./coverage/int ./server -a 2 & 45 server_id=$! 46 echo "---start server" 47 # 48 # start client 49 # 50 GOCOVERDIR=./coverage/int ./client -pwd password ide@localhost 51 client_id=$! 52 sleep 2 53 echo "---start client" 54 # 55 # clean the server and client 56 # 57 echo "kill server[$server_id]" 58 echo "kill client[$client_id]" 59 kill $server_id 60 # kill -9 $client_id 61 62 # 63 # Retrieve total coverage 64 # 65 go tool covdata percent -i=./coverage/unit,./coverage/int -pkg=$PKG 66 67 # 68 # Converting to legacy text format 69 # 70 go tool covdata textfmt -i=./coverage/unit,./coverage/int -o coverage/profile -pkg=$PKG 71 72 # 73 # View total coverage 74 # 75 go tool cover -func coverage/profile