Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Support for custom types + StepParam type #682

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tigh-latte
Copy link
Member

🤔 What's changed?

Add a new supported type to step definitions, being:

  • Any type that is structured ontop of another supported type:
type MyCustomInt int
  • any type that implements StepParam:
type TestFile string

func (t *TestFile) LoadParam(ctx context.Context) (string, error) {}

⚡️ What's your motivation?

We make fairly heavy use of files for test data, along with fairly heavy use of go's template engine for our inputs and file content. This, while working well, has resulted in basically every single step we define having to start with one or more of a few common function calls:

func iExpectXToMatchY(ctx context.Context, x string, y string) error {
    rendered, err := loadAndRenderTestFile(y)
    if err != nil { /* you know how it goes */ }

    // assert that x == y
}

Which, while fine, is duplication that we've had to change a few times before. Combine this with not all templated input being files to be loaded, and you get a fair amount of duplicated boilerplate that eventually the nodupl linter complains about.

Ideally, this would be automatic while also being more declarative:

func iExpectXToMatchY(ctx context.Context, x string, y TestTemplateFile) error {
    //assert that x == string(y)
}

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

Naming, new type placement, and general opinions on the feature would be good (such as, do we even want support for customer non-struct types?).

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

@tigh-latte tigh-latte requested a review from vearutop March 19, 2025 23:00
@tigh-latte tigh-latte force-pushed the enhancement/custom-types branch from d471f33 to 99c6b99 Compare March 19, 2025 23:04
Copy link

codecov bot commented Mar 19, 2025

Codecov Report

Attention: Patch coverage is 93.18182% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.97%. Comparing base (153db4e) to head (e11eb8d).
Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
internal/models/stepdef.go 93.02% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #682      +/-   ##
==========================================
- Coverage   83.21%   77.97%   -5.25%     
==========================================
  Files          28       41      +13     
  Lines        3413     4081     +668     
==========================================
+ Hits         2840     3182     +342     
- Misses        458      780     +322     
- Partials      115      119       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant