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