diff --git a/pkg/build/build.go b/pkg/build/build.go index 48bae22..01ad30b 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -96,11 +96,9 @@ func (b *Build) Build() error { log.Printf("go build cmd is: %v", cmd.Args) err := cmd.Start() if err != nil { - log.Errorf("Fail to execute: %v. The error is: %v", cmd.Args, err) return fmt.Errorf("fail to execute: %v, err: %w", cmd.Args, err) } if err = cmd.Wait(); err != nil { - log.Errorf("go build failed. The error is: %v", err) return fmt.Errorf("fail to execute: %v, err: %w", cmd.Args, err) } log.Infoln("Go build exit successful.") @@ -111,7 +109,6 @@ func (b *Build) Build() error { // the binary name is always same as the directory name of current directory func (b *Build) determineOutputDir(outputDir string) (string, error) { if b.TmpDir == "" { - log.Errorf("Can only be called after Build.MvProjectsToTmp(): %v", ErrWrongCallSequence) return "", fmt.Errorf("can only be called after Build.MvProjectsToTmp(): %w", ErrWrongCallSequence) } @@ -119,8 +116,8 @@ func (b *Build) determineOutputDir(outputDir string) (string, error) { if outputDir != "" { abs, err := filepath.Abs(outputDir) if err != nil { - log.Errorf("Fail to transform the path: %v to absolute path: %v", outputDir, err) - return "", err + return "", fmt.Errorf("Fail to transform the path: %v to absolute path: %v", outputDir, err) + } return abs, nil } diff --git a/tests/build.bats b/tests/build.bats index c9698ea..e2f17a0 100755 --- a/tests/build.bats +++ b/tests/build.bats @@ -29,18 +29,48 @@ teardown_file() { kill -9 $GOC_PID } +setup() { + goc init +} + @test "test basic goc build command" { cd samples/run_for_several_seconds - wait_profile_backend "build1" + + wait_profile_backend "build1" & + profile_pid=$! + run gocc build --debug --debugcisyncfile ci-sync.bak; - info build output: $output + info build1 output: $output [ "$status" -eq 0 ] + + wait $profile_pid } @test "test goc build command without debug" { cd samples/run_for_several_seconds - wait_profile_backend "build2" + + wait_profile_backend "build2" & + profile_pid=$! + run gocc build --debugcisyncfile ci-sync.bak; - info build output: $output + info build2 output: $output [ "$status" -eq 0 ] + + wait $profile_pid +} + +@test "test goc build in GOPATH project" { + info $PWD + export GOPATH=$PWD/samples/simple_gopath_project + export GO111MODULE=off + cd samples/simple_gopath_project/src/qiniu.com/simple_gopath_project + + wait_profile_backend "build3" & + profile_pid=$! + + run gocc build --buildflags="-v" --debug --debugcisyncfile ci-sync.bak; + info build3 output: $output + [ "$status" -eq 0 ] + + wait $profile_pid } \ No newline at end of file diff --git a/tests/clear.bats b/tests/clear.bats index 453924c..24583c7 100755 --- a/tests/clear.bats +++ b/tests/clear.bats @@ -44,19 +44,25 @@ teardown_file() { } @test "test basic goc clear command" { - wait_profile_backend "clear1" + wait_profile_backend "clear1" & + profile_pid=$! run gocc clear --debug --debugcisyncfile ci-sync.bak; info clear1 output: $output [ "$status" -eq 0 ] - [[ "$output" == *"coverage counter clear call successfully"* ]] + [[ "$output" == *""* ]] + + wait $profile_pid } @test "test clear another center" { - wait_profile_backend "clear2" + wait_profile_backend "clear2" & + profile_pid=$! run gocc clear --center=http://127.0.0.1:60001 --debug --debugcisyncfile ci-sync.bak; info clear2 output: $output [ "$status" -eq 0 ] [[ "$output" == *"coverage counter clear call successfully"* ]] + + wait $profile_pid } \ No newline at end of file diff --git a/tests/cover.bats b/tests/cover.bats index fce90e9..dc02751 100755 --- a/tests/cover.bats +++ b/tests/cover.bats @@ -35,9 +35,16 @@ teardown_file() { kill -9 $GOC_PID } +setup() { + goc init +} + @test "test basic goc cover command" { cd test-temp - wait_profile_backend "cover1" + + wait_profile_backend "cover1" & + profile_pid=$! + run gocc cover --debug --debugcisyncfile ci-sync.bak; info cover1 output: $output [ "$status" -eq 0 ] @@ -46,4 +53,6 @@ teardown_file() { info ls output: $output [ "$status" -eq 0 ] [[ "$output" == *"http_cover_apis_auto_generated.go"* ]] + + wait $profile_pid } diff --git a/tests/diff.bats b/tests/diff.bats index dd96f15..fb8e653 100755 --- a/tests/diff.bats +++ b/tests/diff.bats @@ -29,41 +29,53 @@ teardown_file() { kill -9 $GOC_PID } +setup() { + goc init +} + @test "test basic goc diff command" { cd samples/diff_samples - wait_profile_backend "diff1" - + wait_profile_backend "diff1" & + profile_pid=$! run gocc diff --new-profile=./new.voc --base-profile=./base.voc --debug --debugcisyncfile ci-sync.bak; - info list output: $output + info diff1 output: $output [ "$status" -eq 0 ] [[ "$output" == *"qiniu.com/kodo/apiserver/server/main.go | 50.0% | 100.0% | 50.0%"* ]] [[ "$output" == *"Total | 50.0% | 100.0% | 50.0%"* ]] + + wait $profile_pid } @test "test diff in prow environment with periodic job" { cd samples/diff_samples - wait_profile_backend "diff2" + wait_profile_backend "diff2" & + profile_pid=$! export JOB_TYPE=periodic - run gocc diff --new-profile=./new.voc --prow-postsubmit-job=base --debug --debugcisyncfile ci-sync.bak; - info diff1 output: $output - [ "$status" -eq 0 ] - [[ "$output" == *"do nothing"* ]] -} - -@test "test diff in prow environment with postsubmit job" { - cd samples/diff_samples - - wait_profile_backend "diff3" - - export JOB_TYPE=postsubmit - run gocc diff --new-profile=./new.voc --prow-postsubmit-job=base --debug --debugcisyncfile ci-sync.bak; info diff2 output: $output [ "$status" -eq 0 ] [[ "$output" == *"do nothing"* ]] + + wait $profile_pid +} + +@test "test diff in prow environment with postsubmit job" { + cd samples/diff_samples + + wait_profile_backend "diff3" & + profile_pid=$! + + export JOB_TYPE=postsubmit + + run gocc diff --new-profile=./new.voc --prow-postsubmit-job=base --debug --debugcisyncfile ci-sync.bak; + info diff3 output: $output + [ "$status" -eq 0 ] + [[ "$output" == *"do nothing"* ]] + + wait $profile_pid } \ No newline at end of file diff --git a/tests/init.bats b/tests/init.bats index 68dc03b..0bb5d9d 100755 --- a/tests/init.bats +++ b/tests/init.bats @@ -44,9 +44,12 @@ teardown_file() { } @test "test init command" { - wait_profile_backend "init1" + wait_profile_backend "init1" & + profile_pid=$! run gocc init --center=http://127.0.0.1:60001 --debug --debugcisyncfile ci-sync.bak; info init output: $output [ "$status" -eq 0 ] + + wait $profile_pid } \ No newline at end of file diff --git a/tests/install.bats b/tests/install.bats index 3b4c321..dc4252d 100755 --- a/tests/install.bats +++ b/tests/install.bats @@ -29,13 +29,22 @@ teardown_file() { kill -9 $GOC_PID } +setup() { + goc init +} + @test "test basic goc install command" { info $PWD export GOPATH=$PWD/samples/simple_gopath_project export GO111MODULE=off cd samples/simple_gopath_project/src/qiniu.com/simple_gopath_project - wait_profile_backend "install" + + wait_profile_backend "install" & + profile_pid=$! + run gocc install --debug --debugcisyncfile ci-sync.bak; info install output: $output [ "$status" -eq 0 ] + + wait $profile_pid } diff --git a/tests/list.bats b/tests/list.bats index 76284fe..7e9c5da 100755 --- a/tests/list.bats +++ b/tests/list.bats @@ -36,11 +36,14 @@ teardown_file() { } @test "test basic goc list command" { - wait_profile_backend "list" + wait_profile_backend "list" & + profile_pid=$! run gocc list --debug --debugcisyncfile ci-sync.bak; info list output: $output [ "$status" -eq 0 ] [[ "$output" == *"gocc"* ]] [[ "$output" == *"http"* ]] + + wait $profile_pid } \ No newline at end of file diff --git a/tests/profile.bats b/tests/profile.bats index fa76a32..6dfbd30 100755 --- a/tests/profile.bats +++ b/tests/profile.bats @@ -27,6 +27,10 @@ setup_file() { GOCC_PID=$! sleep 1 + WORKDIR=$PWD + cd samples/run_for_several_seconds + goc build --center=http://127.0.0.1:60001 + info "goc server started" } @@ -35,19 +39,41 @@ teardown_file() { kill -9 $GOCC_PID } -@test "test goc profile to stdout" { - wait_profile_backend "profile1" +setup() { + goc init --center=http://127.0.0.1:60001 + goc init +} - run gocc profile --debug --debugcisyncfile ci-sync.bak; +@test "test goc profile to stdout" { + ./simple-project 3>&- & + SAMPLE_PID=$! + sleep 2 + + wait_profile_backend "profile1" & + profile_pid=$! + + run gocc profile --center=http://127.0.0.1:60001 --debug --debugcisyncfile ci-sync.bak + info $output [ "$status" -eq 0 ] [[ "$output" == *"mode: count"* ]] + + wait $profile_pid + kill -9 $SAMPLE_PID } @test "test goc profile to file" { - wait_profile_backend "profile2" + ./simple-project 3>&- & + SAMPLE_PID=$! + sleep 2 - run gocc profile -o test-profile.bak --debug --debugcisyncfile ci-sync.bak; + wait_profile_backend "profile2" & + profile_pid=$! + + run gocc profile --center=http://127.0.0.1:60001 -o test-profile.bak --debug --debugcisyncfile ci-sync.bak; [ "$status" -eq 0 ] run cat test-profile.bak [[ "$output" == *"mode: count"* ]] + + wait $profile_pid + kill -9 $SAMPLE_PID } \ No newline at end of file diff --git a/tests/register.bats b/tests/register.bats index 058234c..6f5d089 100755 --- a/tests/register.bats +++ b/tests/register.bats @@ -35,20 +35,31 @@ teardown_file() { kill -9 $GOCC_PID } +# we need to catch gocc server, so no init +# setup() { +# goc init +# } + @test "test basic goc register command" { - wait_profile_backend "register1" + wait_profile_backend "register1" & + profile_pid=$! run gocc register --center=http://127.0.0.1:60001 --name=xyz --address=http://137.0.0.1:666 --debug --debugcisyncfile ci-sync.bak; - info register output: $output + info register1 output: $output [ "$status" -eq 0 ] [[ "$output" == *"success"* ]] + + wait $profile_pid } @test "test goc register without port" { - wait_profile_backend "register2" + wait_profile_backend "register2" & + profile_pid=$! run gocc register --center=http://127.0.0.1:60001 --name=xyz --address=http://137.0.0.1 --debug --debugcisyncfile ci-sync.bak; - info register output: $output + info register2 output: $output [ "$status" -eq 0 ] [[ "$output" == *"missing port"* ]] -} \ No newline at end of file + + wait $profile_pid +} diff --git a/tests/run.bats b/tests/run.bats index 026a64f..81ba27e 100755 --- a/tests/run.bats +++ b/tests/run.bats @@ -34,10 +34,14 @@ teardown_file() { export GOPATH=$PWD/samples/simple_gopath_project export GO111MODULE=off cd samples/simple_gopath_project/src/qiniu.com/simple_gopath_project - wait_profile_backend "run1" + + wait_profile_backend "run1" & + profile_pid=$! run gocc run . --debug --debugcisyncfile ci-sync.bak; info run output: $output [ "$status" -eq 0 ] [[ "$output" == *"hello, world."* ]] + + wait $profile_pid } \ No newline at end of file diff --git a/tests/util.sh b/tests/util.sh index d59d0d8..950c3b5 100644 --- a/tests/util.sh +++ b/tests/util.sh @@ -22,7 +22,8 @@ wait_profile() { local timeout=10 until [[ ${n} -ge ${timeout} ]] do - # check whether the target port is listened by specific process + LS=`ls` + info $1, $LS if [[ -f ci-sync.bak ]]; then break fi @@ -31,9 +32,10 @@ wait_profile() { done # collect from center goc profile -o filtered-$1.cov + info "done $1 collect" } wait_profile_backend() { rm ci-sync.bak || true - coproc { wait_profile $1; } + wait_profile $1 } \ No newline at end of file diff --git a/tests/version.bats b/tests/version.bats index 4323a2c..a4adfe2 100755 --- a/tests/version.bats +++ b/tests/version.bats @@ -35,8 +35,11 @@ teardown_file() { } @test "test basic goc version command" { - wait_profile_backend "version" + wait_profile_backend "version" & + profile_pid=$! run gocc version --debug --debugcisyncfile ci-sync.bak; [ "$output" = "(devel)" ] + + wait $profile_pid } \ No newline at end of file