testfixtures icon indicating copy to clipboard operation
testfixtures copied to clipboard

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

Open stoewer opened this issue 5 years ago • 4 comments

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 avatar May 23 '19 07:05 stoewer

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

stoewer avatar May 24 '19 13:05 stoewer

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.

andreynering avatar May 25 '19 00:05 andreynering

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

stoewer avatar Jun 14 '19 11:06 stoewer

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.

andreynering avatar Dec 07 '19 19:12 andreynering