@@ -5,42 +5,32 @@ import (
55 "encoding/json"
66 "fmt"
77 "net/http"
8- "time"
98)
109
11- func addToCart (productID , variantID , sessionID string ) {
10+ func addToCart () {
1211 body := map [string ]any {
13- "product_id" : productID ,
14- "variant_id" : variantID ,
12+ "product_id" : e2eProductID ,
13+ "variant_id" : e2eVariantID ,
1514 "quantity" : 1 ,
1615 }
1716
1817 b , _ := json .Marshal (body )
1918
20- var lastErr error
21-
22- for i := 1 ; i <= 10 ; i ++ {
23- req , _ := http .NewRequest (
24- "POST" ,
25- cartBase + "/v1/cart/add" ,
26- bytes .NewReader (b ),
27- )
28- req .Header .Set ("Content-Type" , "application/json" )
29- req .Header .Set ("X-SESSION-ID" , sessionID )
30-
31- resp , err := http .DefaultClient .Do (req )
32- if err != nil {
33- lastErr = err
34- } else {
35- resp .Body .Close ()
36- if resp .StatusCode == http .StatusOK || resp .StatusCode == http .StatusCreated {
37- return // ✅ success
38- }
39- lastErr = fmt .Errorf ("status %d" , resp .StatusCode )
40- }
41-
42- time .Sleep (2 * time .Second )
19+ req , _ := http .NewRequest (
20+ http .MethodPost ,
21+ cartBase + "/v1/cart/add" ,
22+ bytes .NewReader (b ),
23+ )
24+ req .Header .Set ("Content-Type" , "application/json" )
25+ req .Header .Set ("X-SESSION-ID" , e2eSessionID )
26+
27+ resp , err := http .DefaultClient .Do (req )
28+ if err != nil {
29+ panic (err )
4330 }
31+ defer resp .Body .Close ()
4432
45- panic (fmt .Errorf ("addToCart failed after retries: %v" , lastErr ))
33+ if resp .StatusCode != http .StatusOK && resp .StatusCode != http .StatusCreated {
34+ panic (fmt .Errorf ("addToCart failed: %d" , resp .StatusCode ))
35+ }
4636}
0 commit comments