Dropped Ledger Tables Folder (#1625)

* support and testing for Dropped Ledger Table folder

* appending DroppedLedgerTables nodetype

* fixing unit tests

* undoing string.Empty
This commit is contained in:
Jordan Hays
2022-08-09 14:17:51 -07:00
committed by GitHub
parent 091f2c942e
commit 485786f49e
11 changed files with 173 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
@@ -242,8 +243,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
//This takes take long to run so not a good test for CI builds
public async Task VerifySystemObjects()
{
string queryFileName = null;
string baselineFileName = null;
string queryFileName = string.Empty;
string baselineFileName = string.Empty;
string databaseName = "#testDb#";
await TestServiceProvider.CalculateRunTime(() => VerifyObjectExplorerTest(databaseName, queryFileName, "SystemOBjects", baselineFileName, true), true);
}
@@ -473,9 +474,13 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
{
string actual = stringBuilder.ToString();
// write output to a bin directory for easier comparison
string outputRegeneratedFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
@"ObjectExplorerServiceTests\Baselines\Regenerated");
// Dropped ledger objects have a randomly generated GUID appended to their name when they are deleted
// For testing purposes, those guids need to be replaced with a deterministic string
actual = Regex.Replace(actual, "[A-Z0-9]{32}", "<<NonDeterministic>>");
// Write output to a bin directory for easier comparison
string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
string outputRegeneratedFolder = Path.Combine(assemblyPath, @"ObjectExplorerServiceTests\Baselines\Regenerated");
string outputRegeneratedFilePath = Path.Combine(outputRegeneratedFolder, baselineFileName);
string msg = "";
@@ -488,8 +493,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.ObjectExplorer
}
catch (Exception e)
{
//We don't want to fail the test completely if we failed to write the regenerated baseline
//(especially if the test passed).
// We don't want to fail the test completely if we failed to write the regenerated baseline
// (especially if the test passed).
msg = $"Errors also occurred while attempting to write the new baseline file {outputRegeneratedFilePath} : {e.Message}";
}

View File

@@ -1,3 +1,21 @@
NodeType: Table Label: HumanResources.MSSQL_DroppedLedgerTable_Ledger_For_Drop_<<NonDeterministic>> SubType: Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status:
NodeType: Column Label: ledger_start_transaction_id (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_start_sequence_number (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_sequence_number (bigint, null) SubType: Status:
NodeType: HistoryTable Label: HumanResources.MSSQL_DroppedLedgerHistory_Ledger_For_Drop_History_<<NonDeterministic>> (History) SubType:LedgerHistory Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status:
NodeType: Column Label: ledger_start_transaction_id (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_start_sequence_number (bigint, not null) SubType: Status:
NodeType: Column Label: ledger_end_sequence_number (bigint, null) SubType: Status:
NodeType: Table Label: dbo.tableWithAllDataTypes SubType: Status:
NodeType: Column Label: cDecimal (decimal(18,5), null) SubType: Status:
NodeType: Column Label: cNumeric (numeric(18,2), null) SubType: Status:
@@ -198,6 +216,15 @@ NodeType: Column Label: ledger_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_sequence_number (bigint, null) SubType: Status:
NodeType: Column Label: ledger_operation_type (int, not null) SubType: Status:
NodeType: Column Label: ledger_operation_type_desc (nvarchar(6), not null) SubType: Status:
NodeType: View Label: HumanResources.MSSQL_DroppedLedgerView_Ledger_For_Drop_Ledger_<<NonDeterministic>> (Ledger) SubType:Ledger Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
NodeType: Column Label: OrganizationNode (hierarchyid, null) SubType: Status:
NodeType: Column Label: ledger_transaction_id (bigint, null) SubType: Status:
NodeType: Column Label: ledger_sequence_number (bigint, null) SubType: Status:
NodeType: Column Label: ledger_operation_type (int, not null) SubType: Status:
NodeType: Column Label: ledger_operation_type_desc (nvarchar(6), not null) SubType: Status:
NodeType: View Label: HumanResources.vEmployee SubType: Status:
NodeType: Column Label: BusinessEntityID (int, not null) SubType: Status:
NodeType: Column Label: Title (nvarchar(8), null) SubType: Status:

View File

@@ -219,6 +219,29 @@
GO
/****** Object: Table [HumanResources].[Ledger_For_Drop] Script Date: 7/19/2022 01:28:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [HumanResources].[Ledger_For_Drop](
[BusinessEntityID] [int] NOT NULL,
[NationalIDNumber] [nvarchar](15) NOT NULL,
[LoginID] [nvarchar](256) NOT NULL,
[OrganizationNode] [hierarchyid] NULL
)WITH (
LEDGER = ON,
SYSTEM_VERSIONING = ON ( HISTORY_TABLE = [HumanResources].[Ledger_For_Drop_History] )
)
GO
DROP TABLE [HumanResources].[Ledger_For_Drop]
GO
/****** Object: Table [HumanResources].[Employee] Script Date: 4/27/2017 11:50:15 AM ******/
SET ANSI_NULLS ON
GO

View File

@@ -48,7 +48,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
"testServer/Databases/testDatabase/Tables/testSchema.testTable",
"testServer/Databases/System Databases/testDatabase/Tables/testSchema.testTable",
"testServer/Databases/testDatabase/Tables/System Tables/testSchema.testTable",
"testServer/Databases/System Databases/testDatabase/Tables/System Tables/testSchema.testTable"
"testServer/Databases/System Databases/testDatabase/Tables/System Tables/testSchema.testTable",
"testServer/Databases/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable",
"testServer/Databases/System Databases/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable"
};
Assert.AreEqual(expectedPaths.Count, paths.Count);
@@ -61,11 +63,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
[Test]
public void FindCorrectPathsForTableWithDatabaseRoot()
{
var paths = NodePathGenerator.FindNodePaths(databaseSession, "Table", "testSchema", "testTable", null);
var paths = NodePathGenerator.FindNodePaths(databaseSession, "Table", "testSchema", "testTable", string.Empty);
var expectedPaths = new List<string>
{
"testServer/testDatabase/Tables/testSchema.testTable",
"testServer/testDatabase/Tables/System Tables/testSchema.testTable"
"testServer/testDatabase/Tables/System Tables/testSchema.testTable",
"testServer/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable"
};
Assert.AreEqual(expectedPaths.Count, paths.Count);
@@ -85,6 +88,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
"testServer/Databases/System Databases/testDatabase/Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Tables/System Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Tables/System Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Views/testSchema.testTable/Columns/testColumn",
"testServer/Databases/System Databases/testDatabase/Views/testSchema.testTable/Columns/testColumn",
"testServer/Databases/testDatabase/Views/System Views/testSchema.testTable/Columns/testColumn",
@@ -106,6 +111,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
"testServer/testDatabase/Tables/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Tables/System Tables/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Tables/Dropped Ledger Tables/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Views/testSchema.testTable/Columns/testColumn",
"testServer/testDatabase/Views/System Views/testSchema.testTable/Columns/testColumn"
};
@@ -120,7 +126,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
[Test]
public void FindCorrectPathsForDatabase()
{
var paths = NodePathGenerator.FindNodePaths(serverSession, "Database", null, databaseName, null);
var paths = NodePathGenerator.FindNodePaths(serverSession, "Database", null, databaseName, string.Empty);
var expectedPaths = new List<string>
{
"testServer/Databases/testDatabase",