-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Features/propagate goflags env #193
Conversation
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.
Nice. Just a little comment in-line about not calling os.Getenv()
twice to avoid needing two system calls if the environment variable is set up.
@@ -79,7 +79,7 @@ func AppendEnv(args []string, environs map[string]string, quoteNeeded bool) []st | |||
if quoteNeeded && strings.Contains(v, "=") { | |||
// engine requires to double quote the env var when value contains | |||
// the `=` char | |||
env = fmt.Sprintf("%q", env) | |||
env = fmt.Sprintf("%s=%q", k, v) |
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 wonder if this could have a unit test? It potentially could have a big impact on other variable appending and we have seen a few bugs recently that suggest that not all envs encode the same...
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.
Not to sure what the test could be that doesn't look like just enforcing the same code as here, since it is following docker flags interface. Maybe we should exec docker and podman in our tests for that?
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.
It could be factored out to a helper that formats the arts and demonstrates that non-trivial inputs (spaces etc) create the right format of string.
Just a little sanity checking really as a simple "x=y" seems like a potential spot for glitches in env and cmd handling.
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.
Such a tests would enforce and lock implementation details, that are not necessarily correct. That's where I have trouble imagining a test without having to spin a docker and podman command line that is not locking implementation, but actually enforce that it work.
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 am totally lost - why does passing an env into a printf require a docker container?
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.
If that was the case then the comment "double quote the env var when value contains the =
char" would surely have read "double quote the env value when value contains the =
char", as the environment variable is in the KEY=VALUE format is it not?
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 agree with Andrew. It is better to verify that the code does what we think is right than not testing it at all.
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.
If that was the case then the comment "double quote the env var when value contains the
=
char" would surely have read "double quote the env value when value contains the=
char", as the environment variable is in the KEY=VALUE format is it not?
I see and understand that it might be confusing. In that case, any suggestion that would be less confusing for you?
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.
It is better to verify that the code does what we think is right than not testing it at all.
I disagree on this statement. Tech debt for tests is worse than no tests. Never the less, it seems their is a consensus for having this kind of tests in, so I will oblige and add one.
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.
Test and comment change are in.
Co-authored-by: Jacob Alzén <jacob.alzen@gmail.com>
Would be great to have this merged and released asap now that the tests are in! |
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.
Personally I would have factored out the escaping code to a smaller scope so that could be tested with much simpler unit code.
However this certainly covers the usage - but as commented inline isn't it easier / clearer just to iterate over one want
for the args list?
internal/command/docker_test.go
Outdated
for i, v := range tt.wantStart { | ||
assert.Equal(t, v, got[i]) | ||
} | ||
for i := len(tt.wantStart); i < len(got); i += 2 { |
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.
isn't len(tt.wantStart)
always going to be the same as i
?
It took a while to realise this was contiguous, so I would suggest that I spans the two for loops so that is clear.
I also wondered, wouldn't it make sense to simplfy to just have all the output in a single want
that is iterated?
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.
The issue is that you can't rely on hash map order, which is why there is two loops. One for the part that should be stable and one for the part that can vary.
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 I see. But that wouldn't impact the usage of i - a single variable would better indicate that it is checking every item in the slices, even though split over two loops?
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 am not sure what you exactly mean. I reused the same name (i
), but did want to use the cleaner, more readable, call to range
when possible.
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 mean that i := len(tt.wantStart)
creates a new i
with the same value as the old one.
But for me at least this was not obvious... so it seemed sensible that this could be skipped and re-use the same i
for both loops? You can still use the range as you have here.
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.
This actually make the code a bit more complex to read. range
does exit the loop with i == len(tt.wantStart) - 1, but if there is nothing in tt.wantStart, it exit with i == 0. So before I can use it I have to add a test to see if len(tt.wantStart) != 0, to add 1 back. This is a lot less readable at the end that with the current code I think. Do you have any suggestion on how to solve that? I can only imagine with going with the C style loop syntax instead of range
.
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 think you could increment i
inside the range loop too, if that's better?
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.
Do you mean that i
would not be managed by range, but manually? Will have to try that.
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.
Not a big fan, but if that's what you had in mind, I am fine with it.
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.
The notation may not be totally awesome, but it helps to show we are actually only iterating once, despite two loops.
Thanks for the update.
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.
Thanks for this
Description:
This PR will pick GOFLAGS from fyne-cross host environment and propagate them to the call in the container.
Where applicable: