mirror of
https://github.com/aphrody-labs/WSL.git
synced 2026-10-17 20:56:23 +00:00
* Init network commands Co-authored-by: AmelBawa-msft <104940545+AmelBawa-msft@users.noreply.github.com> * Integrate network inspect Co-authored-by: AmelBawa-msft <104940545+AmelBawa-msft@users.noreply.github.com> * Clang format Co-authored-by: AmelBawa-msft <104940545+AmelBawa-msft@users.noreply.github.com> * fix: address review feedback in network port to master Agent-Logs-Url: https://github.com/microsoft/WSL/sessions/db7c0afc-316b-46bf-aae1-71244fd15e16 Co-authored-by: AmelBawa-msft <104940545+AmelBawa-msft@users.noreply.github.com> * Sync with latest * Clang format * Added test * Update test * Update string * Promote parsers * Clang format * Remove comments * Fix test --------- Co-authored-by: AmirMS <104940545+AmelBawa-msft@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
/*++
|
|
|
|
Copyright (c) Microsoft. All rights reserved.
|
|
|
|
Module Name:
|
|
|
|
WSLCCLILabelParserUnitTests.cpp
|
|
|
|
Abstract:
|
|
|
|
This file contains unit tests for WSLC CLI label parsing and validation.
|
|
--*/
|
|
|
|
#include "precomp.h"
|
|
#include "windows/Common.h"
|
|
#include "WSLCCLITestHelpers.h"
|
|
#include "ArgumentValidation.h"
|
|
|
|
using namespace wsl::windows::wslc;
|
|
|
|
namespace WSLCCLILabelParserUnitTests {
|
|
|
|
class WSLCCLILabelParserUnitTests
|
|
{
|
|
WSLC_TEST_CLASS(WSLCCLILabelParserUnitTests)
|
|
|
|
TEST_METHOD(WSLCCLILabelParser_ValidLabels)
|
|
{
|
|
std::vector<std::tuple<std::wstring, std::string, std::string>> validLabels = {
|
|
{L"foo=bar", "foo", "bar"},
|
|
{L"foo=", "foo", ""},
|
|
{L"foo", "foo", ""},
|
|
{L"foo=a=b=c", "foo", "a=b=c"},
|
|
};
|
|
|
|
for (const auto& [input, expectedKey, expectedValue] : validLabels)
|
|
{
|
|
auto result = validation::ParseLabel(input);
|
|
VERIFY_ARE_EQUAL(expectedKey, result.first);
|
|
VERIFY_ARE_EQUAL(expectedValue, result.second);
|
|
}
|
|
}
|
|
|
|
TEST_METHOD(WSLCCLILabelParser_InvalidLabels)
|
|
{
|
|
std::vector<std::wstring> invalidLabels = {
|
|
L"",
|
|
L"=",
|
|
L"=value",
|
|
};
|
|
|
|
for (const auto& input : invalidLabels)
|
|
{
|
|
try
|
|
{
|
|
(void)validation::ParseLabel(input);
|
|
VERIFY_FAIL(L"Expected exception");
|
|
}
|
|
catch (const wil::ResultException& ex)
|
|
{
|
|
VERIFY_ARE_EQUAL(E_INVALIDARG, ex.GetErrorCode());
|
|
|
|
const auto raw = ex.GetFailureInfo().pszMessage;
|
|
std::wstring message = raw ? raw : L"";
|
|
VERIFY_ARE_EQUAL(L"Label key cannot be empty", message);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
} // namespace WSLCCLILabelParserUnitTests
|