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

Add support for loading features from fs.FS #146

Merged
merged 9 commits into from
Aug 23, 2022

Conversation

sagikazarmark
Copy link
Collaborator

@sagikazarmark sagikazarmark commented Jul 31, 2022

This PR adds backward compatible support for loading features from alternative sources (like fs.FS filesystems).

Fixes #143

TODO

  • Update documentation

gobdd_go1_16.go Outdated

// WithFeaturesFS configures a filesystem and a pattern (regexp) where features can be found.
// An empty path defaults to "*.feature"
func WithFeaturesFS(fs fs.FS, pattern string) func(*SuiteOptions) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a separate function that doesn't require a pattern? Might be slightly better than having to pass an empty string as a second parameter.

"github.com/go-bdd/gobdd/features"
)

func TestWithFeaturesFS(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas for better tests?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test is OK. I have some thoughts about the API (see commend below).

@sagikazarmark sagikazarmark requested a review from bkielbasa July 31, 2022 15:28
Copy link
Collaborator

@bkielbasa bkielbasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prise: thanks for your PR!

"github.com/go-bdd/gobdd/features"
)

func TestWithFeaturesFS(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test is OK. I have some thoughts about the API (see commend below).

)

func TestWithFeaturesFS(t *testing.T) {
suite := NewSuite(t, WithFeaturesFS(features.Features(), "example.feature"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: if the pattern is optional, we can make it truly optional. I can see a few options.

  1. use the WithXYZ pattern
suite := NewSuite(t, WithFeaturesFS(features.Features(), WithPattern("example.feature")))
  1. Make the pattern to be a slice and allow to put multiple (or zero) patterns
suite := NewSuite(t, WithFeaturesFS(features.Features(), "example1.feature", "example2.feature", "example3.feature"))
  1. Allow providing any io.Reader
suite := NewSuite(t, WithFeaturesFS(reader))

If you have any other ideas, pls let me know. For now, I'd prefer the second or third option.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think option three is the same concept. (For that we could make the featureSource interface public at some point)

Pattern is not optional, but it (currently) falls back to *.feature which means all feature files.

Maybe it's easier to just make it a mandatory parameter?

suite := NewSuite(t, WithFeaturesFS(features.Features(), "*.feature"))

features/features.go Outdated Show resolved Hide resolved
… sources

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
@bkielbasa
Copy link
Collaborator

I thought about the PR and I think I don't have a better idea. I have one more request for you - could you update the docs as well? I'd be useful for others to find out about the new feature :)

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
@sagikazarmark
Copy link
Collaborator Author

After some thinking, I decided to make the pattern/path parameter mandatory without fallback. Implicit behavior is always harder to understand for the reader.

Having to spell out *.feature in WithFeaturesFS(features.Features(), "*.feature") every time is not a big deal (and that's how it works with the current WithFeaturesPath anyway).

I also added some docs as requested.

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Copy link
Collaborator

@bartlomiej-klimczak-cko bartlomiej-klimczak-cko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomiej-klimczak-cko bartlomiej-klimczak-cko merged commit 2911ec3 into master Aug 23, 2022
@bartlomiej-klimczak-cko bartlomiej-klimczak-cko deleted the features-fs branch August 23, 2022 16:17
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.

Add WithFeaturesFS to use embedded feature files
3 participants