Add report distributor path defaults
This commit is contained in:
@@ -18,11 +18,15 @@ func dailyDefinition() Definition {
|
|||||||
ComparisonStrategy: CompareSameValidDate,
|
ComparisonStrategy: CompareSameValidDate,
|
||||||
ArtifactGroup: "daily",
|
ArtifactGroup: "daily",
|
||||||
BatchOutputName: "daily.md",
|
BatchOutputName: "daily.md",
|
||||||
Generated: true,
|
DistributorPathTemplates: []string{
|
||||||
CompatiblePriorIDs: []ID{Daily},
|
"daily/{valid_start_date}/{run_id}.md",
|
||||||
Modules: dailyModules(),
|
"daily/{valid_start_date}/index.md",
|
||||||
resolve: resolveDaily,
|
},
|
||||||
runIDDisambiguator: validStartDateRunIDDisambiguator,
|
Generated: true,
|
||||||
|
CompatiblePriorIDs: []ID{Daily},
|
||||||
|
Modules: dailyModules(),
|
||||||
|
resolve: resolveDaily,
|
||||||
|
runIDDisambiguator: validStartDateRunIDDisambiguator,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,22 +46,23 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Definition struct {
|
type Definition struct {
|
||||||
ID ID
|
ID ID
|
||||||
Name string
|
Name string
|
||||||
PromptID string
|
PromptID string
|
||||||
GenerationMode GenerationMode
|
GenerationMode GenerationMode
|
||||||
TemplateID string
|
TemplateID string
|
||||||
GeneratedTextSchemaID string
|
GeneratedTextSchemaID string
|
||||||
ComparisonStrategy ComparisonStrategy
|
ComparisonStrategy ComparisonStrategy
|
||||||
ArtifactGroup string
|
ArtifactGroup string
|
||||||
BatchOutputName string
|
BatchOutputName string
|
||||||
Generated bool
|
DistributorPathTemplates []string
|
||||||
CompatiblePriorIDs []ID
|
Generated bool
|
||||||
Modules []module.ConfigItem
|
CompatiblePriorIDs []ID
|
||||||
Morning bool
|
Modules []module.ConfigItem
|
||||||
Evening bool
|
Morning bool
|
||||||
resolve func(ResolveRequest) (timeutil.Period, error)
|
Evening bool
|
||||||
runIDDisambiguator func(Resolved) string
|
resolve func(ResolveRequest) (timeutil.Period, error)
|
||||||
|
runIDDisambiguator func(Resolved) string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Definition) ResolvePeriod(req ResolveRequest) (timeutil.Period, error) {
|
func (d Definition) ResolvePeriod(req ResolveRequest) (timeutil.Period, error) {
|
||||||
|
|||||||
@@ -20,10 +20,13 @@ func hourlyDefinition() Definition {
|
|||||||
ComparisonStrategy: CompareRollingWindow,
|
ComparisonStrategy: CompareRollingWindow,
|
||||||
ArtifactGroup: "hourly",
|
ArtifactGroup: "hourly",
|
||||||
BatchOutputName: "hourly.md",
|
BatchOutputName: "hourly.md",
|
||||||
Generated: true,
|
DistributorPathTemplates: []string{
|
||||||
CompatiblePriorIDs: []ID{Hourly},
|
"hourly/index.md",
|
||||||
Modules: hourlyModules(),
|
},
|
||||||
resolve: resolveHourly,
|
Generated: true,
|
||||||
|
CompatiblePriorIDs: []ID{Hourly},
|
||||||
|
Modules: hourlyModules(),
|
||||||
|
resolve: resolveHourly,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -520,6 +520,88 @@ func TestRegistryDefinitionsDeclarePathAndCompatibilityPolicy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGeneratedRegistryDefinitionsDeclareDistributorPathDefaults(t *testing.T) {
|
||||||
|
for _, definition := range DefaultRegistry().All() {
|
||||||
|
if !definition.Generated {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(definition.DistributorPathTemplates) == 0 {
|
||||||
|
t.Fatalf("%s DistributorPathTemplates is empty", definition.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegistryDefinitionsDeclareDefaultDistributorPathTemplates(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
id ID
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
id: Hourly,
|
||||||
|
want: []string{
|
||||||
|
"hourly/index.md",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Daily,
|
||||||
|
want: []string{
|
||||||
|
"daily/{valid_start_date}/{run_id}.md",
|
||||||
|
"daily/{valid_start_date}/index.md",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Today,
|
||||||
|
want: []string{
|
||||||
|
"daily/{valid_start_date}/{run_id}.md",
|
||||||
|
"daily/{valid_start_date}/index.md",
|
||||||
|
"today/index.md",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Tomorrow,
|
||||||
|
want: []string{
|
||||||
|
"daily/{valid_start_date}/{run_id}.md",
|
||||||
|
"daily/{valid_start_date}/index.md",
|
||||||
|
"tomorrow/index.md",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: ThreeDay,
|
||||||
|
want: []string{
|
||||||
|
"three-day/{valid_start_date}/{run_id}.md",
|
||||||
|
"three-day/{valid_start_date}/index.md",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Weekend,
|
||||||
|
want: []string{
|
||||||
|
"weekend/{valid_start_date}/{run_id}.md",
|
||||||
|
"weekend/{valid_start_date}/index.md",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: Storm,
|
||||||
|
want: []string{
|
||||||
|
"storm/{storm_id}/{run_id}.md",
|
||||||
|
"storm/{storm_id}/index.md",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
registry := DefaultRegistry()
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(string(tt.id), func(t *testing.T) {
|
||||||
|
definition, err := registry.Lookup(tt.id)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Lookup() error = %v", err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(definition.DistributorPathTemplates, tt.want) {
|
||||||
|
t.Fatalf("DistributorPathTemplates = %#v, want %#v", definition.DistributorPathTemplates, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRegistryDefinitionsDeclareDefaultModules(t *testing.T) {
|
func TestRegistryDefinitionsDeclareDefaultModules(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
id ID
|
id ID
|
||||||
@@ -682,6 +764,9 @@ func TestRegistryAppliesModuleOverridesWithoutChangingDefaults(t *testing.T) {
|
|||||||
if len(defaultDefinition.ModuleIDs()) <= len(definition.ModuleIDs()) {
|
if len(defaultDefinition.ModuleIDs()) <= len(definition.ModuleIDs()) {
|
||||||
t.Fatalf("default ModuleIDs() = %#v, want original defaults unchanged", defaultDefinition.ModuleIDs())
|
t.Fatalf("default ModuleIDs() = %#v, want original defaults unchanged", defaultDefinition.ModuleIDs())
|
||||||
}
|
}
|
||||||
|
if !reflect.DeepEqual(definition.DistributorPathTemplates, defaultDefinition.DistributorPathTemplates) {
|
||||||
|
t.Fatalf("overridden DistributorPathTemplates = %#v, want %#v", definition.DistributorPathTemplates, defaultDefinition.DistributorPathTemplates)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRegistryRejectsModuleOverrideForUnknownReport(t *testing.T) {
|
func TestRegistryRejectsModuleOverrideForUnknownReport(t *testing.T) {
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ func DefaultRegistry() Registry {
|
|||||||
func (r Registry) WithModuleOverrides(overrides map[ID][]module.ConfigItem) (Registry, error) {
|
func (r Registry) WithModuleOverrides(overrides map[ID][]module.ConfigItem) (Registry, error) {
|
||||||
next := Registry{definitions: map[ID]Definition{}}
|
next := Registry{definitions: map[ID]Definition{}}
|
||||||
for id, definition := range r.definitions {
|
for id, definition := range r.definitions {
|
||||||
definition.Modules = append([]module.ConfigItem(nil), definition.Modules...)
|
next.definitions[id] = cloneDefinition(definition)
|
||||||
next.definitions[id] = definition
|
|
||||||
}
|
}
|
||||||
for id, items := range overrides {
|
for id, items := range overrides {
|
||||||
definition, ok := next.definitions[id]
|
definition, ok := next.definitions[id]
|
||||||
@@ -44,6 +43,12 @@ func (r Registry) WithModuleOverrides(overrides map[ID][]module.ConfigItem) (Reg
|
|||||||
return next, nil
|
return next, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cloneDefinition(definition Definition) Definition {
|
||||||
|
definition.Modules = cloneModuleItems(definition.Modules)
|
||||||
|
definition.DistributorPathTemplates = append([]string(nil), definition.DistributorPathTemplates...)
|
||||||
|
return definition
|
||||||
|
}
|
||||||
|
|
||||||
func moduleItems(ids ...module.ID) []module.ConfigItem {
|
func moduleItems(ids ...module.ID) []module.ConfigItem {
|
||||||
items := make([]module.ConfigItem, 0, len(ids))
|
items := make([]module.ConfigItem, 0, len(ids))
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ func stormDefinition() Definition {
|
|||||||
ComparisonStrategy: CompareExplicitWindow,
|
ComparisonStrategy: CompareExplicitWindow,
|
||||||
ArtifactGroup: "storm",
|
ArtifactGroup: "storm",
|
||||||
BatchOutputName: "storm.md",
|
BatchOutputName: "storm.md",
|
||||||
|
DistributorPathTemplates: []string{
|
||||||
|
"storm/{storm_id}/{run_id}.md",
|
||||||
|
"storm/{storm_id}/index.md",
|
||||||
|
},
|
||||||
Generated: true,
|
Generated: true,
|
||||||
CompatiblePriorIDs: []ID{Storm},
|
CompatiblePriorIDs: []ID{Storm},
|
||||||
Modules: stormModules(),
|
Modules: stormModules(),
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ func threeDayDefinition() Definition {
|
|||||||
ComparisonStrategy: CompareSameValidDate,
|
ComparisonStrategy: CompareSameValidDate,
|
||||||
ArtifactGroup: "three-day",
|
ArtifactGroup: "three-day",
|
||||||
BatchOutputName: "three-day.md",
|
BatchOutputName: "three-day.md",
|
||||||
|
DistributorPathTemplates: []string{
|
||||||
|
"three-day/{valid_start_date}/{run_id}.md",
|
||||||
|
"three-day/{valid_start_date}/index.md",
|
||||||
|
},
|
||||||
Generated: true,
|
Generated: true,
|
||||||
CompatiblePriorIDs: []ID{ThreeDay},
|
CompatiblePriorIDs: []ID{ThreeDay},
|
||||||
Modules: threeDayModules(),
|
Modules: threeDayModules(),
|
||||||
|
|||||||
@@ -16,11 +16,16 @@ func todayDefinition() Definition {
|
|||||||
ComparisonStrategy: CompareSameValidDate,
|
ComparisonStrategy: CompareSameValidDate,
|
||||||
ArtifactGroup: "today",
|
ArtifactGroup: "today",
|
||||||
BatchOutputName: "today.md",
|
BatchOutputName: "today.md",
|
||||||
Generated: true,
|
DistributorPathTemplates: []string{
|
||||||
CompatiblePriorIDs: []ID{Today},
|
"daily/{valid_start_date}/{run_id}.md",
|
||||||
Modules: todayModules(),
|
"daily/{valid_start_date}/index.md",
|
||||||
Morning: true,
|
"today/index.md",
|
||||||
resolve: resolveToday,
|
},
|
||||||
|
Generated: true,
|
||||||
|
CompatiblePriorIDs: []ID{Today},
|
||||||
|
Modules: todayModules(),
|
||||||
|
Morning: true,
|
||||||
|
resolve: resolveToday,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,16 @@ func tomorrowDefinition() Definition {
|
|||||||
ComparisonStrategy: CompareSameValidDate,
|
ComparisonStrategy: CompareSameValidDate,
|
||||||
ArtifactGroup: "tomorrow",
|
ArtifactGroup: "tomorrow",
|
||||||
BatchOutputName: "tomorrow.md",
|
BatchOutputName: "tomorrow.md",
|
||||||
Generated: true,
|
DistributorPathTemplates: []string{
|
||||||
CompatiblePriorIDs: []ID{Tomorrow},
|
"daily/{valid_start_date}/{run_id}.md",
|
||||||
Modules: tomorrowModules(),
|
"daily/{valid_start_date}/index.md",
|
||||||
Evening: true,
|
"tomorrow/index.md",
|
||||||
resolve: resolveTomorrow,
|
},
|
||||||
|
Generated: true,
|
||||||
|
CompatiblePriorIDs: []ID{Tomorrow},
|
||||||
|
Modules: tomorrowModules(),
|
||||||
|
Evening: true,
|
||||||
|
resolve: resolveTomorrow,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ func weekendDefinition() Definition {
|
|||||||
ComparisonStrategy: CompareWeekendWindow,
|
ComparisonStrategy: CompareWeekendWindow,
|
||||||
ArtifactGroup: "weekend",
|
ArtifactGroup: "weekend",
|
||||||
BatchOutputName: "weekend.md",
|
BatchOutputName: "weekend.md",
|
||||||
|
DistributorPathTemplates: []string{
|
||||||
|
"weekend/{valid_start_date}/{run_id}.md",
|
||||||
|
"weekend/{valid_start_date}/index.md",
|
||||||
|
},
|
||||||
Generated: true,
|
Generated: true,
|
||||||
CompatiblePriorIDs: []ID{Weekend},
|
CompatiblePriorIDs: []ID{Weekend},
|
||||||
Modules: weekendModules(),
|
Modules: weekendModules(),
|
||||||
|
|||||||
Reference in New Issue
Block a user