Add daily render context
This commit is contained in:
@@ -279,9 +279,29 @@ func TestCatalogBuildRenderContextRejectsMismatchedGeneratedText(t *testing.T) {
|
||||
if !strings.Contains(err.Error(), `requires today generated text`) {
|
||||
t.Fatalf("BuildRenderContext(today) error = %v, want today generated text requirement", err)
|
||||
}
|
||||
|
||||
dailyHandler, err := LookupDefinition(report.Definition{
|
||||
ID: report.ID("daily"),
|
||||
GenerationMode: report.GenerationModeGeneratedTextTemplate,
|
||||
GeneratedTextSchemaID: "daily",
|
||||
TemplateID: "daily",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("LookupDefinition(daily) error = %v", err)
|
||||
}
|
||||
_, err = dailyHandler.BuildRenderContext(testDailyMetadata(), testDailySnapshot(t), testCollected(), testDailyDerived(), Tomorrow{
|
||||
Summary: "Storms become more likely tomorrow.",
|
||||
ForecastDiscussion: []string{"A front will keep showers in the forecast."},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("BuildRenderContext(daily) error = nil, want type mismatch")
|
||||
}
|
||||
if !strings.Contains(err.Error(), `requires daily generated text`) {
|
||||
t.Fatalf("BuildRenderContext(daily) error = %v, want daily generated text requirement", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalogBuildRenderContextRejectsDailyUntilContextExists(t *testing.T) {
|
||||
func TestCatalogBuildRenderContextSupportsDaily(t *testing.T) {
|
||||
handler, err := LookupDefinition(report.Definition{
|
||||
ID: report.ID("daily"),
|
||||
GenerationMode: report.GenerationModeGeneratedTextTemplate,
|
||||
@@ -291,14 +311,14 @@ func TestCatalogBuildRenderContextRejectsDailyUntilContextExists(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("LookupDefinition(daily) error = %v", err)
|
||||
}
|
||||
_, err = handler.BuildRenderContext(testTomorrowMetadata(), testTomorrowSnapshot(t), testCollected(), testTomorrowDerived(), Daily{
|
||||
ctx, err := handler.BuildRenderContext(testDailyMetadata(), testDailySnapshot(t), testCollected(), testDailyDerived(), Daily{
|
||||
Summary: "Showers are possible during the selected day.",
|
||||
ForecastDiscussion: []string{"A front will keep rain chances in the forecast."},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("BuildRenderContext(daily) error = nil, want missing builder")
|
||||
if err != nil {
|
||||
t.Fatalf("BuildRenderContext(daily) error = %v", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), `render-context builder is not registered for template "daily"`) {
|
||||
t.Fatalf("BuildRenderContext(daily) error = %v, want missing daily builder", err)
|
||||
if _, ok := ctx.(DailyRenderContext); !ok {
|
||||
t.Fatalf("BuildRenderContext(daily) = %T, want DailyRenderContext", ctx)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user