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

Mock Time #11

Merged
merged 19 commits into from
Aug 20, 2020
Merged

Mock Time #11

merged 19 commits into from
Aug 20, 2020

Conversation

tooolbox
Copy link
Contributor

Closes #8

Adds the ability to mock time for the purpose of unit tests. Uses the IFNULL(?, UTC_TIMESTAMP()) strategy described in #8.

Depends upon #10 because it will be annoying to unit-test this without a proper Go client 😉

@tooolbox tooolbox marked this pull request as ready for review August 19, 2020 20:15
@tooolbox
Copy link
Contributor Author

tooolbox commented Aug 19, 2020

I realized that this did not actually depend upon #10 because all the changes were taking place in the table package and that could be unit-tested without the Client, which is why you don't see that in this PR.

Still, between this and the Client, it will be smooth to unit-test the upcoming ISO8601 support.

Sorry for all the branch merging, I'm maintaining a few here trying to keep different features separate and I got confused 😉

The table package could be unit-tested more thoroughly but for now it has a basic test and you can see how the time-mocking comes into play. I do still need to figure out how I'm going to expose the time-control to outside packages (both inside and outside of this repo) but I don't think it will be difficult.

I'm pleased that this solution allows for mocking the time while preserving the DB as the single time source. The only snag I ran into is that the Mysql driver doesn't support multiple statements in a single Exec—if they contain placeholders—so I had to touch the UpdateInstance call more than I wanted to, but I think it turned out fine.

This was referenced Aug 19, 2020
internal/table/table.go Outdated Show resolved Hide resolved
@cenkalti cenkalti merged commit 61d7b41 into cenkalti:master Aug 20, 2020
@tooolbox tooolbox deleted the 20200818-mocktime branch August 20, 2020 18:54
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.

Mocking Time
2 participants