Share command output projections
This commit is contained in:
42
internal/app/manifest_test.go
Normal file
42
internal/app/manifest_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestManifestCreateJSONPreservesCreatedOffsetAndFileMetadata(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(root, "report.md"), []byte("# Report\n"), 0o600); err != nil {
|
||||
t.Fatalf("write report: %v", err)
|
||||
}
|
||||
var stdout bytes.Buffer
|
||||
|
||||
err := ManifestCreate(context.Background(), ManifestCreateOptions{
|
||||
Root: root,
|
||||
ID: "reports.offset",
|
||||
Created: "2026-06-01T06:30:00-05:00",
|
||||
Files: []string{"report.md"},
|
||||
Stdout: &stdout,
|
||||
OutputFormat: OutputFormatJSON,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("ManifestCreate() error = %v", err)
|
||||
}
|
||||
result := decodeAppResult(t, stdout.String())
|
||||
if result["id"] != "reports.offset" || result["created"] != "2026-06-01T06:30:00-05:00" || result["file_count"] != float64(1) {
|
||||
t.Fatalf("result = %#v, want manifest metadata", result)
|
||||
}
|
||||
files, ok := result["files"].([]any)
|
||||
if !ok || len(files) != 1 {
|
||||
t.Fatalf("files = %#v, want one file", result["files"])
|
||||
}
|
||||
file, ok := files[0].(map[string]any)
|
||||
if !ok || file["path"] != "report.md" || file["sha256"] == "" || file["size"] != float64(9) {
|
||||
t.Fatalf("file = %#v, want projected file metadata", file)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user