| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | WSLCE2ESettingsTests.cpp |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | End-to-end tests for the wslc `settings` command tree. Tests mutate the |
| 12 | user's real settings file at %LOCALAPPDATA%\wslc\settings.yaml; HostFileChange |
| 13 | backs the file up on construction and restores it on scope exit. |
| 14 | |
| 15 | --*/ |
| 16 | |
| 17 | #include "precomp.h" |
| 18 | #include "windows/Common.h" |
| 19 | #include "WSLCExecutor.h" |
| 20 | #include "WSLCE2EHelpers.h" |
| 21 | |
| 22 | namespace WSLCE2ETests { |
| 23 | using namespace wsl::shared; |
| 24 | |
| 25 | class WSLCE2ESettingsTests |
| 26 | { |
| 27 | WSLC_TEST_CLASS(WSLCE2ESettingsTests) |
| 28 | |
| 29 | WSLC_TEST_METHOD(WSLCE2E_Settings_Reset_RewritesFile) |
| 30 | { |
| 31 | const auto settingsPath = GetSettingsPath(); |
| 32 | |
| 33 | HostFileChange settings(settingsPath, "session:\n cpuCount: 2\n"); |
| 34 | |
| 35 | auto result = RunWslc(L"settings reset"); |
| 36 | result.Verify({.Stderr = L"", .ExitCode = 0}); |
| 37 | |
| 38 | const auto content = ReadFileContent(settingsPath.wstring()); |
| 39 | VERIFY_ARE_EQUAL(std::wstring::npos, content.find(L"cpuCount: 2")); |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | static std::filesystem::path GetSettingsPath() |
| 44 | { |
| 45 | return wsl::windows::common::filesystem::GetLocalAppDataPath(nullptr) / L"wslc" / L"settings.yaml"; |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | } // namespace WSLCE2ETests |