diff --git a/tests/gocrun.bats b/tests/gocrun.bats new file mode 100755 index 0000000..d4a363d --- /dev/null +++ b/tests/gocrun.bats @@ -0,0 +1,43 @@ +#!/usr/bin/env bats +# Copyright 2020 Qiniu Cloud (七牛云) +# +# 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. + +setup_file() { + # run centered server + goc server 3>&- & + GOC_PID=$! + sleep 2 + goc init + + # run covered goc run + WORKDIR=$PWD + cd samples/run_for_several_seconds + ls -al + gocc run --debug . 3>&- & + GOCC_PID=$! + sleep 2 + echo "goc gocc server started" +} + +teardown_file() { + cd $WORKDIR + # collect from center + goc profile --debug -o filtered2.cov + kill -9 $GOC_PID + kill -9 $GOCC_PID +} + +@test "test basic goc run" { + +} \ No newline at end of file diff --git a/tests/run-ci-actions.sh b/tests/run-ci-actions.sh index dee7924..8980993 100755 --- a/tests/run-ci-actions.sh +++ b/tests/run-ci-actions.sh @@ -19,4 +19,6 @@ echo "test start" bats server.bats -bash <(curl -s https://codecov.io/bash) -f filtered.cov -F e2e \ No newline at end of file +bats gocrun.bats + +bash <(curl -s https://codecov.io/bash) -f 'filtered*' -F e2e \ No newline at end of file diff --git a/tests/samples/run_for_several_seconds/go.mod b/tests/samples/run_for_several_seconds/go.mod new file mode 100644 index 0000000..c947b9e --- /dev/null +++ b/tests/samples/run_for_several_seconds/go.mod @@ -0,0 +1,4 @@ +module example.com/simple-project + +go 1.11 + diff --git a/tests/samples/run_for_several_seconds/main.go b/tests/samples/run_for_several_seconds/main.go new file mode 100644 index 0000000..f8e8cbc --- /dev/null +++ b/tests/samples/run_for_several_seconds/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" + "time" +) + +func main() { + fmt.Println("hello") + time.Sleep(time.Second * 15) +} diff --git a/tests/server.bats b/tests/server.bats index 88368da..c834e5a 100755 --- a/tests/server.bats +++ b/tests/server.bats @@ -18,9 +18,11 @@ setup_file() { goc server 3>&- & GOC_PID=$! sleep 2 + goc init # run covered goc - gocc server --port=:60001 3>&- & + gocc server --port=:60001 --debug 3>&- & GOCC_PID=$! + sleep 2 echo "goc gocc server started" } @@ -39,3 +41,16 @@ teardown_file() { run goc profile --center=http://127.0.0.1:60001 [ "$status" -eq 0 ] } + +@test "register a covered service" { + WORKDIR=$PWD + cd $WORKDIR/samples/run_for_several_seconds + + run goc build --debug --center=http://127.0.0.1:60001 + [ "$status" -eq 0 ] + ./simple-project 3>&- & + sleep 1 + # connect to covered goc + run goc profile --center=http://127.0.0.1:60001 + [ "$status" -eq 0 ] +} \ No newline at end of file