summaryrefslogtreecommitdiff
path: root/internal/generator/atom
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-27 09:18:52 +0300
committerPaul Buetow <paul@buetow.org>2026-04-27 09:18:52 +0300
commit47d69cb998a447eea662ad1075f9d002dd875443 (patch)
tree1fa586fc4f7e5fae2ce9badfa05679c0fee9dcb3 /internal/generator/atom
parent626ff3ae7d43cfc2ec3f2554d340b40f4a5c0586 (diff)
Add context.Context to I/O-bound public APIs (generator.Run, processor.Run, atom.Generate, syncOutput)
- generator.Run(ctx, cfg) – ctx passed through to atom.Generate - processor.Run(ctx, cfg) – signature updated for cancellation propagation - atom.Generate(ctx, posts, cfg) – accepts ctx for future cancellation - syncOutput(ctx, cfg) – rsync subprocesses now use exec.CommandContext - Updated all call sites in tests, cmd/snonux/main.go, and integration tests - All call sites pass context.Background() / context.TODO() All tests pass: go test ./...
Diffstat (limited to 'internal/generator/atom')
-rw-r--r--internal/generator/atom/atom.go5
-rw-r--r--internal/generator/atom/atom_test.go9
2 files changed, 10 insertions, 4 deletions
diff --git a/internal/generator/atom/atom.go b/internal/generator/atom/atom.go
index 75f4876..03475d8 100644
--- a/internal/generator/atom/atom.go
+++ b/internal/generator/atom/atom.go
@@ -5,6 +5,7 @@
package atom
import (
+ "context"
"encoding/xml"
"fmt"
"os"
@@ -48,7 +49,9 @@ type content struct {
// Generate writes atom.xml to cfg.OutputDir containing the most recent
// min(len(posts), config.PostsPerPage) entries. Posts must already be sorted
// newest-first (as produced by generator.Run).
-func Generate(posts []*post.Post, cfg *config.Config) error {
+// The context is currently accepted for API consistency and future
+// cancellation propagation; no blocking I/O operations currently observe it.
+func Generate(ctx context.Context, posts []*post.Post, cfg *config.Config) error {
limit := config.PostsPerPage
if len(posts) < limit {
limit = len(posts)
diff --git a/internal/generator/atom/atom_test.go b/internal/generator/atom/atom_test.go
index 2bfdfb7..04a33fb 100644
--- a/internal/generator/atom/atom_test.go
+++ b/internal/generator/atom/atom_test.go
@@ -1,6 +1,7 @@
package atom
import (
+ "context"
"encoding/xml"
"os"
"path/filepath"
@@ -12,6 +13,8 @@ import (
"codeberg.org/snonux/snonux/internal/post"
)
+var ctx = context.Background() //nolint:gochecknoglobals // test-only top-level helper used by every test in the file
+
func TestGenerate_writesAtomXML(t *testing.T) {
t.Parallel()
@@ -28,7 +31,7 @@ func TestGenerate_writesAtomXML(t *testing.T) {
},
}
- if err := Generate(posts, cfg); err != nil {
+ if err := Generate(ctx, posts, cfg); err != nil {
t.Fatalf("Generate: %v", err)
}
@@ -54,7 +57,7 @@ func TestGenerate_emptyPosts(t *testing.T) {
dir := t.TempDir()
cfg := &config.Config{OutputDir: dir, BaseURL: "https://x.test"}
- if err := Generate(nil, cfg); err != nil {
+ if err := Generate(ctx, nil, cfg); err != nil {
t.Fatalf("Generate: %v", err)
}
@@ -90,7 +93,7 @@ func TestGenerate_limitPostsPerPage(t *testing.T) {
})
}
- if err := Generate(posts, cfg); err != nil {
+ if err := Generate(ctx, posts, cfg); err != nil {
t.Fatalf("Generate: %v", err)
}