diff --git a/cmd/checkout/cart-client.go b/cmd/checkout/cart-client.go index eb999aa..d263b64 100644 --- a/cmd/checkout/cart-client.go +++ b/cmd/checkout/cart-client.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "log" "net/http" "time" @@ -57,6 +58,7 @@ func (s *CartClient) getCartGrain(ctx context.Context, cartId cart.CartId) (*car } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { + log.Printf("request to %s failed with status %s", url, resp.Status) return nil, fmt.Errorf("failed to get cart: %s", resp.Status) } var grain cart.CartGrain diff --git a/cmd/checkout/cart-client_test.go b/cmd/checkout/cart-client_test.go new file mode 100644 index 0000000..aa7d95e --- /dev/null +++ b/cmd/checkout/cart-client_test.go @@ -0,0 +1,31 @@ +package main + +import ( + "context" + "testing" + + "git.k6n.net/go-cart-actor/pkg/cart" +) + +// TestGetCartGrain_RealService tests against the actual service at https://cart.k6n.net/ +// This test is skipped by default and can be run with: go test -run TestGetCartGrain_RealService +func TestGetCartGrain_RealService(t *testing.T) { + t.Skip("Skipping integration test against real service") + + client := NewCartClient("https://cart.k6n.net") + + // You would need a real cart ID that exists in the system + // For example: cartId := cart.NewCartId(123, 456) + cartId := cart.MustParseCartId("JkfG6bRNLMy") + + grain, err := client.getCartGrain(context.Background(), cartId) + if err != nil { + t.Fatalf("Failed to get cart grain: %v", err) + } + + if grain == nil { + t.Fatal("Expected grain to be non-nil") + } + + t.Logf("Successfully retrieved cart grain: %+v", grain) +} diff --git a/cmd/checkout/pool-server.go b/cmd/checkout/pool-server.go index 8135f2a..a87f805 100644 --- a/cmd/checkout/pool-server.go +++ b/cmd/checkout/pool-server.go @@ -197,7 +197,7 @@ func (s *CheckoutPoolServer) StartCheckoutHandler(w http.ResponseWriter, r *http cartGrain, err := s.cartClient.getCartGrain(r.Context(), cartId) if err != nil { logger.Error("failed to fetch cart", "error", err, "cartId", cartId) - http.Error(w, "failed to fetch cart", http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) return }