Atlas › Test

TestRunnerReportCrash

Exact test identity: go.temporal.io/server/tools/testrunner/TestRunnerReportCrash

Package
go.temporal.io/server/tools/testrunner
Suite / test hierarchy
TestRunnerReportCrash
Test
TestRunnerReportCrash
Introduced at
testrunner.go ×2 Frontier kind: Joint frontier
Covered ranges
25
Covered lines
69
Covered files
2

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/tools/testrunner/junit.go 35 covered LOC · 5 ranges

Open complete file

56 // canonical failure type (for example TIMEOUT or CRASH), and Failure.Data is
57 // intentionally left empty.
58 > func generateReport(names []string, suffix string, kind failureType) *junitReport { junit.go
59 > var testcases []junit.Testcase
60 > for _, name := range names {
61 > testcases = append(testcases, junit.Testcase{
62 > Name: fmt.Sprintf("%s (%s)", name, suffix),
63 > Failure: generateFailure(kind, ""),
64 > })
65 > }
66 > return &junitReport{
67 > Testsuites: junit.Testsuites{
68 > Suites: []junit.Testsuite{
69 > {
70 > Name: "suite",
71 > Testcases: testcases,
72 > },
73 > },
74 > },
75 > }
76 }
77
78 > func generateFailure(kind failureType, data string) *junit.Result { junit.go
79 > return &junit.Result{
80 > Message: string(kind),
81 > Type: string(kind),
82 > Data: data,
83 > }
84 > }
85
86 > func (j *junitReport) write() error { junit.go
87 > f, err := os.Create(j.path)
88 > if err != nil {
89 return fmt.Errorf("failed to open junit report file: %w", err)
90 }
91 > defer f.Close() junit.go
92 >
93 > encoder := xml.NewEncoder(f)
94 > encoder.Indent("", " ")
95 > if err = encoder.Encode(j.Testsuites); err != nil {
96 return fmt.Errorf("failed to write junit report file: %w", err)
97 }
98 > log.Printf("wrote junit report to %s", j.path) junit.go
99 > return nil
100 }
101
go.temporal.io/server/tools/testrunner/testrunner.go 34 covered LOC · 20 ranges

Open complete file

81 }
82
83 > func newRunner() *runner { testrunner.go
84 > return &runner{
85 > attempts: make([]*attempt, 0),
86 > maxAttempts: 1,
87 > }
88 > }
89
90 // nolint:revive,cognitive-complexity
91 > func (r *runner) sanitizeAndParseArgs(command string, args []string) ([]string, error) { testrunner.go
92 > var sanitizedArgs []string
93 > for _, arg := range args {
94 > if strings.HasPrefix(arg, maxAttemptsFlag) { testrunner.go
95 var err error
96 r.maxAttempts, err = strconv.Atoi(strings.Split(arg, "=")[1])
104 }
105
106 > if strings.HasPrefix(arg, totalTimeoutFlag) { testrunner.go
107 var err error
108 r.totalTimeout, err = time.ParseDuration(strings.TrimPrefix(arg, totalTimeoutFlag))
116 }
117
118 > if strings.HasPrefix(arg, gotestsumPathFlag) { testrunner.go
119 r.gotestsumPath = strings.Split(arg, "=")[1]
120 continue
121 }
122
123 > if strings.HasPrefix(arg, crashReportNameFlag) { testrunner.go
124 > r.crashName = strings.Split(arg, "=")[1] testrunner.go
125 > if r.crashName == "" {
126 return nil, fmt.Errorf("invalid argument %q: must not be empty", crashReportNameFlag)
127 }
128 > if command != crashReportCommand { testrunner.go
129 return nil, fmt.Errorf("argument %q is only valid for command %q", crashReportNameFlag, crashReportCommand)
130 }
131 > continue // this is a `testrunner` only arg and not passed through testrunner.go
132 }
133
134 > if strings.HasPrefix(arg, junitGlobFlag) { testrunner.go
135 r.junitGlob = strings.Split(arg, "=")[1]
136 continue
137 }
138 > if strings.HasPrefix(arg, summaryOutputDirFlag) { testrunner.go
139 r.summaryOutputDir = strings.Split(arg, "=")[1]
140 if command != summaryCommand {
143 continue
144 }
145 > if strings.HasPrefix(arg, coverProfileFlag) { testrunner.go
146 r.coverProfilePath = strings.Split(arg, "=")[1]
147 > } else if strings.HasPrefix(arg, junitReportFlag) { testrunner.go
148 > // --junitfile is used by gotestsum testrunner.go
149 > r.junitOutputPath = strings.Split(arg, "=")[1]
150 > }
151
152 > sanitizedArgs = append(sanitizedArgs, arg) testrunner.go
153 }
154
155 > switch command { testrunner.go
156 case testCommand:
157 if r.coverProfilePath == "" {
164 return nil, fmt.Errorf("missing required argument %q", gotestsumPathFlag)
165 }
166 > case crashReportCommand: testrunner.go
167 > if r.junitOutputPath == "" {
168 return nil, fmt.Errorf("missing required argument %q", junitReportFlag)
169 }
170 > if r.crashName == "" { testrunner.go
171 return nil, fmt.Errorf("missing required argument %q", crashReportNameFlag)
172 }
182 }
183
184 > return sanitizedArgs, nil testrunner.go
185 }
186
248
249 // nolint:revive,deep-exit
250 > func (r *runner) reportCrash() { testrunner.go
251 > jr := generateReport([]string{r.crashName}, "crash", failureTypeCrash)
252 > jr.path = r.junitOutputPath
253 > if err := jr.write(); err != nil {
254 log.Fatal(err)
255 }