master
cpp 64 lines 2.25 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 WSLCCLITmpfsParserUnitTests.cpp
8
9 Abstract:
10
11 This file contains unit tests for WSLC CLI tmpfs parsing and validation.
12 --*/
13
14 #include "precomp.h"
15 #include "windows/Common.h"
16 #include "MountSpecParsing.h"
17
18 using namespace wsl::windows::common;
19
20 namespace WSLCCLITmpfsParserUnitTests {
21
22 class WSLCCLITmpfsParserUnitTests
23 {
24 WSLC_TEST_CLASS(WSLCCLITmpfsParserUnitTests)
25
26 TEST_METHOD(WSLCCLITmpfsMount_Parse)
27 {
28 const std::vector<std::tuple<std::wstring, std::string, std::string>> validTmpfsSpecs = {
29 {L"", "", ""},
30 {L"/tmp", "/tmp", ""},
31 {L"/tmp:size=50m", "/tmp", "size=50m"},
32 {L"/var/tmp:size=1g", "/var/tmp", "size=1g"},
33 {L"/tmp:size=50m,mode=1777", "/tmp", "size=50m,mode=1777"},
34 {L"/cache:uid=1000,gid=1000", "/cache", "uid=1000,gid=1000"},
35 {L"/mnt/ramdisk:size=256k,nr_inodes=1k", "/mnt/ramdisk", "size=256k,nr_inodes=1k"},
36 {L"/securetmp:mode=0700", "/securetmp", "mode=0700"},
37 {L"/scratch:nosuid,nodev,noexec", "/scratch", "nosuid,nodev,noexec"},
38 {L"/wsl/tmp:size=2g,uid=0,gid=0,mode=1777", "/wsl/tmp", "size=2g,uid=0,gid=0,mode=1777"},
39 };
40
41 for (const auto& [input, expectedTarget, expectedOptions] : validTmpfsSpecs)
42 {
43 const auto result = mount::ParseDockerTmpfsString(input);
44 VERIFY_ARE_EQUAL(static_cast<int>(WSLCMountTypeTmpfs), static_cast<int>(result.MountType));
45 VERIFY_ARE_EQUAL(expectedTarget, result.Target);
46 VERIFY_IS_TRUE(result.TmpfsOptions.has_value());
47 VERIFY_ARE_EQUAL(expectedOptions, result.TmpfsOptions.value());
48 }
49 }
50
51 TEST_METHOD(WSLCCLITmpfsMount_Validate)
52 {
53 auto valid = mount::ParseDockerTmpfsString(L"/tmp:size=50m");
54 VERIFY_NO_THROW(mount::ValidateMountSpec(valid));
55
56 auto empty = mount::ParseDockerTmpfsString(L":size=50m");
57 VERIFY_THROWS(mount::ValidateMountSpec(empty), mount::MountValidationException);
58
59 auto relative = mount::ParseDockerTmpfsString(L"tmp:size=50m");
60 VERIFY_THROWS(mount::ValidateMountSpec(relative), mount::MountValidationException);
61 }
62 };
63
64 } // namespace WSLCCLITmpfsParserUnitTests