ai cooking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

dont panic if we get a nil (#385)

* Limit avoidance to recently cooked recipes and show save feedback

* parallel fetch of old

* save regenerated ones

* simplify

* wait group update and move last recipes

* keep mail matching

* go fumpt

* catch nils

authored by

Paul Miller and committed by
GitHub
d081adc3 0d3bcfe5

+35
+4
cmd/careme/middleware.go
··· 89 89 } 90 90 91 91 func newAppInsightsTracker(next http.Handler, tracker requestTracker) http.Handler { 92 + if tracker == nil { 93 + return next 94 + } 95 + 92 96 return &appInsightsTracker{ 93 97 Handler: next, 94 98 tracker: tracker,
+31
cmd/careme/middleware_test.go
··· 277 277 } 278 278 } 279 279 280 + func TestWithMiddlewareProvidesIDsWithoutTracker(t *testing.T) { 281 + var operationID string 282 + var sessionID string 283 + handler := AppMiddleWare(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 284 + operationID, _ = logsetup.OperationIDFromContext(r.Context()) 285 + sessionID, _ = logsetup.SessionIDFromContext(r.Context()) 286 + w.WriteHeader(http.StatusNoContent) 287 + }), nil) 288 + 289 + req := httptest.NewRequest(http.MethodGet, "http://careme.cooking/about", nil) 290 + rec := httptest.NewRecorder() 291 + handler.ServeHTTP(rec, req) 292 + 293 + if rec.Code != http.StatusNoContent { 294 + t.Fatalf("expected status 204, got %d", rec.Code) 295 + } 296 + if operationID == "" { 297 + t.Fatal("expected operation id in context") 298 + } 299 + if sessionID == "" { 300 + t.Fatal("expected session id in context") 301 + } 302 + if rec.Header().Get("X-Operation-ID") != operationID { 303 + t.Fatalf("expected X-Operation-ID %q, got %q", operationID, rec.Header().Get("X-Operation-ID")) 304 + } 305 + cookie := findCookie(t, rec.Result().Cookies(), sessionCookieName) 306 + if cookie.Value != sessionID { 307 + t.Fatalf("expected session cookie %q, got %q", sessionID, cookie.Value) 308 + } 309 + } 310 + 280 311 func findCookie(t *testing.T, cookies []*http.Cookie, name string) *http.Cookie { 281 312 t.Helper() 282 313 for _, cookie := range cookies {