/
artifacts.go
39 lines (30 loc) · 1.18 KB
/
artifacts.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
38
39
package helpers
import (
"fmt"
"os"
"path/filepath"
"strings"
ginkgoconfig "github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
)
type artifactsDirectoryConfig interface {
GetArtifactsDirectory() string
}
func EnableCFTrace(config artifactsDirectoryConfig, componentName string) {
os.Setenv("CF_TRACE", traceLogFilePath(config, componentName))
}
func NewJUnitReporter(config artifactsDirectoryConfig, componentName string) *reporters.JUnitReporter {
return reporters.NewJUnitReporter(jUnitReportFilePath(config, componentName))
}
func traceLogFilePath(config artifactsDirectoryConfig, componentName string) string {
return filepath.Join(config.GetArtifactsDirectory(), fmt.Sprintf("CATS-TRACE-%s-%d.txt", sanitizeComponentName(componentName), ginkgoNode()))
}
func jUnitReportFilePath(config artifactsDirectoryConfig, componentName string) string {
return filepath.Join(config.GetArtifactsDirectory(), fmt.Sprintf("junit-%s-%d.xml", sanitizeComponentName(componentName), ginkgoNode()))
}
func ginkgoNode() int {
return ginkgoconfig.GinkgoConfig.ParallelNode
}
func sanitizeComponentName(componentName string) string {
return strings.Replace(componentName, " ", "_", -1)
}