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

Job container path touchups + rework tests #1117

Merged
merged 1 commit into from
Sep 7, 2021

Conversation

dcantah
Copy link
Contributor

@dcantah dcantah commented Aug 17, 2021

This change does a couple of things for the path resolution logic and tests.

  1. I was using filepath.Clean to 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.

  1. 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.

  2. 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.

  3. 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 [email protected]

@dcantah dcantah requested a review from a team as a code owner August 17, 2021 01:24
@@ -156,7 +152,7 @@ func getApplicationName(commandLine, workingDirectory, pathEnv string) (string,
if quoteCmdLine {
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would https://pkg.go.dev/strings#TrimSpace this work instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sweet, forgot there was something that removed whitespace at the beginning/end.

Copy link
Contributor

@katiewasnothere katiewasnothere left a comment

Choose a reason for hiding this comment

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

two nits, otherwise lgtm

},
{
name: "Ping_With_Cwd",
commandLine: "cmd /c ping 127.0.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add another test case with something like "some\\windows\\path /flag arg"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Added a system32\\cmd /c ping 127.0.0.1 test case

Copy link
Contributor

@anmaxvl anmaxvl left a comment

Choose a reason for hiding this comment

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

small suggestion, otherwise lgtm

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 <[email protected]>
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