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

tests(quotes.go): create unit test #9

Merged
merged 3 commits into from
Dec 31, 2023
Merged

Conversation

servusdei2018
Copy link
Contributor

This PR adds unit tests for quotes.go. The loading and writing of quotes is tested to ensure expected functionality, by mocking an io.Reader and io.Writer.

@Alextopher Alextopher self-assigned this Dec 23, 2023
@Alextopher Alextopher added the enhancement New feature or request label Dec 23, 2023
@Alextopher Alextopher linked an issue Dec 23, 2023 that may be closed by this pull request
search.go Outdated Show resolved Hide resolved
search.go Outdated Show resolved Hide resolved
quotes_test.go Outdated Show resolved Hide resolved
quotes_test.go Outdated Show resolved Hide resolved
if quoteList[key] != val {
t.Errorf(`error, expected "%s", got "%s"`, val, quoteList[key])
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is a welcomed addition. My bigger concern is #7 with a few invariants I worry about.

  • The "default" search always returns all quotes
  • Searches return the expected quotes
  • New quotes get added to the end of pre-existing searches
  • There was a bug in a previous version that once a search ran until completion it would start returning "" instead of restarting. Exhausting a quote should just restart the search (with or without a new random order)

@Alextopher
Copy link
Collaborator

@servusdei2018 Are you planning on adding additional tests to this PR? I can merge this now without closing #7

@servusdei2018
Copy link
Contributor Author

Yeah I'll probably try to add some tests for searching in this PR too 👍🏽

@servusdei2018
Copy link
Contributor Author

Okay I now added test coverage for searches, and it should hit all the major points you listed:

  • The "default" search always returns all quotes
  • Searches return the expected quotes
  • New quotes get added to the end of pre-existing searches
  • There was a bug in a previous version that once a search ran until completion it would start returning "" instead of restarting. Exhausting a quote should just restart the search (with or without a new random order)

@bashawhm
Copy link
Owner

This all looks good to me, I would say that the addition of tests has highlighted how much we depend on random globals all over the place and that should probably be looked at, though that can be its own PR for whoever feels so inclined.

@Alextopher Alextopher merged commit 8e45aa8 into bashawhm:main Dec 31, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verify that quote searching works
3 participants