theStandardErrorShouldContain looks at the standard error (stderr) of the last invoked ec command and compares the expected error with the resulted error.
(ctx context.Context, expected *godog.DocString)
| 536 | // theStandardErrorShouldContain looks at the standard error (stderr) of the last invoked ec |
| 537 | // command and compares the expected error with the resulted error. |
| 538 | func theStandardErrorShouldContain(ctx context.Context, expected *godog.DocString) error { |
| 539 | status, err := ecStatusFrom(ctx) |
| 540 | if err != nil { |
| 541 | return err |
| 542 | } |
| 543 | |
| 544 | if expected == nil { |
| 545 | return errors.New("must provide expected error") |
| 546 | } |
| 547 | |
| 548 | expectedStdErr := os.Expand(expected.Content, func(key string) string { |
| 549 | return status.vars[key] |
| 550 | }) |
| 551 | |
| 552 | stderr := status.stderr.String() |
| 553 | |
| 554 | // shortcut, if the output is exactly as expected |
| 555 | if stderr == expectedStdErr { |
| 556 | return nil |
| 557 | } |
| 558 | |
| 559 | if matched, err := regexp.MatchString(expectedStdErr, stderr); matched && err == nil { |
| 560 | return nil |
| 561 | } |
| 562 | |
| 563 | var b bytes.Buffer |
| 564 | if diffErr := diff.Text("stderr", "expected", status.stderr, expectedStdErr, &b); diffErr != nil { |
| 565 | return fmt.Errorf("expected error:\n%s\nnot found in standard error:\n%s", expectedStdErr, stderr) |
| 566 | } |
| 567 | |
| 568 | return fmt.Errorf("expected and actual stderr differ:\n%s", b.String()) |
| 569 | } |
| 570 | |
| 571 | // theStandardOutputShouldMatchBaseline reads the expected text from a file instead of directly |
| 572 | // from the feature file |
nothing calls this directly
no test coverage detected