94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/distributor/internal/testutil"
|
|
)
|
|
|
|
func TestInspectPrintsBundleSummary(t *testing.T) {
|
|
var stdout bytes.Buffer
|
|
err := Inspect(context.Background(), InspectOptions{
|
|
Path: filepath.Join("..", "bundle", "testdata", "valid_bundle"),
|
|
Stdout: &stdout,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("Inspect() error = %v", err)
|
|
}
|
|
output := stdout.String()
|
|
for _, want := range []string{
|
|
"Bundles: 1",
|
|
"path=.",
|
|
"id=weather.daily.brentwood.2026-05-30",
|
|
"created=2026-05-30T11:10:00Z",
|
|
"report.md size=16",
|
|
"summary.txt size=8",
|
|
} {
|
|
if !strings.Contains(output, want) {
|
|
t.Fatalf("Inspect() output = %q, want substring %q", output, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestInspectConfiguredLocalSource(t *testing.T) {
|
|
sourceRoot := t.TempDir()
|
|
destinationRoot := t.TempDir()
|
|
testutil.WriteSourceBundle(t, sourceRoot, "daily", testutil.BundleOptions{ID: "reports.daily"})
|
|
var stdout bytes.Buffer
|
|
|
|
err := Inspect(context.Background(), InspectOptions{
|
|
ConfigPath: testutil.WriteMinimalLocalConfig(t, sourceRoot, destinationRoot),
|
|
PipelineID: "reports",
|
|
Stdout: &stdout,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Fatalf("Inspect() configured source error = %v", err)
|
|
}
|
|
output := stdout.String()
|
|
for _, want := range []string{
|
|
"Pipeline: reports",
|
|
"Source: local",
|
|
"Bundles: 1",
|
|
"path=daily",
|
|
"id=reports.daily",
|
|
} {
|
|
if !strings.Contains(output, want) {
|
|
t.Fatalf("Inspect() output = %q, want substring %q", output, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestInspectConfiguredSourceJSON(t *testing.T) {
|
|
sourceRoot := t.TempDir()
|
|
destinationRoot := t.TempDir()
|
|
testutil.WriteSourceBundle(t, sourceRoot, "", testutil.BundleOptions{ID: "reports.json"})
|
|
var stdout bytes.Buffer
|
|
|
|
err := Inspect(context.Background(), InspectOptions{
|
|
ConfigPath: testutil.WriteMinimalLocalConfig(t, sourceRoot, destinationRoot),
|
|
PipelineID: "reports",
|
|
Stdout: &stdout,
|
|
OutputFormat: OutputFormatJSON,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Fatalf("Inspect() configured JSON error = %v", err)
|
|
}
|
|
result := decodeAppResult(t, stdout.String())
|
|
if result["pipeline_id"] != "reports" || result["source_backend"] != "local" || result["bundle_count"] != float64(1) {
|
|
t.Fatalf("result = %#v, want configured inspect metadata", result)
|
|
}
|
|
}
|
|
|
|
func TestInspectRequiresPath(t *testing.T) {
|
|
err := Inspect(context.Background(), InspectOptions{})
|
|
if err == nil || !strings.Contains(err.Error(), "requires a path") {
|
|
t.Fatalf("Inspect() error = %v, want required path", err)
|
|
}
|
|
}
|