-
Notifications
You must be signed in to change notification settings - Fork 16
/
report.go
90 lines (78 loc) · 3.19 KB
/
report.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
package report
import (
"time"
"github.com/saucelabs/saucectl/internal/junit"
)
// Attempt represents a single attempt of a job.
type Attempt struct {
// ID is the unique identifier of the attempt. This is usually the job ID.
// Can also be the runner ID (imagerunner) or whatever is used to identify
// the attempt in the context of the job.
ID string `json:"id"`
Duration time.Duration `json:"duration"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"`
Status string `json:"status"`
// TestSuites contains the junit test suites that were generated as part of
// the attempt.
TestSuites junit.TestSuites `json:"-"`
}
// TestResult represents the test result.
type TestResult struct {
Name string `json:"name"`
Duration time.Duration `json:"duration"`
StartTime time.Time `json:"startTime"`
EndTime time.Time `json:"endTime"`
Status string `json:"status"`
Browser string `json:"browser,omitempty"`
Platform string `json:"platform"`
DeviceName string `json:"deviceName,omitempty"`
URL string `json:"url,omitempty"`
Artifacts []Artifact `json:"artifacts,omitempty"`
Origin string `json:"origin,omitempty"`
BuildURL string `json:"buildURL,omitempty"`
RunID string `json:"runID,omitempty"`
RDC bool `json:"-"`
TimedOut bool `json:"-"`
PassThreshold bool `json:"-"`
Attempts []Attempt `json:"-"`
}
// ArtifactType represents the type of assets (e.g. a junit report). Semantically similar to Content-Type.
type ArtifactType int
const (
// Unknown represents an asset with an unknown purpose that isn't further defined.
Unknown ArtifactType = iota
// JUnitArtifact represents the junit artifact type (https://llg.cubic.org/docs/junit/).
JUnitArtifact
)
// Artifact represents an artifact (aka asset) that was generated as part of a job.
type Artifact struct {
FilePath string `json:"filePath,omitempty"`
AssetType ArtifactType `json:"-"`
Body []byte `json:"-"`
// Error contains optional error information in case the artifact was not retrieved.
Error error `json:"-"`
}
// Reporter is the interface for rest result reporting.
type Reporter interface {
// Add adds the TestResult to the reporter. TestResults added this way can then be rendered out by calling Render().
Add(t TestResult)
// Render renders the test results. The destination depends on the implementation.
Render()
// Reset resets the state of the reporter (e.g. remove any previously reported TestResults).
Reset()
// ArtifactRequirements returns a list of artifact types that this reporter requires to create a proper report.
ArtifactRequirements() []ArtifactType
}
// IsArtifactRequired traverses the list of reporters and validates their requirements against the given artifact type.
// Returns true if at least one of the reporters has a matching requirement.
func IsArtifactRequired(reps []Reporter, at ArtifactType) bool {
for _, r := range reps {
for _, ar := range r.ArtifactRequirements() {
if ar == at {
return true
}
}
}
return false
}