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

Use the idiomatic testdata folder #23

Merged
merged 3 commits into from
Jun 28, 2021
Merged

Use the idiomatic testdata folder #23

merged 3 commits into from
Jun 28, 2021

Conversation

hjwk
Copy link
Contributor

@hjwk hjwk commented Jun 19, 2021

Solves #16

@emilybache
Copy link
Contributor

I suspect this change will break people's existing test suites. I think we need to make the folder you put approved files in configurable as it is in other language versions like python.

@hjwk
Copy link
Contributor Author

hjwk commented Jun 21, 2021

Ah yes, I had totally forgotten about that aspect. Then I will try to do as you suggest.

hjwk added 2 commits June 21, 2021 19:38
The legacy behavior (i.e. no folder) will be kept as default
for compatibility reasons. Use of a subfolder is made possible
by the addition of a new 'UseFolder' configuration function.
@hjwk
Copy link
Contributor Author

hjwk commented Jun 21, 2021

I looked at Python's implementation and I was not really a fan of using a .json file as config so I tried to reuse the idea behind the UseReporter() function.

So to use a subfolder you either need to specify it in each Test function or use a TestMain()

content, err := ioutil.ReadFile(approvedPath)
func printFileContent(filepath string) {
approvedPath := strings.Replace(filepath, ".received.", ".approved.", 1)
content, err := ioutil.ReadFile(path.Join("testdata", approvedPath))
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this hardcoded "testdata" should refer instead to approvals.defaultFolder ?

Copy link
Contributor Author

@hjwk hjwk Jun 23, 2021

Choose a reason for hiding this comment

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

it is actually a bit more complicated because this file is in the approvals_test package, so it should not have access to defaultFolder. So I will revert these changes,

@emilybache
Copy link
Contributor

Thanks, this is better. Just that one comment if you could look at it?

@emilybache emilybache merged commit df28ede into approvals:master Jun 28, 2021
@emilybache
Copy link
Contributor

Thankyou!

@hjwk hjwk deleted the testdata_folder branch June 28, 2021 08:21
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.

2 participants