Add local source publication

This commit is contained in:
2026-05-31 02:21:36 +00:00
parent aeee91940d
commit e296361042
17 changed files with 1019 additions and 84 deletions

View File

@@ -41,28 +41,6 @@ func TestExecuteVersion(t *testing.T) {
}
}
func TestRunWithoutDryRunFailsClearly(t *testing.T) {
tests := []string{"run"}
for _, command := range tests {
t.Run(command, func(t *testing.T) {
var stdout, stderr bytes.Buffer
code := Execute(context.Background(), []string{command}, &stdout, &stderr)
if code != exitError {
t.Fatalf("exit code = %d, want %d", code, exitError)
}
if stdout.Len() != 0 {
t.Fatalf("stdout = %q, want empty", stdout.String())
}
if !strings.Contains(stderr.String(), "not implemented") {
t.Fatalf("stderr = %q, want not implemented error", stderr.String())
}
})
}
}
func TestExecuteValidate(t *testing.T) {
var stdout, stderr bytes.Buffer
@@ -90,17 +68,19 @@ func TestExecuteInspect(t *testing.T) {
}
func TestExecuteRunDryRun(t *testing.T) {
sourceRoot := t.TempDir()
writeCLIBundle(t, sourceRoot)
configPath := filepath.Join(t.TempDir(), "config.yml")
err := os.WriteFile(configPath, []byte(`
pipelines:
- id: reports
source:
backend: local
path: /source
path: `+sourceRoot+`
destinations:
- id: archive
backend: local
path: /archive
path: `+t.TempDir()+`
`), 0o600)
if err != nil {
t.Fatalf("write config: %v", err)
@@ -113,7 +93,7 @@ pipelines:
if code != exitOK {
t.Fatalf("exit code = %d, want %d; stderr = %q", code, exitOK, stderr.String())
}
if !strings.Contains(stdout.String(), "Configured pipelines: 1") {
if !strings.Contains(stdout.String(), "action=publish_new") {
t.Fatalf("stdout = %q, want config summary", stdout.String())
}
if stderr.Len() != 0 {
@@ -121,6 +101,38 @@ pipelines:
}
}
func TestExecuteRunPublishes(t *testing.T) {
sourceRoot := t.TempDir()
destinationRoot := t.TempDir()
writeCLIBundle(t, sourceRoot)
configPath := filepath.Join(t.TempDir(), "config.yml")
err := os.WriteFile(configPath, []byte(`
pipelines:
- id: reports
source:
backend: local
path: `+sourceRoot+`
destinations:
- id: archive
backend: local
path: `+destinationRoot+`
`), 0o600)
if err != nil {
t.Fatalf("write config: %v", err)
}
var stdout, stderr bytes.Buffer
code := Execute(context.Background(), []string{"run", "--config", configPath}, &stdout, &stderr)
if code != exitOK {
t.Fatalf("exit code = %d, want %d; stderr = %q", code, exitOK, stderr.String())
}
if _, err := os.Stat(filepath.Join(destinationRoot, ".distributor.json")); err != nil {
t.Fatalf("state stat error = %v", err)
}
}
func TestUnknownCommandIsUsageError(t *testing.T) {
var stdout, stderr bytes.Buffer
@@ -133,3 +145,37 @@ func TestUnknownCommandIsUsageError(t *testing.T) {
t.Fatalf("stderr = %q, want unknown command error", stderr.String())
}
}
func writeCLIBundle(t *testing.T, root string) {
t.Helper()
for _, file := range []struct {
path string
data string
}{
{"manifest.json", `{
"schema_version": 1,
"id": "weather.daily.brentwood.2026-05-30",
"digest": "sha256:099b205780d2b050024868399961b05731729a548d5d6329c7b06a6740dd75fe",
"created": "2026-05-30T11:10:00Z",
"files": [
{
"path": "report.md",
"sha256": "sha256:3640fd37140ee4d2e0e93e78834f232ea67a50e7bc6279203690cc7de1975fa6",
"size": 16
},
{
"path": "summary.txt",
"sha256": "sha256:3cbb36aca330b3bd113955dfbada0adb7a5f95ad9f678bd61f175406c6a37e95",
"size": 8
}
]
}
`},
{"report.md", "# Report\nSunny.\n"},
{"summary.txt", "Summary\n"},
} {
if err := os.WriteFile(filepath.Join(root, file.path), []byte(file.data), 0o600); err != nil {
t.Fatalf("write bundle file: %v", err)
}
}
}