Generalize distributor report path rendering
This commit is contained in:
@@ -1317,35 +1317,38 @@ func TestDistributorTemplateRendering(t *testing.T) {
|
||||
ValidEndTime: "0600",
|
||||
ValidStartStamp: "2026-06-07T1800",
|
||||
ValidEndStamp: "2026-06-08T0600",
|
||||
StormID: "2026-06-07T1800-2026-06-08T0600",
|
||||
BundleID: "weatherreporter.home.daily",
|
||||
}
|
||||
|
||||
bundleID, err := RenderDistributorBundleID("weatherreporter.{location_id}.{report_id}", values)
|
||||
bundleID, err := RenderDistributorBundleID("weatherreporter.{location_id}.{report_id}.{storm_id}", values)
|
||||
if err != nil {
|
||||
t.Fatalf("RenderDistributorBundleID() error = %v", err)
|
||||
}
|
||||
if bundleID != "weatherreporter.home.daily" {
|
||||
if bundleID != "weatherreporter.home.daily.2026-06-07T1800-2026-06-08T0600" {
|
||||
t.Fatalf("bundleID = %q, want rendered value", bundleID)
|
||||
}
|
||||
values.BundleID = bundleID
|
||||
|
||||
pipelineID, err := RenderDistributorPipelineID("weatherreporter.{artifact_group}.{bundle_id}", values)
|
||||
pipelineID, err := RenderDistributorPipelineID("weatherreporter.{artifact_group}.{storm_id}.{bundle_id}", values)
|
||||
if err != nil {
|
||||
t.Fatalf("RenderDistributorPipelineID() error = %v", err)
|
||||
}
|
||||
if pipelineID != "weatherreporter.daily.weatherreporter.home.daily" {
|
||||
if pipelineID != "weatherreporter.daily.2026-06-07T1800-2026-06-08T0600.weatherreporter.home.daily.2026-06-07T1800-2026-06-08T0600" {
|
||||
t.Fatalf("pipelineID = %q, want rendered pipeline ID", pipelineID)
|
||||
}
|
||||
|
||||
idempotencyKey, err := RenderDistributorIdempotencyKey("{bundle_id}.{run_id}", values)
|
||||
idempotencyKey, err := RenderDistributorIdempotencyKey("{bundle_id}.{storm_id}.{run_id}", values)
|
||||
if err != nil {
|
||||
t.Fatalf("RenderDistributorIdempotencyKey() error = %v", err)
|
||||
}
|
||||
if idempotencyKey != "weatherreporter.home.daily.20260607T120000Z" {
|
||||
if idempotencyKey != "weatherreporter.home.daily.2026-06-07T1800-2026-06-08T0600.2026-06-07T1800-2026-06-08T0600.20260607T120000Z" {
|
||||
t.Fatalf("idempotencyKey = %q, want rendered run key", idempotencyKey)
|
||||
}
|
||||
|
||||
reportPaths, err := RenderDistributorReportPaths([]string{
|
||||
reportPaths, err := RenderDistributorReportPaths("reports.daily.distributor.path_templates", []string{
|
||||
"{valid_start_date}/{artifact_group}/{valid_start_stamp}-{valid_end_stamp}-{run_id}.md",
|
||||
"storm/{storm_id}/index.md",
|
||||
"{valid_start_date}/{artifact_group}/latest.md",
|
||||
}, values)
|
||||
if err != nil {
|
||||
@@ -1353,6 +1356,7 @@ func TestDistributorTemplateRendering(t *testing.T) {
|
||||
}
|
||||
wantPaths := []string{
|
||||
"2026-06-07/daily/2026-06-07T1800-2026-06-08T0600-20260607T120000Z.md",
|
||||
"storm/2026-06-07T1800-2026-06-08T0600/index.md",
|
||||
"2026-06-07/daily/latest.md",
|
||||
}
|
||||
if strings.Join(reportPaths, "\n") != strings.Join(wantPaths, "\n") {
|
||||
@@ -1360,6 +1364,50 @@ func TestDistributorTemplateRendering(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistributorReportPathRenderingUsesCallerName(t *testing.T) {
|
||||
values := DistributorTemplateValues{
|
||||
BatchOutputName: "report.md",
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
templates []string
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "UnknownVariable",
|
||||
templates: []string{"{unknown}.md"},
|
||||
wantErr: `report.daily.distributor_path_templates[0] contains unknown template variable "unknown"`,
|
||||
},
|
||||
{
|
||||
name: "InvalidPath",
|
||||
templates: []string{"/{batch_output_name}"},
|
||||
wantErr: "report.daily.distributor_path_templates[0] must render a relative path",
|
||||
},
|
||||
{
|
||||
name: "DuplicatePath",
|
||||
templates: []string{"latest.md", "latest.md"},
|
||||
wantErr: `report.daily.distributor_path_templates renders duplicate path "latest.md"`,
|
||||
},
|
||||
{
|
||||
name: "Empty",
|
||||
templates: nil,
|
||||
wantErr: "report.daily.distributor_path_templates must contain at least one entry",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := RenderDistributorReportPaths("report.daily.distributor_path_templates", tt.templates, values)
|
||||
if err == nil {
|
||||
t.Fatal("RenderDistributorReportPaths() error = nil, want error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), tt.wantErr) {
|
||||
t.Fatalf("error = %q, want %q", err.Error(), tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDistributorBatchTemplateRendering(t *testing.T) {
|
||||
values := DistributorBatchTemplateValues{
|
||||
LocationID: "home",
|
||||
@@ -1492,12 +1540,15 @@ func TestDistributorReportPathRenderingRejectsInvalidValues(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := RenderDistributorReportPaths([]string{"{batch_output_name}"}, DistributorTemplateValues{
|
||||
_, err := RenderDistributorReportPaths("report.daily.distributor_path_templates", []string{"{batch_output_name}"}, DistributorTemplateValues{
|
||||
BatchOutputName: tt.batchOutputName,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("RenderDistributorReportPaths() error = nil, want error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "report.daily.distributor_path_templates[0]") {
|
||||
t.Fatalf("error = %q, want caller path name", err.Error())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user