cucumber / godog

Cucumber for golang
MIT License
2.32k stars 254 forks source link

added support for Attachments (aka Embedddings) #623

Closed Johnlon closed 6 months ago

Johnlon commented 6 months ago

πŸ€” What's changed?

The cucumber and events formatters support the inclusion of Attachments.

The proposed API is demonstrated in the tests as ...

func stepWithAttachment(ctx context.Context) (context.Context, error) {
    ctxOut := godog.Attach(ctx,
    godog.Attachment{Body: []byte("TheData1"), FileName: "TheFilename1", MediaType: "text/plain"},
    godog.Attachment{Body: []byte("TheData2"), FileName: "TheFilename2", MediaType: "text/plain"},
    )

    return ctxOut, nil
}

⚑️ What's your motivation?

https://github.com/cucumber/godog/issues/617

Want support for Attachments from steps. This PR proposes to use the context.Context object as a means to attach content from the step.

🏷️ What kind of change is this?

♻️ Anything particular you want feedback on?

This change involves minimal changes to patterns of use of godog API's.

I added tests for the cuke and events formats but the coverage isn't being recorded even on some lines I didn't modify.

fmt_output_test.go now has a normalise() fn that eliminates some extraneous diffs in the actual/expected files such as line endings and also line numbers so that the tests are easier to maintain and cross platform,

πŸ“‹ Checklist:

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 88.70968% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 79.69%. Comparing base (153db4e) to head (9de0ee7). Report is 8 commits behind head on main.

Files Patch % Lines
suite.go 81.25% 5 Missing and 1 partial :warning:
internal/models/results.go 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #623 +/- ## ========================================== - Coverage 83.21% 79.69% -3.52% ========================================== Files 28 40 +12 Lines 3413 3113 -300 ========================================== - Hits 2840 2481 -359 - Misses 458 513 +55 - Partials 115 119 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mattwynne commented 6 months ago

@Johnlon thanks for this, it looks great!

Are you able to take a look at why the build is failing? It seems to be just some noise from go fmt, maybe your editor has added some whitespace or something?

mattwynne commented 6 months ago

@Johnlon it would help the other maintainers if you could add an entry to the changelog as part of this PR. You can use this tool if you like, or just copy and adapt other existing entries.

Johnlon commented 6 months ago

@mattwynne thanks - will do. Still confused by the coverage problems. Any ideas? Cheers John

Johnlon commented 6 months ago

@Johnlon thanks for this, it looks great!

Are you able to take a look at why the build is failing? It seems to be just some noise from go fmt, maybe your editor has added some whitespace or something?

At go fmt sorry . Hmm will see if I can reverse??

Johnlon commented 6 months ago

@mattwynn Err Matt - I fixed the fmt issue and added the CHANGELOG - but it looks like I also merged to main (which wasn't my intention). Apols - please give it the once over. John

I see a put the CHANGELOG entry in the wrong please - please review this fix - https://github.com/cucumber/godog/pull/626

mattwynne commented 6 months ago

Hey @Johnlon no worries, looks like the build on main is green which is the main thing I was worried about, so all good.

As I said in the other thread, we favour Ship/Show/Ask in the Cucumber org, so feel free to merge your own PRs if you feel you've had enough feedback. Try and do it on purpose though! πŸ˜†

mattwynne commented 6 months ago

I really appreciate the work you've put into this, thanks!

Johnlon commented 6 months ago

No prob happy to help How do releases work? I mean is there some governance or Star chamber who decide? Or do I DIY here? Thanks

mattwynne commented 6 months ago

First things first, before thinking about a release, if you can make another PR with the changes @vearutop has suggested, then we'll have the code in the best shape we can get it.

Johnlon commented 6 months ago

@vearutop Hi - Take a look at my responses to your suggestions. PR raised here : https://github.com/cucumber/godog/pull/628