Skip to content

Commit baa0c1b

Browse files
committed
Split Windows/Unix tests
1 parent 59d3c5f commit baa0c1b

File tree

2 files changed

+64
-35
lines changed

2 files changed

+64
-35
lines changed

Snowflake.Data.Tests/UnitTests/Tools/FileOperationsTest.cs renamed to Snowflake.Data.Tests/UnitTests/Tools/FileOperationsUnixTest.cs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
namespace Snowflake.Data.Tests.UnitTests.Tools
1313
{
1414
[TestFixture, NonParallelizable]
15-
public class FileOperationsTest
15+
[Platform(Exclude = "Win")]
16+
public class FileOperationsUnixTest
1617
{
1718
private static FileOperations s_fileOperations;
1819
private static readonly string s_relativeWorkingDirectory = $"file_operations_test_{Path.GetRandomFileName()}";
@@ -38,20 +39,6 @@ public static void After()
3839
}
3940

4041
[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")]
5542
public void TestReadAllTextCheckingPermissionsUsingTomlConfigurationFileValidations(
5643
[ValueSource(nameof(UserAllowedFilePermissions))]
5744
FileAccessPermissions userAllowedFilePermissions)
@@ -69,7 +56,6 @@ public void TestReadAllTextCheckingPermissionsUsingTomlConfigurationFileValidati
6956
}
7057

7158
[Test]
72-
[Platform(Exclude = "Win")]
7359
public void TestShouldThrowExceptionIfOtherPermissionsIsSetWhenReadConfigurationFile(
7460
[ValueSource(nameof(UserAllowedFilePermissions))]
7561
FileAccessPermissions userAllowedFilePermissions)
@@ -86,7 +72,6 @@ public void TestShouldThrowExceptionIfOtherPermissionsIsSetWhenReadConfiguration
8672

8773

8874
[Test]
89-
[Platform(Exclude = "Win")]
9075
public void TestFileIsSafeOnNotWindows()
9176
{
9277
// arrange
@@ -98,7 +83,6 @@ public void TestFileIsSafeOnNotWindows()
9883
}
9984

10085
[Test]
101-
[Platform(Exclude = "Win")]
10286
public void TestFileIsNotSafeOnNotWindowsWhenTooBroadPermissionsAreUsed(
10387
[ValueSource(nameof(InsecurePermissions))]
10488
FileAccessPermissions permissions)
@@ -112,19 +96,6 @@ public void TestFileIsNotSafeOnNotWindowsWhenTooBroadPermissionsAreUsed(
11296
}
11397

11498
[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")]
12899
public void TestOwnerIsCurrentUser()
129100
{
130101
// arrange
@@ -137,7 +108,6 @@ public void TestOwnerIsCurrentUser()
137108
}
138109

139110
[Test]
140-
[Platform(Exclude = "Win")]
141111
public void TestOwnerIsNotCurrentUser()
142112
{
143113
// arrange
@@ -150,7 +120,6 @@ public void TestOwnerIsNotCurrentUser()
150120
}
151121

152122
[Test]
153-
[Platform(Exclude = "Win")]
154123
public void TestFileIsNotSecureWhenNotOwnedByCurrentUser()
155124
{
156125
// arrange
@@ -171,7 +140,6 @@ public void TestFileIsNotSecureWhenNotOwnedByCurrentUser()
171140
}
172141

173142
[Test]
174-
[Platform(Exclude = "Win")]
175143
public void TestFileCopyUsesProperPermissions()
176144
{
177145
// arrange
@@ -193,7 +161,6 @@ public void TestFileCopyUsesProperPermissions()
193161
}
194162

195163
[Test]
196-
[Platform(Exclude = "Win")]
197164
public void TestFileCopyShouldThrowExecptionIfTooBroadPermissionsAreUsed()
198165
{
199166
// arrange
@@ -232,3 +199,4 @@ public static IEnumerable<FileAccessPermissions> InsecurePermissions()
232199
}
233200
}
234201
}
202+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.IO;
2+
using NUnit.Framework;
3+
using Snowflake.Data.Core;
4+
using Snowflake.Data.Core.Tools;
5+
using Snowflake.Data.Tests.Mock;
6+
using static Snowflake.Data.Tests.UnitTests.Configuration.EasyLoggingConfigGenerator;
7+
8+
namespace Snowflake.Data.Tests.UnitTests.Tools
9+
{
10+
[TestFixture, NonParallelizable]
11+
[Platform("Win")]
12+
public class FileOperationsWindowsTest
13+
{
14+
private static FileOperations s_fileOperations;
15+
private static readonly string s_relativeWorkingDirectory = $"file_operations_test_{Path.GetRandomFileName()}";
16+
private static readonly string s_workingDirectory = Path.Combine(TempUtil.GetTempPath(), s_relativeWorkingDirectory);
17+
private static readonly string s_content = "random text";
18+
private static readonly string s_fileName = "testfile";
19+
20+
[SetUp]
21+
public static void Before()
22+
{
23+
if (!Directory.Exists(s_workingDirectory))
24+
{
25+
Directory.CreateDirectory(s_workingDirectory);
26+
}
27+
28+
s_fileOperations = new FileOperations();
29+
}
30+
31+
[TearDown]
32+
public static void After()
33+
{
34+
Directory.Delete(s_workingDirectory, true);
35+
}
36+
37+
[Test]
38+
public void TestReadAllTextOnWindows()
39+
{
40+
var filePath = CreateConfigTempFile(s_workingDirectory, s_content);
41+
42+
// act
43+
var result = s_fileOperations.ReadAllText(filePath, TomlConnectionBuilder.ValidateFilePermissions);
44+
45+
// assert
46+
Assert.AreEqual(s_content, result);
47+
}
48+
49+
[Test]
50+
public void TestFileIsSafeOnWindows()
51+
{
52+
// arrange
53+
var absoluteFilePath = Path.Combine(s_workingDirectory, s_fileName);
54+
File.Create(absoluteFilePath).Close();
55+
56+
// act and assert
57+
Assert.IsTrue(s_fileOperations.IsFileSafe(absoluteFilePath));
58+
}
59+
}
60+
}
61+

0 commit comments

Comments
 (0)