Skip to content

Commit

Permalink
SNOW-990111: Add test for EasyLoggerUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Jan 24, 2024
1 parent 1c43705 commit eff9425
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 1 deletion.
225 changes: 225 additions & 0 deletions Snowflake.Data.Tests/UnitTests/Logger/EasyLoggerUtilTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/*
* Copyright (c) 2023 Snowflake Computing Inc. All rights reserved.
*/

using Mono.Unix;
using NUnit.Framework;
using Snowflake.Data.Log;
using System;
using System.Collections.Generic;

namespace Snowflake.Data.Tests.UnitTests.Logger
{
[TestFixture]
public class EasyLoggerUtilTest
{
[Test]
public void TestConversionForAllPermissionCombinations(
[ValueSource(nameof(UserPermissionTestCases))] PermissionTestCase userTestCase,
[ValueSource(nameof(GroupPermissionTestCases))] PermissionTestCase groupTestCase,
[ValueSource(nameof(OtherPermissionTestCases))] PermissionTestCase otherTestCase)
{
// arrange
var permissions = userTestCase.permissions | groupTestCase.permissions | otherTestCase.permissions;
var expectedPermissions = userTestCase.expectedPermissions + groupTestCase.expectedPermissions + otherTestCase.expectedPermissions;

// act
var convertedPermissions = EasyLoggerUtil.ConvertFileAccessPermissionsToInt(permissions);

// assert
Assert.AreEqual(expectedPermissions, convertedPermissions);
}

public static IEnumerable<PermissionTestCase> UserPermissionTestCases()
{
var noPermissionTestCase = new PermissionTestCase()
{
expectedPermissions = 000
};

var readPermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.UserRead,
expectedPermissions = 400
};

var writePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.UserWrite,
expectedPermissions = 200
};

var executePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.UserExecute,
expectedPermissions = 100
};

var readWritePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.UserRead | FileAccessPermissions.UserWrite,
expectedPermissions = 600
};

var readExecutePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.UserRead | FileAccessPermissions.UserExecute,
expectedPermissions = 500
};

var writeExecutePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.UserWrite | FileAccessPermissions.UserExecute,
expectedPermissions = 300
};

var allPermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.UserReadWriteExecute,
expectedPermissions = 700
};

return new[]
{
noPermissionTestCase,
readPermissionsTestCase,
writePermissionsTestCase,
executePermissionsTestCase,
readWritePermissionsTestCase,
readExecutePermissionsTestCase,
writeExecutePermissionsTestCase,
allPermissionsTestCase
};
}

public static IEnumerable<PermissionTestCase> GroupPermissionTestCases()
{
var noPermissionTestCase = new PermissionTestCase()
{
expectedPermissions = 000
};

var readPermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.GroupRead,
expectedPermissions = 040
};

var writePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.GroupWrite,
expectedPermissions = 020
};

var executePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.GroupExecute,
expectedPermissions = 010
};

var readWritePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.GroupRead | FileAccessPermissions.GroupWrite,
expectedPermissions = 060
};

var readExecutePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.GroupRead | FileAccessPermissions.GroupExecute,
expectedPermissions = 050
};

var writeExecutePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.GroupWrite | FileAccessPermissions.GroupExecute,
expectedPermissions = 030
};

var allPermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.GroupReadWriteExecute,
expectedPermissions = 070
};

return new[]
{
noPermissionTestCase,
readPermissionsTestCase,
writePermissionsTestCase,
executePermissionsTestCase,
readWritePermissionsTestCase,
readExecutePermissionsTestCase,
writeExecutePermissionsTestCase,
allPermissionsTestCase
};
}

public static IEnumerable<PermissionTestCase> OtherPermissionTestCases()
{
var noPermissionTestCase = new PermissionTestCase()
{
expectedPermissions = 000
};

var readPermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.OtherRead,
expectedPermissions = 004
};

var writePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.OtherWrite,
expectedPermissions = 002
};

var executePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.OtherExecute,
expectedPermissions = 001
};

var readWritePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.OtherRead | FileAccessPermissions.OtherWrite,
expectedPermissions = 006
};

var readExecutePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.OtherRead | FileAccessPermissions.OtherExecute,
expectedPermissions = 005
};

var writeExecutePermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.OtherWrite | FileAccessPermissions.OtherExecute,
expectedPermissions = 003
};

var allPermissionsTestCase = new PermissionTestCase()
{
permissions = FileAccessPermissions.OtherReadWriteExecute,
expectedPermissions = 007
};

return new[]
{
noPermissionTestCase,
readPermissionsTestCase,
writePermissionsTestCase,
executePermissionsTestCase,
readWritePermissionsTestCase,
readExecutePermissionsTestCase,
writeExecutePermissionsTestCase,
allPermissionsTestCase
};
}

public class PermissionTestCase
{
internal FileAccessPermissions permissions;
internal int expectedPermissions;
}
}
}
1 change: 0 additions & 1 deletion Snowflake.Data/Logger/EasyLoggerUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

using System;
using System.Diagnostics;
using Mono.Unix;

namespace Snowflake.Data.Log
Expand Down

0 comments on commit eff9425

Please sign in to comment.