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: Ensure that empty strings aren't used as IRIs in tests #52

Merged
merged 2 commits into from
Feb 26, 2016

Conversation

benjamingeer
Copy link

The resources responder and values responder test specs include a number of tests that generate IRIs that are used in subsequent tests. These IRIs have just been stored as strings in mutable variables, initialised to the empty string. A problem I've encountered is that if one test fails, a subsequent test may try to use an empty string as an IRI, resulting in an unbound SPARQL variable, which leads to a very busy triplestore, a massive unwanted query result, and a confusing delay before the test fails.

This pull request replaces those mutable variables with a little class called MutableTestIri, which has get and set methods that throw exceptions if the IRI is an empty string, is invalid, or hasn't been set when it's needed. So if a test fails and doesn't set an IRI, a subsequent test that needs the IRI will fail gracefully.

@benjamingeer benjamingeer added the enhancement improve existing code or new feature label Feb 25, 2016
@benjamingeer benjamingeer added this to the On Deck milestone Feb 25, 2016
@tobiasschweizer
Copy link
Contributor

Why did we have to check for an empty resource Iri in getResourceInfoV1 and what did you replace this behaviour with? Was this just there for the test cases (in case the previous operation failed which was supposed to return a valid resource Iri) and for the live cases we would have checked for a valid resource Iri already in the route?

If it was just there for the test cases, we do not need it anymore, and so it is correct as it is now.

In general, we should avoid putting code in the responders that handle cases that only occur in tests.

@tobiasschweizer
Copy link
Contributor

In ResourcesResponderV1Spec.scala, couldn't you make private var newResourceIri = new MutableTestIri (line 186) a val as it points always to the same instance (immutable).

@tobiasschweizer
Copy link
Contributor

Otherwise it seems fine to me. This is a much better than we had before.

@benjamingeer
Copy link
Author

Why did we have to check for an empty resource Iri in getResourceInfoV1 and what did you replace this behaviour with? Was this just there for the test cases

Yes, I had just added it yesterday. :)

In general, we should avoid putting code in the responders that handle cases that only occur in tests.

Yes, it was a hack and it bothered me, that's why I made this pull request. :)

In ResourcesResponderV1Spec.scala, couldn't you make private var newResourceIri = new MutableTestIri (line 186) a val as it points always to the same instance (immutable).

Yes, thanks, fixed.

benjamingeer pushed a commit that referenced this pull request Feb 26, 2016
test: Ensure that empty strings aren't used as IRIs in tests
@benjamingeer benjamingeer merged commit 93cc65b into develop Feb 26, 2016
@benjamingeer benjamingeer deleted the wip/safe-iri-strings-in-tests branch February 26, 2016 08:44
@tobiasschweizer
Copy link
Contributor

great, this was fast

@benjamingeer benjamingeer mentioned this pull request Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improve existing code or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants