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

refactor: simplify building of options in tests #21

Merged
merged 1 commit into from
May 17, 2020

Conversation

bajtos
Copy link
Contributor

@bajtos bajtos commented May 4, 2020

Extracted from #18, where I noticed that adding a new sync option involves changes in many existing tests, which is not ideal.

  • Replace the global constant DEFAULT_SYNC_OPTIONS with a factory function to obtain a new instance of the options object
  • Rework tests using custom options to start with the default options and modify only the fields relevant in the test.

With this improvement in place, when we add a new sync option in the future, existing tests should not need any changes.

@bajtos
Copy link
Contributor Author

bajtos commented May 7, 2020

@klausi have you had a chance to take a look at my proposed changes? I'd like to land this pull request before I start working on #17 and #23.

sync_retweets: true,
};
let mut options = get_sync_options();
options.sync_reblogs = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative I considered: Instead of changing all tests to use get_sync_options() instead of DEFAULT_SYNC_OPTIONS, maybe I can instead use clone only in the tests that need to modify the default values. Something along the following lines:

let mut options = DEFAULT_SYNC_OPTIONS.clone();
options.sync_reblogs = false;

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went ahead and implemented this simpler version. The patch is much smaller now 🕺

Rework tests using custom options to clone the default options and
modify only the fields relevant in the test.

With this improvement in place, when we add a new sync option in the
future, existing tests should not need any changes.

Signed-off-by: Miroslav Bajtoš <[email protected]>
@klausi klausi merged commit 813ca0a into klausi:master May 17, 2020
@klausi
Copy link
Owner

klausi commented May 17, 2020

Makes sense, thanks!

@bajtos bajtos deleted the refactor/simplify-tests branch May 21, 2020 14:23
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