From c00f871f80d479b8969d678c6db96e0bb5c594f5 Mon Sep 17 00:00:00 2001 From: jichangjun Date: Sat, 5 Sep 2020 16:27:23 +0800 Subject: [PATCH] add e2e for goc profile with coverfile flag --- pkg/cover/server.go | 2 +- tests/profile.bats | 20 +++++++++++++++++++ tests/samples/run_for_several_seconds/a/a.go | 6 ++++++ tests/samples/run_for_several_seconds/b/b.go | 6 ++++++ tests/samples/run_for_several_seconds/main.go | 5 +++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/samples/run_for_several_seconds/a/a.go create mode 100644 tests/samples/run_for_several_seconds/b/b.go diff --git a/pkg/cover/server.go b/pkg/cover/server.go index 1c11e92..e952d02 100644 --- a/pkg/cover/server.go +++ b/pkg/cover/server.go @@ -204,7 +204,7 @@ func filterProfile(coverFile []string, profiles []*cover.Profile) ([]*cover.Prof for _, pattern := range coverFile { matched, err := regexp.MatchString(pattern, profile.FileName) if err != nil { - return nil, fmt.Errorf("filterProfile failed with pattern %s for profile %s", pattern, profile.FileName) + return nil, fmt.Errorf("filterProfile failed with pattern %s for profile %s, err: %v", pattern, profile.FileName, err) } if matched { out = append(out, profile) diff --git a/tests/profile.bats b/tests/profile.bats index 6dfbd30..d4bc91e 100755 --- a/tests/profile.bats +++ b/tests/profile.bats @@ -74,6 +74,26 @@ setup() { run cat test-profile.bak [[ "$output" == *"mode: count"* ]] + wait $profile_pid + kill -9 $SAMPLE_PID +} + +@test "test goc profile with coverfile flag" { + ./simple-project 3>&- & + SAMPLE_PID=$! + sleep 2 + + wait_profile_backend "profile3" & + profile_pid=$! + + run gocc profile --center=http://127.0.0.1:60001 --coverfile="a.go$,b.go$" --debug --debugcisyncfile ci-sync.bak; + info $output + [ "$status" -eq 0 ] + [[ "$output" == *"mode: count"* ]] + [[ "$output" == *"a.go"* ]] # contains a.go file + [[ "$output" == *"b.go"* ]] # contains b.go file + [[ "$output" != *"main.go"* ]] # not contains main.go file + wait $profile_pid kill -9 $SAMPLE_PID } \ No newline at end of file diff --git a/tests/samples/run_for_several_seconds/a/a.go b/tests/samples/run_for_several_seconds/a/a.go new file mode 100644 index 0000000..6bd3ef3 --- /dev/null +++ b/tests/samples/run_for_several_seconds/a/a.go @@ -0,0 +1,6 @@ +package a + +// Say Hello A +func Say() { + println("Hello A") +} diff --git a/tests/samples/run_for_several_seconds/b/b.go b/tests/samples/run_for_several_seconds/b/b.go new file mode 100644 index 0000000..ff8954c --- /dev/null +++ b/tests/samples/run_for_several_seconds/b/b.go @@ -0,0 +1,6 @@ +package b + +// Say Hello B +func Say() { + println("Hello B") +} diff --git a/tests/samples/run_for_several_seconds/main.go b/tests/samples/run_for_several_seconds/main.go index f8e8cbc..c17eea6 100644 --- a/tests/samples/run_for_several_seconds/main.go +++ b/tests/samples/run_for_several_seconds/main.go @@ -3,9 +3,14 @@ package main import ( "fmt" "time" + + "example.com/simple-project/a" + "example.com/simple-project/b" ) func main() { fmt.Println("hello") + a.Say() + b.Say() time.Sleep(time.Second * 15) }