-
Notifications
You must be signed in to change notification settings - Fork 892
feat: Add golden files to test cli help output #4897
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
Conversation
6db8c38
to
71ad866
Compare
c652c69
to
c814fa3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is an interesting way of doing it. The makefile updates the golden files
c814fa3
to
7f6b0f4
Compare
|
||
//nolint:tparallel,paralleltest // These test sets env vars. | ||
func TestCommandHelp(t *testing.T) { | ||
t.Parallel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use t.Setenv
in the subtests. Can't we not set envs during parallel tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, t.Setenv
will panic after a call to t.Parallel()
. It modifies the os env but restores it at the end of the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, apparently it does not panic if you use t.Setenv
in a subtest and you have t.Parallel
on the root test.
TestCommandHelp
sets t.Parallel
on the first line, but subtests use t.Setenv
. Do we need to remove t.Parallel
from the root test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh?
This is from the Go implementation:
func (t *T) Setenv(key, value string) {
if t.isParallel {
panic("testing: t.Setenv called after t.Parallel; cannot set environment variables in parallel tests")
}
So if the subtest is parallel, it'll panic, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I think I misunderstood. It’s fine if the parent test has t.Parallel. Just means that starting it will not block other tests, but the subtests will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
3ec3ae3
to
1b4dbe9
Compare
Get Started: | ||
- Start a Coder server: | ||
|
||
[;m$ coder server[0m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you may consider disabling colors for readability purposes. I assume that the major goal of this change request is to check the CLI text output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should already be since stdout is not a tty, so seems like a separate issue 😅. (You're absolutely right that it shouldn't be output since we only care about the text.)
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Unset all CODER_ environment variables for a clean slate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if you shouldn't remove all environment variables, like TTY-related, NO_COLOR
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was being cautious by only overriding the CODER ones, but I'm guessing it won't hurt 👍🏻. Currently (to my knowledge) the only non-coder env that has an effect on the application is CACHE_DIRECTORY
(for systemd compat).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dang, looks like it broke Windows tests, I'll just revert the change and we can fix any issues if they surface in the future. https://github.com/coder/coder/actions/runs/3394713015/jobs/5643623340
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Maybe there is a minimal set of env vars that are required by Windows.
This reverts commit 0928b8b.
This PR adds golden files to test cli help output.
Any changes to
coder --help
orcoder server --help
now need to be verified via occular output.Like this: