Job container path touchups + rework tests#1117
Merged
dcantah merged 1 commit intomicrosoft:masterfrom Sep 7, 2021
Merged
Conversation
internal/jobcontainers/path.go
Outdated
| trialName = "\"" + trialName + "\"" | ||
| trialName += " " + strings.Join(args[argsIndex+1:], " ") | ||
| adjustedCommandLine = trialName | ||
| adjustedCommandLine = trialName[0 : len(trialName)-1] // Take off the last empty space from above when joining the args. |
There was a problem hiding this comment.
Would https://pkg.go.dev/strings#TrimSpace this work instead?
Contributor
Author
There was a problem hiding this comment.
Oh sweet, forgot there was something that removed whitespace at the beginning/end.
anmaxvl
reviewed
Sep 7, 2021
| }, | ||
| { | ||
| name: "Ping_With_Cwd", | ||
| commandLine: "cmd /c ping 127.0.0.1", |
Contributor
There was a problem hiding this comment.
maybe add another test case with something like "some\\windows\\path /flag arg"
Contributor
Author
There was a problem hiding this comment.
Sure! Added a system32\\cmd /c ping 127.0.0.1 test case
anmaxvl
approved these changes
Sep 7, 2021
This change does a couple of things for the path resolution logic. 1. I was using filepath.Clean to remove any initial '.' paths in the command line to handle relative paths with a dot. However it changes all forward slashes to backslashes, which hinders command lines like the following: `"cmd /c ping 127.0.0.1"` as the /c argument will be altered. Windows Server containers don't handle relative paths with a dot, so it doesn't seem necessary to support them for job containers either, so just get rid of the call entirely. 2. Remove empty spaces off the end of the cmdline if it's quoted. There was an empty space in this case as I was using strings.Join to join the arguments after the quoted element. This had no effects on actual usage/functionality, but to compare commandlines for tests, this made things easier. 3. When replacing instances of %CONTAINER_SANDBOX_MOUNT_POINT% in the commandline, the path of the volume we were replacing it with had a trailing forward slash, so you'd end up with C:\C\12345678abcdefg\\\mybinary.exe (two forward slashes). This also didn't have much of an effect on anything, but just to clean things up. 4. Lastly, this change also refactors the job container path tests as they were a bit unwieldy and were due for the t.Run treatment. This moves the tests to being run via t.Run and a slice of configs to test different path, working directory, env matrixes. Also adds some new test cases to try out. Signed-off-by: Daniel Canter <dcanter@microsoft.com>
5089057 to
76c63b5
Compare
3 tasks
anmaxvl
pushed a commit
to anmaxvl/hcsshim
that referenced
this pull request
Nov 17, 2021
Related work items: microsoft#1062, microsoft#1087, microsoft#1089, microsoft#1095, microsoft#1104, microsoft#1112, microsoft#1117, microsoft#1118, microsoft#1125, microsoft#1137, microsoft#1139, microsoft#1140, microsoft#1141, microsoft#1142, microsoft#1143, microsoft#1145, microsoft#1146, microsoft#1150, microsoft#1151, microsoft#1153, microsoft#1154, microsoft#1155, microsoft#1156, microsoft#1157, microsoft#1158, microsoft#1159, microsoft#1161, microsoft#1162, microsoft#1163, microsoft#1164, microsoft#1165, microsoft#1166, microsoft#1167, microsoft#1168, microsoft#1169, microsoft#1171, microsoft#1172, microsoft#1173, microsoft#1174, microsoft#1178
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change does a couple of things for the path resolution logic and tests.
filepath.Cleanto remove any initial '.' paths in the command line. However it changes all forward slashes to backslashes, which hinders command lines like the following:"cmd /c ping 127.0.0.1"as the /c argument will be altered. Windows Server containers don't handle relative paths with a dot, so it doesn't seem necessary to support them for job containers either, so just get rid of the call entirely.
Remove empty spaces off the end of the cmdline if it's quoted. There was an empty space in this case as I was using strings.Join to join the arguments after the quoted element. This had no effects on actual usage/functionality, but to compare command lines for tests, this made things easier.
When replacing instances of %CONTAINER_SANDBOX_MOUNT_POINT% in the commandline, the path of the volume we were replacing it with had a trailing forward slash, so you'd end up with C:\C\12345678abcdefg\\mybinary.exe (two forward slashes). This also didn't have much of an effect on anything, but just to clean things up.
Lastly, this change also refactors the job container path tests as they were a bit unwieldy and were due for the t.Run treatment. This moves the tests to being run via t.Run and a slice of configs to test different path, working directory, env matrixes. Also adds some new test cases to try out.
Signed-off-by: Daniel Canter dcanter@microsoft.com