11using System . Collections . Generic ;
22using System . IO ;
3+ using System . Runtime . InteropServices ;
34using System . Security ;
45using Mono . Unix ;
56using Mono . Unix . Native ;
1213namespace Snowflake . Data . Tests . UnitTests . Tools
1314{
1415 [ TestFixture , NonParallelizable ]
15- public class FileOperationsTest
16+ [ Platform ( Exclude = "Win" ) ]
17+ public class FileOperationsUnixTest
1618 {
1719 private static FileOperations s_fileOperations ;
1820 private static readonly string s_relativeWorkingDirectory = $ "file_operations_test_{ Path . GetRandomFileName ( ) } ";
@@ -23,6 +25,11 @@ public class FileOperationsTest
2325 [ SetUp ]
2426 public static void Before ( )
2527 {
28+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
29+ {
30+ Assert . Ignore ( "Unix-specific tests are not run on Windows" ) ;
31+ }
32+
2633 if ( ! Directory . Exists ( s_workingDirectory ) )
2734 {
2835 Directory . CreateDirectory ( s_workingDirectory ) ;
@@ -34,24 +41,15 @@ public static void Before()
3441 [ TearDown ]
3542 public static void After ( )
3643 {
44+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
45+ {
46+ return ;
47+ }
48+
3749 Directory . Delete ( s_workingDirectory , true ) ;
3850 }
3951
4052 [ Test ]
41- [ Platform ( "Win" ) ]
42- public void TestReadAllTextOnWindows ( )
43- {
44- var filePath = CreateConfigTempFile ( s_workingDirectory , s_content ) ;
45-
46- // act
47- var result = s_fileOperations . ReadAllText ( filePath , TomlConnectionBuilder . ValidateFilePermissions ) ;
48-
49- // assert
50- Assert . AreEqual ( s_content , result ) ;
51- }
52-
53- [ Test ]
54- [ Platform ( Exclude = "Win" ) ]
5553 public void TestReadAllTextCheckingPermissionsUsingTomlConfigurationFileValidations (
5654 [ ValueSource ( nameof ( UserAllowedFilePermissions ) ) ]
5755 FileAccessPermissions userAllowedFilePermissions )
@@ -69,7 +67,6 @@ public void TestReadAllTextCheckingPermissionsUsingTomlConfigurationFileValidati
6967 }
7068
7169 [ Test ]
72- [ Platform ( Exclude = "Win" ) ]
7370 public void TestShouldThrowExceptionIfOtherPermissionsIsSetWhenReadConfigurationFile (
7471 [ ValueSource ( nameof ( UserAllowedFilePermissions ) ) ]
7572 FileAccessPermissions userAllowedFilePermissions )
@@ -86,7 +83,6 @@ public void TestShouldThrowExceptionIfOtherPermissionsIsSetWhenReadConfiguration
8683
8784
8885 [ Test ]
89- [ Platform ( Exclude = "Win" ) ]
9086 public void TestFileIsSafeOnNotWindows ( )
9187 {
9288 // arrange
@@ -98,7 +94,6 @@ public void TestFileIsSafeOnNotWindows()
9894 }
9995
10096 [ Test ]
101- [ Platform ( Exclude = "Win" ) ]
10297 public void TestFileIsNotSafeOnNotWindowsWhenTooBroadPermissionsAreUsed (
10398 [ ValueSource ( nameof ( InsecurePermissions ) ) ]
10499 FileAccessPermissions permissions )
@@ -112,19 +107,6 @@ public void TestFileIsNotSafeOnNotWindowsWhenTooBroadPermissionsAreUsed(
112107 }
113108
114109 [ Test ]
115- [ Platform ( "Win" ) ]
116- public void TestFileIsSafeOnWindows ( )
117- {
118- // arrange
119- var absoluteFilePath = Path . Combine ( s_workingDirectory , s_fileName ) ;
120- File . Create ( absoluteFilePath ) . Close ( ) ;
121-
122- // act and assert
123- Assert . IsTrue ( s_fileOperations . IsFileSafe ( absoluteFilePath ) ) ;
124- }
125-
126- [ Test ]
127- [ Platform ( Exclude = "Win" ) ]
128110 public void TestOwnerIsCurrentUser ( )
129111 {
130112 // arrange
@@ -137,7 +119,6 @@ public void TestOwnerIsCurrentUser()
137119 }
138120
139121 [ Test ]
140- [ Platform ( Exclude = "Win" ) ]
141122 public void TestOwnerIsNotCurrentUser ( )
142123 {
143124 // arrange
@@ -150,7 +131,6 @@ public void TestOwnerIsNotCurrentUser()
150131 }
151132
152133 [ Test ]
153- [ Platform ( Exclude = "Win" ) ]
154134 public void TestFileIsNotSecureWhenNotOwnedByCurrentUser ( )
155135 {
156136 // arrange
@@ -171,7 +151,6 @@ public void TestFileIsNotSecureWhenNotOwnedByCurrentUser()
171151 }
172152
173153 [ Test ]
174- [ Platform ( Exclude = "Win" ) ]
175154 public void TestFileCopyUsesProperPermissions ( )
176155 {
177156 // arrange
@@ -193,7 +172,6 @@ public void TestFileCopyUsesProperPermissions()
193172 }
194173
195174 [ Test ]
196- [ Platform ( Exclude = "Win" ) ]
197175 public void TestFileCopyShouldThrowExecptionIfTooBroadPermissionsAreUsed ( )
198176 {
199177 // arrange
@@ -232,3 +210,4 @@ public static IEnumerable<FileAccessPermissions> InsecurePermissions()
232210 }
233211 }
234212}
213+
0 commit comments