Skip to content

Commit 4175739

Browse files
committed
ci.yml typo fixed
1 parent 98b23c7 commit 4175739

File tree

7 files changed

+58
-56
lines changed

7 files changed

+58
-56
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ jobs:
6262
exit 1
6363
6464
- name: Run Full E2E Checkout Flow
65+
env:
66+
E2E_PRODUCT_ID: 92390a37-43f7-404c-979d-1614afc7309b
67+
E2E_VARIANT_ID: b1db6569-6ad7-48d3-8c88-5a29bb05445d
68+
E2E_SESSION_ID: e2e-ci-session
69+
INTERNAL_SERVICE_KEY: sabhyatam-internal-2025
6570
run: |
6671
go run ./tools/e2e_checkout
6772

tools/e2e_checkout/cart.go

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tools/e2e_checkout/config.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
package main
22

3-
const (
4-
productBase = "http://localhost:8080"
5-
cartBase = "http://localhost:8081"
6-
ordersBase = "http://localhost:8082"
7-
paymentsBase = "http://localhost:8083"
3+
import "os"
84

9-
internalKey = "sabhyatam-internal-2025"
5+
var (
6+
productBase = getenv("PRODUCT_BASE", "http://localhost:8080")
7+
cartBase = getenv("CART_BASE", "http://localhost:8081")
8+
ordersBase = getenv("ORDERS_BASE", "http://localhost:8082")
9+
paymentsBase = getenv("PAYMENTS_BASE", "http://localhost:8083")
1010

11-
// change only this
12-
testProductID = "99d56444-6e73-4ce1-aee1-e718331b0e1f"
13-
testVariantID = "1d7d7b72-92f6-4451-af54-844454979b02"
11+
internalKey = getenv("INTERNAL_SERVICE_KEY", "sabhyatam-internal-2025")
1412

15-
sessionID = "e2e_guest_001"
13+
e2eProductID = mustEnv("E2E_PRODUCT_ID")
14+
e2eVariantID = mustEnv("E2E_VARIANT_ID")
15+
e2eSessionID = getenv("E2E_SESSION_ID", "e2e-session-001")
1616
)
17+
18+
func getenv(k, d string) string {
19+
if v := os.Getenv(k); v != "" {
20+
return v
21+
}
22+
return d
23+
}
24+
25+
func mustEnv(k string) string {
26+
v := os.Getenv(k)
27+
if v == "" {
28+
panic("missing required env: " + k)
29+
}
30+
return v
31+
}

tools/e2e_checkout/flow_full.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import "log"
55
func runFullFlow() {
66
log.Println("🚀 Starting E2E Checkout Flow")
77

8-
addToCart(testProductID, testVariantID, sessionID)
8+
addToCart()
99

10-
orderID := prepareOrder(sessionID)
10+
orderID := prepareOrder()
1111
log.Println("🧾 Order ID:", orderID)
1212

1313
initiatePayment(orderID)

tools/e2e_checkout/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package main
22

3-
import "log"
4-
53
func main() {
6-
log.Println("🚀 Starting E2E Checkout Flow")
74
runFullFlow()
85
}

tools/e2e_checkout/order.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
package main
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"net/http"
78
)
89

9-
func prepareOrder(sessionID string) string {
10-
req, err := http.NewRequest(
11-
"POST",
10+
func prepareOrder() string {
11+
req, _ := http.NewRequest(
12+
http.MethodPost,
1213
ordersBase+"/v1/orders/prepare",
13-
nil,
14+
bytes.NewReader([]byte(`{}`)),
1415
)
15-
if err != nil {
16-
panic(err)
17-
}
18-
1916
req.Header.Set("Content-Type", "application/json")
20-
req.Header.Set("X-SESSION-ID", sessionID)
17+
req.Header.Set("X-SESSION-ID", e2eSessionID)
2118

2219
resp, err := http.DefaultClient.Do(req)
2320
if err != nil {
@@ -32,9 +29,7 @@ func prepareOrder(sessionID string) string {
3229
var out struct {
3330
OrderID string `json:"order_id"`
3431
}
35-
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
36-
panic(err)
37-
}
32+
json.NewDecoder(resp.Body).Decode(&out)
3833

3934
return out.OrderID
4035
}

tools/e2e_checkout/payment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func initiatePayment(orderID string) {
2020
}
2121
defer resp.Body.Close()
2222

23-
if resp.StatusCode != http.StatusOK {
23+
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
2424
panic(fmt.Errorf("initiatePayment failed: %d", resp.StatusCode))
2525
}
2626
}

0 commit comments

Comments
 (0)