-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxctesthtmlreport.go
92 lines (74 loc) · 2.53 KB
/
xctesthtmlreport.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"bytes"
"fmt"
"net/http"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/log"
)
// InstallBranch is the selected source branch of the XCHTMLReport repository
type InstallBranch string
// enum SourceBranch
const (
Develop InstallBranch = "develop"
Master InstallBranch = "master"
)
const xcHTMLReportRepository string = "https://raw.githubusercontent.com/TitouanVanBelle/XCTestHTMLReport/%s/xchtmlreport.rb"
const xcHTMLReportInstallScriptURL string = "https://raw.githubusercontent.com/TitouanVanBelle/XCTestHTMLReport/master/install.sh"
const xcHTMLReportGithubOrg string = "TitouanVanBelle"
const xcHTMLReportGithubRepo string = "XCTestHTMLReport"
type xcTestHTMLReport struct {
verbose bool
generateJUnit bool
resultBundlePaths []string
version string
}
//
// Reciever methods
// Deprecated:
func (xcTestHTMLReport) installCmd(branch InstallBranch) *command.Model {
return command.New("brew", "install", fmt.Sprintf(xcHTMLReportRepository, branch))
}
func (xcTestHTMLReport) installViaScriptCmd(version string) *command.Model {
return command.New("/bin/sh", []string{"install.sh", version}...)
}
func (x xcTestHTMLReport) convertToHTMReportCmd() *command.Model {
return command.New("xchtmlreport", convertToHTMReportArgs(x)...)
}
// installScript returns the install script located on the master branch of the XCTestHTMLReport repository
// https://raw.githubusercontent.com/TitouanVanBelle/XCTestHTMLReport/master/install.sh
func (x xcTestHTMLReport) installScript() (string, error) {
resp, err := http.Get(xcHTMLReportInstallScriptURL)
if err != nil {
return "", fmt.Errorf("failed to call the %s, error: %v", xcHTMLReportInstallScriptURL, err)
}
log.Debugf("Response status: %s", resp.Status)
defer func() {
if cerr := resp.Body.Close(); err != nil {
log.Warnf("Failed to close response body of %s, error: %v", xcHTMLReportInstallScriptURL, cerr)
}
}()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("response status %v", resp.StatusCode)
}
buf := new(bytes.Buffer)
if _, err := buf.ReadFrom(resp.Body); err != nil {
return "", fmt.Errorf("failed to copy the response body to a buffer, error: %v", err)
}
return buf.String(), nil
}
//
// Private methods
func convertToHTMReportArgs(x xcTestHTMLReport) []string {
var args []string
for _, path := range x.resultBundlePaths {
args = append(args, []string{"-r", path}...)
}
if x.generateJUnit {
args = append(args, "-j")
}
if x.verbose {
args = append(args, "-v")
}
return args
}