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

Test a seed that changes while an extraction is in progress #221

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

RyuzakiKK
Copy link
Contributor

This adds an automated tests for #220.

I added an environment variable in sequencer because that seemed the cleaner way to mock the Validate() function.
Please let me know if instead there is a better way to do that.

Comment on lines 175 to 177
// When targeting at least Go 1.17, we can replace the following with "t.Setenv()"
err := os.Setenv("DESYNC_MOCK_VALID_PLAN", "1")
t.Cleanup(func() { os.Unsetenv("DESYNC_MOCK_VALID_PLAN") })
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Go 1.17 introduced scoped env vars, so these two lines could be replaced with t.Setenv("DESYNC_MOCK_VALID_PLAN", "1")

Github VMs seems to include Go 1.17 now actions/runner-images#5280 but in go.mod the minimum Go version is the 1.15.
Probably not worth it to bump the Go version for just this minor improvement?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, it's definitely time to bump the min version to 1.17 since 1.18 is out already. Should also update the dependencies at that time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I don't use the environment variable anymore, we can probably bump the min version in a separate PR.

Comment on lines 175 to 177
// When targeting at least Go 1.17, we can replace the following with "t.Setenv()"
err := os.Setenv("DESYNC_MOCK_VALID_PLAN", "1")
t.Cleanup(func() { os.Unsetenv("DESYNC_MOCK_VALID_PLAN") })
Copy link
Owner

Choose a reason for hiding this comment

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

Yes, it's definitely time to bump the min version to 1.17 since 1.18 is out already. Should also update the dependencies at that time.

cmd/desync/extract_test.go Outdated Show resolved Hide resolved
sequencer.go Outdated
@@ -108,6 +108,10 @@ func (p Plan) Validate(ctx context.Context, n int, pb ProgressBar) (err error) {
in = make(chan Job)
fileMap = make(map[string]*os.File)
)
if mock := os.Getenv("DESYNC_MOCK_VALID_PLAN"); mock != "" {
Copy link
Owner

Choose a reason for hiding this comment

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

Not a fan of injecting testing variables via the environment. Let's think of alternatives:

  1. The test could move into the desync package rather than main. This would provide more control over what is mocked. One could use an interface with a testing-implementation, or a non-exported global variable that the test sets before running
  2. Exporting a variable that can be set from main. That's not ideal though.
    Any other ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestions!
I'll research a bit more about the possible solutions and I'll try to improve this PR.

Copy link
Contributor Author

@RyuzakiKK RyuzakiKK May 2, 2022

Choose a reason for hiding this comment

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

After reading the Go documentation and a few articles online, I ended up using a non-exported global variable to flag the mock validation and moved the test in the desync package.

Please let me know if you preferred a different approach instead.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
@RyuzakiKK
Copy link
Contributor Author

I guess this PR fell through the cracks. Is it Okay as-is or would you prefer some changes?

@folbricht
Copy link
Owner

Thanks for following up, forgot about this.

@folbricht folbricht merged commit 5b0c1a2 into folbricht:master Feb 8, 2024
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