-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Enhance and organize test execution #40108
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
Open
AmelBawa-msft
wants to merge
15
commits into
feature/wsl-for-apps
Choose a base branch
from
user/amelbawa/e2e-1
base: feature/wsl-for-apps
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
de4ab00
container attach
AmelBawa-msft 62bbf74
Enhance tests
AmelBawa-msft 1aa8b61
Resolve conflicts
AmelBawa-msft f0fc76a
Move more tests to run
AmelBawa-msft d8b211f
Init exec
AmelBawa-msft cc91ca9
Clang format
AmelBawa-msft bac0a6f
Resolve copilot comment
AmelBawa-msft 6a4a033
Replace S_OK with 0
AmelBawa-msft 880e702
Added error messages
AmelBawa-msft f3e11b8
Resolve copilot comment
AmelBawa-msft db11a0f
Merge branch 'feature/wsl-for-apps' into user/amelbawa/e2e-1
AmelBawa-msft 532648f
Clang format
AmelBawa-msft 8338c2f
Resolve conflicts
AmelBawa-msft 42da208
Merge branch 'feature/wsl-for-apps' of https://github.com/microsoft/w…
AmelBawa-msft 92e0074
Fix tests
AmelBawa-msft 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| WSLCE2EContainerAttachTests.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| This file contains end-to-end tests for WSLC container attach command. | ||
| --*/ | ||
|
|
||
| #include "precomp.h" | ||
| #include "windows/Common.h" | ||
| #include "WSLCExecutor.h" | ||
| #include "WSLCE2EHelpers.h" | ||
|
|
||
| namespace WSLCE2ETests { | ||
|
|
||
| class WSLCE2EContainerAttachTests | ||
| { | ||
| WSLC_TEST_CLASS(WSLCE2EContainerAttachTests) | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| WSLC_TEST_METHOD(WSLCE2E_Container_Attach_HelpCommand) | ||
| { | ||
| auto result = RunWslc(L"container attach --help"); | ||
| result.Verify({.Stdout = GetHelpMessage(), .Stderr = L"", .ExitCode = 0}); | ||
| } | ||
|
|
||
| WSLC_TEST_METHOD(WSLCE2E_Container_Attach_TTY) | ||
| { | ||
| VerifyContainerIsNotListed(WslcContainerName); | ||
|
|
||
| const auto& prompt = ">"; | ||
| auto result = RunWslc(std::format( | ||
| L"container run -itd -e PS1={} --name {} {} bash --norc", prompt, WslcContainerName, DebianImage.NameAndTag())); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
| auto containerId = result.GetStdoutOneLine(); | ||
|
|
||
| const auto& expectedAttachPrompt = VT::BuildContainerAttachPrompt(prompt); | ||
| const auto& expectedPrompt = VT::BuildContainerPrompt(prompt); | ||
|
|
||
| auto session = RunWslcInteractive(std::format(L"container attach {}", containerId)); | ||
| VERIFY_IS_TRUE(session.IsRunning(), L"Container session should be running"); | ||
|
|
||
| // The container attach prompt appears twice. | ||
| session.ExpectStdout(expectedAttachPrompt); | ||
| session.ExpectStdout(expectedAttachPrompt); | ||
|
|
||
| session.WriteLine("echo hello"); | ||
| session.ExpectCommandEcho("echo hello"); | ||
| session.ExpectStdout("hello\r\n"); | ||
| session.ExpectStdout(expectedPrompt); | ||
|
|
||
| session.WriteLine("whoami"); | ||
| session.ExpectCommandEcho("whoami"); | ||
| session.ExpectStdout("root\r\n"); | ||
| session.ExpectStdout(expectedPrompt); | ||
|
|
||
| session.ExitAndVerifyNoErrors(); | ||
| auto exitCode = session.Wait(); | ||
AmelBawa-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| VERIFY_ARE_EQUAL(0, exitCode); | ||
| } | ||
|
|
||
| WSLC_TEST_METHOD(WSLCE2E_Container_Attach_NoTTY) | ||
| { | ||
| VerifyContainerIsNotListed(WslcContainerName); | ||
| auto result = RunWslc(std::format(L"container run -id --name {} {} cat", WslcContainerName, DebianImage.NameAndTag())); | ||
| result.Verify({.Stderr = L"", .ExitCode = 0}); | ||
| auto containerId = result.GetStdoutOneLine(); | ||
|
|
||
| auto session = RunWslcInteractive(std::format(L"container attach {}", containerId)); | ||
| VERIFY_IS_TRUE(session.IsRunning(), L"Container session should be running"); | ||
|
|
||
| session.WriteLine("test line 1"); | ||
| session.ExpectStdout("test line 1\n"); | ||
| session.WriteLine("test line 2"); | ||
| session.ExpectStdout("test line 2\n"); | ||
|
|
||
| // Close stdin to signal EOF to cat | ||
| session.CloseStdin(); | ||
|
|
||
| // Wait for cat to exit with code 0 | ||
| auto exitCode = session.Wait(10000); | ||
| VERIFY_ARE_EQUAL(0, exitCode, L"Cat should exit with code 0 after receiving EOF"); | ||
| session.VerifyNoErrors(); | ||
| } | ||
|
|
||
| WSLC_TEST_METHOD(WSLCE2E_Container_Attach_MissingContainerId) | ||
| { | ||
| auto result = RunWslc(L"container attach"); | ||
| result.Verify({.Stdout = GetHelpMessage(), .Stderr = L"Required argument not provided: 'container-id'\r\n", .ExitCode = 1}); | ||
| } | ||
|
|
||
| WSLC_TEST_METHOD(WSLCE2E_Container_Attach_ContainerNotFound) | ||
| { | ||
| auto result = RunWslc(std::format(L"container attach {}", WslcContainerName)); | ||
| result.Verify({.Stderr = L"Element not found. \r\nError code: ERROR_NOT_FOUND\r\n", .ExitCode = 1}); | ||
| } | ||
|
|
||
| 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"Attaches to a container.\r\n\r\n"; | ||
| } | ||
|
|
||
| std::wstring GetUsage() const | ||
| { | ||
| return L"Usage: wslc container attach [<options>] <container-id>\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"\r\n"; | ||
| return commands.str(); | ||
| } | ||
|
|
||
| std::wstring GetAvailableOptions() const | ||
| { | ||
| std::wstringstream options; | ||
| options << L"The following options are available:\r\n" // | ||
| << L" --session Specify the session to use\r\n" // | ||
| << L" -h,--help Shows help about the selected command\r\n" | ||
| << L"\r\n"; | ||
| return options.str(); | ||
| } | ||
| }; | ||
| } // namespace WSLCE2ETests | ||
Oops, something went wrong.
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.