-
Notifications
You must be signed in to change notification settings - Fork 0
/
testutils.go
37 lines (33 loc) · 968 Bytes
/
testutils.go
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
29
30
31
32
33
34
35
36
37
package testutils
import (
"fmt"
"os"
"regexp"
"runtime"
"testing"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
. "github.com/onsi/gomega"
)
// RegisterAndRun setup and run Ginkgo tests
func RegisterAndRun(t *testing.T) {
_, suitePath, _, _ := runtime.Caller(1)
RegisterFailHandler(Fail)
reportPath := os.Getenv("JUNIT_REPORT_DIR")
if reportPath != "" {
name := regexp.MustCompile("[^a-zA-Z0-9]+").ReplaceAllString(suitePath, "__")
reportPath := fmt.Sprintf("%s/%s_%d.xml", reportPath, name, config.GinkgoConfig.ParallelNode)
fmt.Printf("test result output: %s\n", reportPath)
junitReporter := reporters.NewJUnitReporter(reportPath)
RunSpecsWithDefaultAndCustomReporters(t, suitePath, []Reporter{junitReporter})
} else {
RunSpecs(t, suitePath)
}
}
// SkipCI test if CI is enabled
func SkipCI(t *testing.T) {
if os.Getenv("CI") != "" {
t.Skip("Skipping testing in CI environment")
}
}