Skip to content

Commit

Permalink
More data pipeline tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed May 16, 2020
1 parent 0474818 commit 695a8f8
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 62 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<!-- Controls whether references are local projects or NuGet packages -->
<LocalReferences>false</LocalReferences>
<LocalReferences>true</LocalReferences>
<!-- The NuGet version of Statiq that should be referenced if LocalReferences is false -->
<StatiqFrameworkVersion>1.0.0-beta.10</StatiqFrameworkVersion>
<StatiqFrameworkVersion>1.0.0-beta.11</StatiqFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/Statiq.Web/Modules/ApplyDirectoryMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override IEnumerable<IDocument> ExecuteContext(IExecutionContext conte
.ToImmutableArray());

// Iterate through all input documents in parallel
return context.Inputs.Select(input =>
IEnumerable<IDocument> results = context.Inputs.Select(input =>
{
IDocument merged = input;
Expand Down Expand Up @@ -65,6 +65,7 @@ protected override IEnumerable<IDocument> ExecuteContext(IExecutionContext conte
return merged;
});
return results;
}

private class DirectoryMetadataData
Expand Down
55 changes: 0 additions & 55 deletions tests/Statiq.Web.Tests/BootstrapperExtensions.cs

This file was deleted.

136 changes: 132 additions & 4 deletions tests/Statiq.Web.Tests/Pipelines/DataFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using Shouldly;
Expand All @@ -26,10 +27,11 @@ public async Task ParsesJson()
};

// When
ImmutableArray<IDocument> outputs = await bootstrapper.RunTestAsync(nameof(Data), Phase.Process, fileProvider);
BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

// Then
IDocument document = outputs.ShouldHaveSingleItem();
result.ExitCode.ShouldBe((int)ExitCode.Normal);
IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();
document["Foo"].ShouldBe("Bar");
}

Expand All @@ -44,10 +46,136 @@ public async Task ParsesYaml()
};

// When
ImmutableArray<IDocument> outputs = await bootstrapper.RunTestAsync(nameof(Data), Phase.Process, fileProvider);
BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

// Then
IDocument document = outputs.ShouldHaveSingleItem();
result.ExitCode.ShouldBe((int)ExitCode.Normal);
IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();
document["Foo"].ShouldBe("Bar");
}

[Test]
public async Task HonorsDataFilesSetting()
{
// Given
Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty<string>());
bootstrapper.AddSetting(WebKeys.DataFiles, "x/**/*.json");
TestFileProvider fileProvider = new TestFileProvider
{
{ "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
{ "/input/x/y/z.json", "{ \"Foo\": \"Buz\" }" }
};

// When
BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

// Then
result.ExitCode.ShouldBe((int)ExitCode.Normal);
IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();
document["Foo"].ShouldBe("Buz");
}

[Test]
public async Task SupportsMultipleDataFilesPatterns()
{
// Given
Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty<string>());
bootstrapper.AddSetting(WebKeys.DataFiles, new[] { "a/**/*.json", "x/**/*.json" });
TestFileProvider fileProvider = new TestFileProvider
{
{ "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
{ "/input/x/y/z.json", "{ \"Foo\": \"Buz\" }" }
};

// When
BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

// Then
result.ExitCode.ShouldBe((int)ExitCode.Normal);
result.Outputs[nameof(Data)][Phase.Process].Select(x => x["Foo"]).ShouldBe(new[] { "Bar", "Buz" }, true);
}

[Test]
public async Task IncludesDocumentsFromDependencies()
{
// Given
Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty<string>());
bootstrapper.AddSetting(WebKeys.DataFiles, "x/**/*.json");
bootstrapper.BuildPipeline("Test", builder => builder
.WithInputReadFiles("a/**/*.json")
.AsDependencyOf(nameof(Data)));
TestFileProvider fileProvider = new TestFileProvider
{
{ "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
{ "/input/x/y/z.json", "{ \"Foo\": \"Buz\" }" }
};

// When
BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

// Then
result.ExitCode.ShouldBe((int)ExitCode.Normal);
result.Outputs[nameof(Data)][Phase.Process].Select(x => x["Foo"]).ShouldBe(new[] { "Bar", "Buz" }, true);
}

[Test]
public async Task AddsDiectoryMetadata()
{
// Given
Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty<string>());
TestFileProvider fileProvider = new TestFileProvider
{
{ "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
{ "/input/a/_directory.json", "{ \"Fizz\": \"Buzz\" }" }
};

// When
BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

// Then
result.ExitCode.ShouldBe((int)ExitCode.Normal);
IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();
document["Foo"].ShouldBe("Bar");
document["Fizz"].ShouldBe("Buzz");
}

[Test]
public async Task FiltersExcludedFiles()
{
// Given
Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty<string>());
TestFileProvider fileProvider = new TestFileProvider
{
{ "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
{ "/input/x/y/z.json", "{ \"Excluded\": \"true\" }" }
};

// When
BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

// Then
result.ExitCode.ShouldBe((int)ExitCode.Normal);
IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();
document["Foo"].ShouldBe("Bar");
}

[Test]
public async Task DoesNotReadUnderscoreFilesByDefault()
{
// Given
Bootstrapper bootstrapper = Bootstrapper.Factory.CreateWeb(Array.Empty<string>());
TestFileProvider fileProvider = new TestFileProvider
{
{ "/input/a/b/c.json", "{ \"Foo\": \"Bar\" }" },
{ "/input/x/y/_z.json", "{ \"Fizz\": \"Buzz\" }" }
};

// When
BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider);

// Then
result.ExitCode.ShouldBe((int)ExitCode.Normal);
IDocument document = result.Outputs[nameof(Data)][Phase.Process].ShouldHaveSingleItem();
document["Foo"].ShouldBe("Bar");
}
}
Expand Down

0 comments on commit 695a8f8

Please sign in to comment.