-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathWSLCE2EContainerExecTests.cpp
More file actions
126 lines (101 loc) · 3.98 KB
/
WSLCE2EContainerExecTests.cpp
File metadata and controls
126 lines (101 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
WSLCE2EContainerExecTests.cpp
Abstract:
This file contains end-to-end tests for WSLC container exec command.
--*/
#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" -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