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

Load fixtures from http.FileSystem to support files bundled with packr #49

Open
stoewer opened this issue May 23, 2019 · 4 comments
Open
Labels

Comments

@stoewer
Copy link

stoewer commented May 23, 2019

For some testing scenarios it can be handy to generate a binary that is able to populate it's own test database. A prerequisite for this is to bundle the fixture files with the binary. One possible way to do so is packr. But there is no straightforward way to make the bundled files available for the testfixtures package.

Luckily packr implements http.FileSystem in order to represent the bundled files in the binary. I therefore suggest to add the following functions to testfixtures:

func NewFileSystem(db *sql.DB, helper Helper, fs http.FileSystem) (*Context, error) 
func LoadFixtureFileSystem(db *sql.DB, helper Helper, fs http.FileSystem) error

This would allow testfixtures to work together with packr or other sources for fixture files that implement the http.FileSystem interface.

@stoewer
Copy link
Author

stoewer commented May 24, 2019

If I could get some 👍 from the maintainers I would be willing to work on this feature.

@andreynering
Copy link
Contributor

Hi @stoewer,

I used embedding tools like fileb0x a lot, but for production stuff like assets and HTML templates. I found it very curious that you want to use it for testing stuff.

I have no opposition to adding a function that accepts http.FileSystem, though. I'd be happy to review a pull request for it. 🙂

Something to keep in mind is that it may be necessary to add an additional directory parameter to that function, otherwise users won't be able to load fixtures if they're not in the root directory.

@stoewer
Copy link
Author

stoewer commented Jun 14, 2019

I discovered a bug in packr while implementing this feature #211. I'll suspend the development until it get's fixed.

@andreynering
Copy link
Contributor

Perhaps we should wait to do this now that the Go team is discussing embed assets support in Go itself?

Once that is released, it will become the default way of embedding assets in Go, and so we should follow its pattern.

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

No branches or pull requests

2 participants