Enforce generated text report identity
This commit is contained in:
@@ -8,17 +8,32 @@ import (
|
||||
)
|
||||
|
||||
func TestCatalogCompleteForGeneratedTextTemplateReports(t *testing.T) {
|
||||
for _, definition := range report.DefaultRegistry().All() {
|
||||
t.Run(string(definition.ID), func(t *testing.T) {
|
||||
expected := []struct {
|
||||
reportID report.ID
|
||||
schemaID string
|
||||
templateID string
|
||||
}{
|
||||
{reportID: report.Daily, schemaID: "daily", templateID: "daily"},
|
||||
{reportID: report.Today, schemaID: "today", templateID: "today"},
|
||||
{reportID: report.Tomorrow, schemaID: "tomorrow", templateID: "tomorrow"},
|
||||
{reportID: report.Hourly, schemaID: "hourly", templateID: "hourly"},
|
||||
}
|
||||
registry := report.DefaultRegistry()
|
||||
for _, expected := range expected {
|
||||
t.Run(string(expected.reportID), func(t *testing.T) {
|
||||
definition := registry.MustLookup(expected.reportID)
|
||||
if definition.GeneratedTextSchemaID != expected.schemaID || definition.TemplateID != expected.templateID {
|
||||
t.Fatalf("definition = %#v, want schema/template %q/%q", definition, expected.schemaID, expected.templateID)
|
||||
}
|
||||
handler, err := LookupDefinition(definition)
|
||||
if err != nil {
|
||||
t.Fatalf("LookupDefinition() error = %v", err)
|
||||
}
|
||||
if handler.SchemaID() != definition.GeneratedTextSchemaID {
|
||||
t.Fatalf("SchemaID() = %q, want %q", handler.SchemaID(), definition.GeneratedTextSchemaID)
|
||||
if handler.SchemaID() != expected.schemaID {
|
||||
t.Fatalf("SchemaID() = %q, want %q", handler.SchemaID(), expected.schemaID)
|
||||
}
|
||||
if handler.TemplateID() != definition.TemplateID {
|
||||
t.Fatalf("TemplateID() = %q, want %q", handler.TemplateID(), definition.TemplateID)
|
||||
if handler.TemplateID() != expected.templateID {
|
||||
t.Fatalf("TemplateID() = %q, want %q", handler.TemplateID(), expected.templateID)
|
||||
}
|
||||
if handler.validate == nil {
|
||||
t.Fatal("validator is nil")
|
||||
@@ -40,6 +55,35 @@ func TestCatalogCompleteForGeneratedTextTemplateReports(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalogRejectsKnownPairForAnotherReport(t *testing.T) {
|
||||
pairs := []struct {
|
||||
reportID report.ID
|
||||
schemaID string
|
||||
templateID string
|
||||
}{
|
||||
{reportID: report.Daily, schemaID: "daily", templateID: "daily"},
|
||||
{reportID: report.Today, schemaID: "today", templateID: "today"},
|
||||
{reportID: report.Tomorrow, schemaID: "tomorrow", templateID: "tomorrow"},
|
||||
{reportID: report.Hourly, schemaID: "hourly", templateID: "hourly"},
|
||||
}
|
||||
registry := report.DefaultRegistry()
|
||||
for _, definitionPair := range pairs {
|
||||
for _, mismatchedPair := range pairs {
|
||||
if definitionPair.reportID == mismatchedPair.reportID {
|
||||
continue
|
||||
}
|
||||
t.Run(string(definitionPair.reportID)+"/"+string(mismatchedPair.reportID), func(t *testing.T) {
|
||||
definition := registry.MustLookup(definitionPair.reportID)
|
||||
definition.GeneratedTextSchemaID = mismatchedPair.schemaID
|
||||
definition.TemplateID = mismatchedPair.templateID
|
||||
if _, err := LookupDefinition(definition); err == nil || !strings.Contains(err.Error(), "do not belong") {
|
||||
t.Fatalf("LookupDefinition(%#v) error = %v, want wrong-report error", definition, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCatalogLookupRejectsUnsupportedSchemaAndTemplate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user