(res harness.Results, stdout io.Writer)
| 267 | } |
| 268 | |
| 269 | func (o *scaleTestOutput) write(res harness.Results, stdout io.Writer) error { |
| 270 | var ( |
| 271 | w = stdout |
| 272 | c io.Closer |
| 273 | ) |
| 274 | if o.path != "-" { |
| 275 | f, err := os.Create(o.path) |
| 276 | if err != nil { |
| 277 | return xerrors.Errorf("create output file: %w", err) |
| 278 | } |
| 279 | w, c = f, f |
| 280 | } |
| 281 | |
| 282 | switch o.format { |
| 283 | case scaleTestOutputFormatText: |
| 284 | res.PrintText(w) |
| 285 | case scaleTestOutputFormatJSON: |
| 286 | err := json.NewEncoder(w).Encode(res) |
| 287 | if err != nil { |
| 288 | return xerrors.Errorf("encode JSON: %w", err) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | // Sync the file to disk if it's a file. |
| 293 | if s, ok := w.(interface{ Sync() error }); ok { |
| 294 | // Best effort. If we get an error from syncing, just ignore it. |
| 295 | _ = s.Sync() |
| 296 | } |
| 297 | |
| 298 | if c != nil { |
| 299 | err := c.Close() |
| 300 | if err != nil { |
| 301 | return xerrors.Errorf("close output file: %w", err) |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return nil |
| 306 | } |
| 307 | |
| 308 | type scaletestOutputFlags struct { |
| 309 | outputSpecs []string |
no test coverage detected