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

Include actual and expected values in config test error message #1633

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

rajatjindal
Copy link
Collaborator

this allows to debug config vars test by sending expected and actual value back

Copy link
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

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

The behaviour is fine but the naming is confusing in the context of the password fiction. As this is specifically a test case, not something that is meant to motivate understanding, I'd suggest dropping the fiction, and being absolutely clear in the naming and the error message about it being a config value that was not what it should have been.

tests/testcases/config-variables/src/lib.rs Outdated Show resolved Hide resolved
tests/testcases/config-variables/src/lib.rs Outdated Show resolved Hide resolved
tests/testcases/config-variables/src/lib.rs Outdated Show resolved Hide resolved
);

return Ok(http::Response::builder()
.status(401)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd leave this as a 500 - it's "something is wrong in our test, something that shouldn't have happened," not an actual auth failure. (Not sure if this means we could go back to using ensure! though.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I see you and @kate-goldenring have already been round and round on this one... sorry for sticking another opinion in! I agree with the previous discussion that it doesn't much matter!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we can't use ensure! as it panics and returns 500 without useful message. though to remove the fiction part, I would change it to return 500 instead of 401

how I have done in some other tests is to let the lib.rs just return the value and do assertion in test case assertions itself.

@kate-goldenring @itowlson - what do you think about that?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rajatjindal That's fine. I don't care vastly about the code. Happy with what you and @kate-goldenring have decided.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've changed it back to 500. just because 401 generally means unauthorized and in the context of the test, the user may get confused with the error code.

if we don't agree to 500, a better code would be 400 (bad request).

@itowlson
Copy link
Contributor

itowlson commented Jul 5, 2023

@rajatjindal Also could you please amend the commit message? It makes sense close up, but to someone scanning the history it won't be clear what it refers to.

@itowlson itowlson changed the title send error msg in return for debugging Include actual and expected values in config test error message Jul 5, 2023
@rajatjindal
Copy link
Collaborator Author

@rajatjindal Also could you please amend the commit message? It makes sense close up, but to someone scanning the history it won't be clear what it refers to.

done.

.expect("Should have a password query string");
let expected_password = config::get("password")?;
let expected_config_value = query
.get("expected_config_value")
Copy link
Contributor

Choose a reason for hiding this comment

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

If you change this, I think you need to change the test that passes the query string? It might be easier to leave the actual query string as was, as you did for the config key. It's only the variables and the message that I found confusing - sorry if I was overemphatic in my suggestions for change.

@rajatjindal
Copy link
Collaborator Author

ok, sorry for the back and forth on the PR. current state:

  • ensure returns the error msg, but it was not clear. so I've updated it to include expected/actual values
  • changed the variable names to reflect expected/actual values correctly
  • I've removed other unnecessary changes.

@rajatjindal rajatjindal merged commit 6aa2e1a into main Jul 6, 2023
7 of 8 checks passed
@rylev rylev deleted the debug-config-vars branch July 6, 2023 09:15
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.

3 participants