Skip to content

Commit 757c50b

Browse files
committed
Plug coverage hole.
1 parent e2df351 commit 757c50b

3 files changed

Lines changed: 52 additions & 30 deletions

File tree

PSql.Deploy.Tests/Commands/GetSqlMigrationsCommandTests.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ namespace PSql.Deploy.Commands;
88
using static ScriptExecutor;
99

1010
[TestFixture]
11+
[FixtureLifeCycle(LifeCycle.SingleInstance)]
1112
public class GetSqlMigrationsCommandTests
1213
{
1314
// This test fixture tests only discovery of migrations defined on disk.
1415
// Discovery of migrations registered in a target database is tested in
1516
// InvokeSqlMigrationsCommandIntegrationTests.
1617

1718
[Test]
18-
public void Invoke()
19+
public void Invoke_Path()
1920
{
2021
var (output, exception) = Execute(
2122
"""
@@ -32,9 +33,34 @@ public void Invoke()
3233
.Select(o => o.BaseObject.ShouldBeOfType<Migration>())
3334
.ToList();
3435

36+
ShouldBeTestDbADefinedMigrations(migrations);
37+
}
38+
39+
[Test]
40+
public void Invoke_Path_FromPipeline()
41+
{
42+
var (output, exception) = Execute(
43+
"""
44+
Join-Path TestDbs A | Get-SqlMigrations
45+
"""
46+
);
47+
48+
exception.ShouldBeNull();
49+
50+
output.Count.ShouldBe(5);
51+
52+
var migrations = output
53+
.Select(o => o.ShouldNotBeNull())
54+
.Select(o => o.BaseObject.ShouldBeOfType<Migration>())
55+
.ToList();
56+
57+
ShouldBeTestDbADefinedMigrations(migrations);
58+
}
59+
60+
private void ShouldBeTestDbADefinedMigrations(List<Migration> migrations)
61+
{
3562
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestDbs", "A");
3663

37-
// From Pre+Core run
3864
migrations[0].Name .ShouldBe("_Begin");
3965
migrations[0].Hash .ShouldBe("1FA5BB132E282E92E49B1F3C73E5CA91977D1B7A");
4066
migrations[0].Path .ShouldBe(Path.Combine(path, "Migrations", "_Begin", "_Main.sql"));

PSql.Deploy.Tests/Integration/InvokeSqlMigrationsCommandTests.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public void Invoke()
4141
-Path $Path `
4242
-Confirm: $false
4343
44-
Get-SqlMigrations -Target $TargetA
44+
# Test pipeline input
45+
$TargetA | Get-SqlMigrations
46+
[PSql.Deploy.SqlTargetDatabase]::new($TargetA) | Get-SqlMigrations
4547
"""
4648
);
4749

@@ -51,33 +53,29 @@ public void Invoke()
5153

5254
var migrations = output.Select(o => o?.BaseObject).OfType<Migration>().ToList();
5355

54-
migrations.Count.ShouldBe(6);
55-
56-
// From Pre+Core run
57-
migrations[0].Name .ShouldBe("Migration0");
58-
migrations[0].Hash .ShouldBe("D8462C316FD72659FB11FA7C9727D05707F8332B");
59-
migrations[0].State.ShouldBe(MigrationState.AppliedCore);
56+
migrations.Count.ShouldBe(9);
6057

61-
migrations[1].Name .ShouldBe("Migration1");
62-
migrations[1].Hash .ShouldBe("2909F7C67C9B831FFCD4655F31683941F700A205");
63-
migrations[1].State.ShouldBe(MigrationState.AppliedCore);
58+
void ShouldBeMigrations(int n, MigrationState state)
59+
{
60+
migrations[n + 0].Name .ShouldBe("Migration0");
61+
migrations[n + 0].Hash .ShouldBe("D8462C316FD72659FB11FA7C9727D05707F8332B");
62+
migrations[n + 0].State.ShouldBe(state);
6463

65-
migrations[2].Name .ShouldBe("Migration2");
66-
migrations[2].Hash .ShouldBe("FB049E6EA9DC10019088850C94E9C5D2661A6DE7");
67-
migrations[2].State.ShouldBe(MigrationState.AppliedCore);
64+
migrations[n + 1].Name .ShouldBe("Migration1");
65+
migrations[n + 1].Hash .ShouldBe("2909F7C67C9B831FFCD4655F31683941F700A205");
66+
migrations[n + 1].State.ShouldBe(state);
6867

69-
// From Post run
70-
migrations[3].Name .ShouldBe("Migration0");
71-
migrations[3].Hash .ShouldBe("D8462C316FD72659FB11FA7C9727D05707F8332B");
72-
migrations[3].State.ShouldBe(MigrationState.AppliedPost);
68+
migrations[n + 2].Name .ShouldBe("Migration2");
69+
migrations[n + 2].Hash .ShouldBe("FB049E6EA9DC10019088850C94E9C5D2661A6DE7");
70+
migrations[n + 2].State.ShouldBe(state);
71+
}
7372

74-
migrations[4].Name .ShouldBe("Migration1");
75-
migrations[4].Hash .ShouldBe("2909F7C67C9B831FFCD4655F31683941F700A205");
76-
migrations[4].State.ShouldBe(MigrationState.AppliedPost);
73+
// From Pre+Core run
74+
ShouldBeMigrations(0, MigrationState.AppliedCore);
7775

78-
migrations[5].Name .ShouldBe("Migration2");
79-
migrations[5].Hash .ShouldBe("FB049E6EA9DC10019088850C94E9C5D2661A6DE7");
80-
migrations[5].State.ShouldBe(MigrationState.AppliedPost);
76+
// From Post run
77+
ShouldBeMigrations(3, MigrationState.AppliedPost);
78+
ShouldBeMigrations(6, MigrationState.AppliedPost);
8179

8280
File.ReadAllText("..PSqlDeployTestA.0_Pre.log" ).ShouldNotBeNullOrEmpty();
8381
File.ReadAllText("..PSqlDeployTestA.1_Core.log").ShouldNotBeNullOrEmpty();

PSql.Deploy/Commands/GetSqlMigrationsCommand.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,9 @@ private bool IsForTarget()
106106
return false;
107107

108108
case nameof(Target):
109-
Assume.NotNull(Target);
109+
Assume.NotNull(Target); // due to [ValidateNotNullOrEmpty]
110110
return true;
111111

112-
case nameof(InputObject) when InputObject is null:
113-
return false;
114-
115112
case nameof(InputObject) when InputObject is string path && !path.Contains(';'):
116113
Path = path;
117114
return false;
@@ -121,7 +118,8 @@ private bool IsForTarget()
121118
return true;
122119

123120
default:
124-
Target = new SqlTargetDatabase(InputObject!);
121+
Assume.NotNull(InputObject); // due to [ValidateNotNullOrEmpty]
122+
Target = new SqlTargetDatabase(InputObject);
125123
return true;
126124
}
127125
}

0 commit comments

Comments
 (0)