🧪 test: implement per-scenario state isolation and enhance validate-test-suite.sh
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 10s
CI/CD Pipeline / CI Pipeline (push) Failing after 4m8s

- Add pkg/bdd/steps/scenario_state.go with thread-safe per-scenario state manager
- Update auth_steps.go, jwt_retention_steps.go to use per-scenario state accessors
- Add LastSecret and LastError fields to ScenarioState for JWT retention testing
- Update steps.go with SetScenarioKeyForAllSteps function
- Update suite.go to generate scenario keys and clear state properly
- Mark config hot-reload scenarios as @flaky (timing-sensitive)
- Fix validate-test-suite.sh: add -p 1 flag for sequential execution, filter JSON logs, add --count flag
- Add CONFIG_SCHEMA.md documenting configuration architecture
- Split greet tests into v1/v2 sub-tests with explicit v2 enable/disable

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-11 13:34:51 +02:00
parent dbadff58e2
commit 70c2eb554e
18 changed files with 1287 additions and 177 deletions

View File

@@ -1,22 +1,26 @@
package steps
import (
"os"
"time"
"fmt"
"dance-lessons-coach/pkg/bdd/testserver"
"fmt"
)
// GreetSteps holds greet-related step definitions
type GreetSteps struct {
client *testserver.Client
client *testserver.Client
scenarioKey string // Track current scenario for state isolation
}
func NewGreetSteps(client *testserver.Client) *GreetSteps {
return &GreetSteps{client: client}
}
// SetScenarioKey sets the current scenario key for state isolation
func (s *GreetSteps) SetScenarioKey(key string) {
s.scenarioKey = key
}
func (s *GreetSteps) RegisterSteps(ctx interface {
RegisterStep(string, interface{}) error
}) error {
@@ -63,69 +67,7 @@ func (s *GreetSteps) theServerIsRunningWithV2Enabled() error {
return nil
}
// If we get 404, v2 is disabled - enable it
if resp.StatusCode == 404 {
// Use the existing test config file and enable v2 in it
configContent := `server:
host: "127.0.0.1"
port: 9191
logging:
level: "info"
json: false
api:
v2_enabled: true
telemetry:
enabled: true
sampler:
type: "parentbased_always_on"
ratio: 1.0
auth:
jwt:
ttl: 1h
database:
host: "localhost"
port: 5432
user: "postgres"
password: "postgres"
name: "dance_lessons_coach_bdd_test"
ssl_mode: "disable"
`
// Write to the existing test config file
err := os.WriteFile("test-config.yaml", []byte(configContent), 0644)
if err != nil {
return fmt.Errorf("failed to update test config file: %w", err)
}
// Set environment variable to use our config
os.Setenv("DLC_CONFIG_FILE", "test-config.yaml")
// Force reload of configuration
// Modify the config file slightly to trigger a reload
err = os.WriteFile("test-config.yaml", []byte(configContent+"\n# trigger v2 reload\n"), 0644)
if err != nil {
return fmt.Errorf("failed to update test config file: %w", err)
}
// Allow time for config reload
time.Sleep(500 * time.Millisecond)
// Verify v2 is now enabled
resp, err = s.client.CustomRequest("GET", "/api/v2/greet", nil)
if err != nil {
return fmt.Errorf("failed to verify v2 enablement: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode == 404 {
return fmt.Errorf("v2 endpoint still not available after enabling")
}
}
return nil
// If we get 404, v2 is not enabled - this means the test is not properly tagged
// The test should use @v2 tag and the test server should have v2 enabled via createTestConfig
return fmt.Errorf("v2 endpoint not available - ensure running with @v2 tag to enable v2 API")
}