🧪 test: fix BDD step registration and update CI/CD workflow
- Fix step pattern escaping in pkg/bdd/steps/steps.go:80 - Update CI/CD workflow to use run-bdd-tests.sh script - Enhance run-bdd-tests.sh for both local and CI environments - Add strict validation for undefined/pending/skipped steps - Update BDD testing documentation with pattern requirements The CI/CD pipeline now properly validates BDD tests and fails on any undefined, pending, or skipped steps. All 22 BDD scenarios are passing with correct step pattern registration.
This commit is contained in:
@@ -15,7 +15,12 @@ Feature: Greet Service
|
||||
Then the response should be "..." # ??? UNDEFINED STEP
|
||||
```
|
||||
|
||||
**Root Cause:** Step patterns don't match Godog's exact expectations.
|
||||
**Root Cause:** Step patterns don't match Godog's exact expectations. Godog is very particular about regex escaping.
|
||||
|
||||
**Common Pattern Issues:**
|
||||
- `\"` vs `\\"` (single vs double escaping)
|
||||
- Exact quote handling in JSON patterns
|
||||
- Parameter capture group syntax
|
||||
|
||||
**Debugging Steps:**
|
||||
|
||||
@@ -28,25 +33,30 @@ Feature: Greet Service
|
||||
```
|
||||
You can implement step definitions for the undefined steps with these snippets:
|
||||
|
||||
func theServerIsRunning() error {
|
||||
func theResponseShouldBe(arg1, arg2 string) error {
|
||||
return godog.ErrPending
|
||||
}
|
||||
|
||||
func iRequestTheDefaultGreeting() error {
|
||||
return godog.ErrPending
|
||||
func InitializeScenario(ctx *godog.ScenarioContext) {
|
||||
ctx.Step(`^the response should be "{\\"([^"]*)\\":\\"([^"]*)\\"}"$`, theResponseShouldBe)
|
||||
}
|
||||
```
|
||||
|
||||
3. **Compare with your implementation:**
|
||||
```go
|
||||
// ❌ Wrong pattern
|
||||
ctx.Step(`^the server is running$`, sc.theServerIsRunning)
|
||||
// ❌ Wrong pattern (single escaping)
|
||||
ctx.Step(`^the response should be "{\"([^"]*)\":\"([^"]*)\"}"$`, sc.commonSteps.theResponseShouldBe)
|
||||
|
||||
// ✅ Correct pattern (matches Godog's suggestion)
|
||||
ctx.Step(`^the server is running$`, sc.theServerIsRunning)
|
||||
// ✅ Correct pattern (double escaping - matches Godog's suggestion)
|
||||
ctx.Step(`^the response should be "{\\"([^"]*)\\":\\"([^"]*)\\"}"$`, sc.commonSteps.theResponseShouldBe)
|
||||
```
|
||||
|
||||
**Solution:** Use Godog's EXACT regex patterns.
|
||||
**Key Insight:** Godog expects `\\"` (four backslashes + quote) for escaped quotes in JSON patterns, not `\"` (two backslashes + quote).
|
||||
|
||||
**Solution:** Use Godog's EXACT regex patterns, paying special attention to:
|
||||
- JSON escaping: `\\"` not `\"`
|
||||
- Parameter names: Use `arg1, arg2` as suggested
|
||||
- Capture groups: Match Godog's exact regex syntax
|
||||
|
||||
### 2. JSON Comparison Failures
|
||||
|
||||
|
||||
Reference in New Issue
Block a user