-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[WSLC] Add --workdir / -w option to 'wslc exec' #40041
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
090934b
[WSLC] Add --workdir / -w option to 'wslc exec'
4a2218d
Merge branch 'feature/wsl-for-apps' into user/ptrivedi/exec-workingdir
84851fd
Update test/windows/wslc/CommandLineTestCases.h
ptrivedi 9add70a
Update test/windows/wslc/CommandLineTestCases.h
ptrivedi 53c56a1
Merge branch 'feature/wsl-for-apps' into user/ptrivedi/exec-workingdir
ptrivedi ce1e458
Fix clang formatting issues
e6b90dd
Update test/windows/wslc/WSLCCLIExecutionUnitTests.cpp
ptrivedi 1699085
Add E2E tests for wslc container exec, including --workdir option
d54748e
Fix clang formatting in WSLCE2EContainerExecTests.cpp
9e966e3
Validate --workdir is non-empty; add unit and parse test cases
6b8fcbc
Fix clang formatting in CommandLineTestCases.h
6267e6d
Trim exec E2E tests to --workdir coverage only
70d3f3a
Merge branch 'feature/wsl-for-apps' into user/ptrivedi/exec-workingdir
ptrivedi 6eacc0b
Missed change from merge conflict resolution
0979c36
Fix --workdir whitespace validation to use std::iswspace for full Uni…
Copilot 7c16de1
Use lambda with wint_t cast in iswspace call to avoid potential UB
Copilot a923420
Missed change from merge conflict resolution
a1e710e
Merge branch 'user/ptrivedi/exec-workingdir' of https://github.com/mi…
53b0bb9
Address Copilot PR feedback
edb9743
Merge branch 'feature/wsl-for-apps' into user/ptrivedi/exec-workingdir
ptrivedi 2942cb4
Update src/windows/wslc/services/ContainerService.cpp
ptrivedi 7e7fbfe
Fix ParserTest_StateMachine_PositionalForward: replace -v with -h in …
00e3420
Merge remote-tracking branch 'origin/feature/wsl-for-apps' into user/…
f7cda40
Fix E2E exec help test: add --user option after base branch merge
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| WSLCE2EContainerExecTests.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| This file contains end-to-end tests for WSLC container exec command. | ||
| --*/ | ||
ptrivedi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #include "precomp.h" | ||
| #include "windows/Common.h" | ||
| #include "WSLCExecutor.h" | ||
| #include "WSLCE2EHelpers.h" | ||
|
|
||
| namespace WSLCE2ETests { | ||
|
|
||
| class WSLCE2EContainerExecTests | ||
| { | ||
| WSLC_TEST_CLASS(WSLCE2EContainerExecTests) | ||
|
|
||
| TEST_CLASS_SETUP(ClassSetup) | ||
| { | ||
| EnsureImageIsLoaded(DebianImage); | ||
| return true; | ||
| } | ||
|
|
||
| TEST_CLASS_CLEANUP(ClassCleanup) | ||
| { | ||
| EnsureContainerDoesNotExist(WslcContainerName); | ||
| EnsureImageIsDeleted(DebianImage); | ||
| return true; | ||
| } | ||
|
|
||
| TEST_METHOD_SETUP(TestMethodSetup) | ||
| { | ||
| EnsureContainerDoesNotExist(WslcContainerName); | ||
| return true; | ||
| } | ||
|
|
||
| TEST_METHOD(WSLCE2E_Container_Exec_HelpCommand) | ||
| { | ||
| WSL2_TEST_ONLY(); | ||
|
|
||
| auto result = RunWslc(L"container exec --help"); | ||
| result.Verify({.Stdout = GetHelpMessage(), .Stderr = L"", .ExitCode = 0}); | ||
| } | ||
|
|
||
| TEST_METHOD(WSLCE2E_Container_Exec_WorkDir) | ||
| { | ||
| WSL2_TEST_ONLY(); | ||
|
|
||
| auto result = RunWslc(std::format(L"container run -d --name {} {} sleep infinity", WslcContainerName, DebianImage.NameAndTag())); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
|
|
||
| result = RunWslc(std::format(L"container exec --workdir /tmp {} pwd", WslcContainerName)); | ||
| result.Verify({.Stdout = L"/tmp\n", .Stderr = L"", .ExitCode = 0}); | ||
| } | ||
|
|
||
| TEST_METHOD(WSLCE2E_Container_Exec_WorkDir_ShortAlias) | ||
| { | ||
| WSL2_TEST_ONLY(); | ||
|
|
||
| auto result = RunWslc(std::format(L"container run -d --name {} {} sleep infinity", WslcContainerName, DebianImage.NameAndTag())); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
|
|
||
| result = RunWslc(std::format(L"container exec -w /tmp {} pwd", WslcContainerName)); | ||
| result.Verify({.Stdout = L"/tmp\n", .Stderr = L"", .ExitCode = 0}); | ||
| } | ||
|
|
||
| private: | ||
| const std::wstring WslcContainerName = L"wslc-test-container"; | ||
| const TestImage& DebianImage = DebianTestImage(); | ||
|
|
||
| std::wstring GetHelpMessage() const | ||
| { | ||
| std::wstringstream output; | ||
| output << GetWslcHeader() // | ||
| << GetDescription() // | ||
| << GetUsage() // | ||
| << GetAvailableCommands() // | ||
| << GetAvailableOptions(); | ||
| return output.str(); | ||
| } | ||
|
|
||
| std::wstring GetDescription() const | ||
| { | ||
| return L"Executes a command in a running container.\r\n\r\n"; | ||
| } | ||
|
|
||
| std::wstring GetUsage() const | ||
| { | ||
| return L"Usage: wslc container exec [<options>] <container-id> <command> [<arguments>...]\r\n\r\n"; | ||
| } | ||
|
|
||
| std::wstring GetAvailableCommands() const | ||
| { | ||
| std::wstringstream commands; | ||
| commands << L"The following arguments are available:\r\n" | ||
| << L" container-id Container ID\r\n" | ||
| << L" command The command to run\r\n" | ||
| << L" arguments Arguments to pass to the command being executed inside the container\r\n" | ||
| << L"\r\n"; | ||
| return commands.str(); | ||
| } | ||
|
|
||
| std::wstring GetAvailableOptions() const | ||
| { | ||
| std::wstringstream options; | ||
| options << L"The following options are available:\r\n" | ||
| << L" -d,--detach Run container in detached mode\r\n" | ||
| << L" -e,--env Key=Value pairs for environment variables\r\n" | ||
| << L" --env-file File containing key=value pairs of env variables\r\n" | ||
| << L" -i,--interactive Attach to stdin and keep it open\r\n" | ||
| << L" --session Specify the session to use\r\n" | ||
| << L" -t,--tty Open a TTY with the container process.\r\n" | ||
| << L" -u,--user User ID for the process (name|uid|uid:gid)\r\n" | ||
| << L" -w,--workdir Working directory inside the container\r\n" | ||
| << L" -h,--help Shows help about the selected command\r\n" | ||
| << L"\r\n"; | ||
| return options.str(); | ||
| } | ||
| }; | ||
| } // namespace WSLCE2ETests | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.