From 49c44b9df84a0c419f0a26475e6885d3681bf2d0 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Sun, 27 Apr 2025 12:59:33 -0600 Subject: [PATCH] lil further cron one --- src/cmd/cron/main.go | 7 +++++-- src/cmd/cron/main_test.go | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cmd/cron/main.go b/src/cmd/cron/main.go index d8ca119..a0de98e 100644 --- a/src/cmd/cron/main.go +++ b/src/cmd/cron/main.go @@ -39,9 +39,12 @@ func one(ctx context.Context, feed feeds.Feed) error { return nil } - return fmt.Errorf("should GET %s", feed.Version.URL) + items, err := feed.Fetch(ctx) + if err != nil { + return err + } - return fmt.Errorf("should parse %s", feed.Version.URL) + return fmt.Errorf("what do with %+v", items) return feed.Executed(ctx) } diff --git a/src/cmd/cron/main_test.go b/src/cmd/cron/main_test.go index 8f26b75..6f2c16b 100644 --- a/src/cmd/cron/main_test.go +++ b/src/cmd/cron/main_test.go @@ -18,20 +18,27 @@ func TestOne(t *testing.T) { ctx, can := context.WithTimeout(context.Background(), 5*time.Second) defer can() - for name, aCtx := range map[string]func() context.Context{ - "empty": func() context.Context { + for name, aCtx := range map[string]func(t *testing.T) context.Context{ + "empty": func(t *testing.T) context.Context { return db.Test(t, ctx) }, - "feeds": func() context.Context { + "feeds": func(t *testing.T) context.Context { gets := []string{} s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { gets = append(gets, r.URL.String()) t.Logf("%s", gets[len(gets)-1]) + + switch r.URL.Query().Get("id") { + case "0": + case "1": + default: + http.NotFound(w, r) + } })) t.Cleanup(s.Close) t.Cleanup(func() { slices.Sort(gets) - if len(gets) != 2+2+2 { // id=1+id=2 for each of 2 unrecycled ctx, id=1+id=2 for one across shared ctx + if len(gets) != 2+2+2 { // id=0+id=1 for each of 2 unrecycled ctx, id=0+id=1 for one across shared ctx t.Errorf("didn't call urls exactly twice: %+v", gets) } }) @@ -39,7 +46,7 @@ func TestOne(t *testing.T) { ctx := db.Test(t, ctx) for i := 0; i < 2; i++ { - if _, err := feeds.Insert(ctx, fmt.Sprintf("%s?idx=%d", s.URL, i), "* * * * *", "matches"); err != nil { + if _, err := feeds.Insert(ctx, fmt.Sprintf("%s?idx=%d", s.URL, i), "* * * * *", "matches", "tag"); err != nil { t.Fatal(err) } } @@ -50,7 +57,7 @@ func TestOne(t *testing.T) { aCtx := aCtx t.Run(name, func(t *testing.T) { t.Run("same ctx", func(t *testing.T) { - ctx := aCtx() + ctx := aCtx(t) for i := 0; i < 2; i++ { t.Run(strconv.Itoa(i), func(t *testing.T) { if err := cron.One(ctx); err != nil && ctx.Err() == nil { @@ -63,7 +70,7 @@ func TestOne(t *testing.T) { t.Run("new ctx", func(t *testing.T) { for i := 0; i < 2; i++ { t.Run(strconv.Itoa(i), func(t *testing.T) { - ctx := aCtx() + ctx := aCtx(t) if err := cron.One(ctx); err != nil && ctx.Err() == nil { t.Fatalf("failed %d: %v", i, err) }