-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to use regex patten for table exclude check when doing a backup
- Loading branch information
Showing
7 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...ure.Storage.Table.Backup.Tests/CoreHelpers.WindowsAzure.Storage.Table.Backup.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/> | ||
<PackageReference Include="xunit" Version="2.4.1"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CoreHelpers.WindowsAzure.Storage.Table.Backup\CoreHelpers.WindowsAzure.Storage.Table.Backup.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
31 changes: 31 additions & 0 deletions
31
CoreHelpers.WindowsAzure.Storage.Table.Backup.Tests/TableExcludeExpressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using CoreHelpers.WindowsAzure.Storage.Table.Backup.Internal; | ||
|
||
namespace CoreHelpers.WindowsAzure.Storage.Table.Backup.Tests; | ||
|
||
public class TableExcludeExpressionTests | ||
{ | ||
[Fact] | ||
public void VerifyFullTableNameTests() | ||
{ | ||
var validator = new TabledExcludeExpressionValidator(new string[] { "demoTable", "secondTable" }); | ||
Assert.True(validator.IsTableExcluded("demoTable")); | ||
Assert.True(validator.IsTableExcluded("demotable")); | ||
Assert.True(validator.IsTableExcluded("DEMOTABLE")); | ||
Assert.True(validator.IsTableExcluded("secondtable")); | ||
Assert.False(validator.IsTableExcluded("demo*")); | ||
Assert.False(validator.IsTableExcluded("*Table")); | ||
Assert.False(validator.IsTableExcluded("otherTable")); | ||
} | ||
|
||
[Fact] | ||
public void VerifyRegExPatternTableNameTests() | ||
{ | ||
var validator = new TabledExcludeExpressionValidator(new string[] { "demo.*" }); | ||
Assert.True(validator.IsTableExcluded("demoTable")); | ||
Assert.True(validator.IsTableExcluded("demotable")); | ||
Assert.True(validator.IsTableExcluded("DEMOTABLE")); | ||
Assert.True(validator.IsTableExcluded("demo*")); | ||
Assert.False(validator.IsTableExcluded("*Table")); | ||
Assert.False(validator.IsTableExcluded("otherTable")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
18 changes: 18 additions & 0 deletions
18
CoreHelpers.WindowsAzure.Storage.Table.Backup/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: AssemblyCompany("Core Helpers")] | ||
[assembly: AssemblyProduct("WindowsAzure.Storage.Table.Backup")] | ||
[assembly: AssemblyTitle("CoreHelpers Azure Storage Abstraction")] | ||
|
||
[assembly: AssemblyFileVersion("2.0.0.0")] | ||
[assembly: AssemblyVersion("2.0.0.0")] | ||
|
||
#if (DEBUG) | ||
[assembly: AssemblyConfiguration("Debug")] | ||
#else | ||
[assembly: AssemblyConfiguration("Release")] | ||
#endif | ||
|
||
[assembly: InternalsVisibleTo("CoreHelpers.WindowsAzure.Storage.Table.Backup.Tests")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
CoreHelpers.WindowsAzure.Storage.Table.Backup/Internal/TabledExcludeExpressionValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace CoreHelpers.WindowsAzure.Storage.Table.Backup.Internal; | ||
|
||
internal class TabledExcludeExpressionValidator | ||
{ | ||
private List<string> _excludes = new List<string>(); | ||
public TabledExcludeExpressionValidator(string[]? excludes) | ||
{ | ||
if (excludes != null) | ||
_excludes = excludes.Select(e => e.ToLower()).ToList(); | ||
} | ||
|
||
public bool IsTableExcluded(string tableName) | ||
{ | ||
// verify if the tablename is in the exclude list | ||
if (_excludes.Contains(tableName.ToLower())) | ||
return true; | ||
|
||
// verify if the tablename matches a regex pattern | ||
foreach (var exclude in _excludes) | ||
{ | ||
if (Regex.IsMatch(tableName, exclude, RegexOptions.IgnoreCase)) | ||
return true; | ||
} | ||
|
||
// all the rest don't exclude | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters