Skip to content

Commit 0d0a40d

Browse files
Adding /api/scenarios endpoint to list active scenarios (jmartin82#123)
* Adding /api/scenarios endpoint to list active scenarios * Add /api/scenarios to ReadME.md Co-authored-by: EslamAK <eslam.abdelkader@deliveryhero.com>
1 parent 1b055b6 commit 0d0a40d

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ Like stubbing this call also uses the same DSL to filter and query requests.
461461

462462
### Scenario
463463

464+
**Title** : Get all active scenarios.<br>
465+
**URL** : /api/scenarios<br>
466+
**Method** : GET<br>
467+
**Response Codes**: Success (200 OK)<br>
468+
464469
**Title** : Clean all scenarios status and pause state.<br>
465470
**URL** : /api/scenarios/reset_all<br>
466471
**Method** : GET<br>

internal/console/dispatcher.go

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (di *Dispatcher) Start() {
8989
e.GET("/api/request/matched", di.requestMatchedHandler)
9090
e.GET("/api/request/unmatched", di.requestUnMatchedHandler)
9191
e.GET("/api/scenarios/reset_all", di.scenariosResetHandler)
92+
e.GET("/api/scenarios", di.scenariosListHandler)
9293
e.PUT("/api/scenarios/set/:scenario/:state", di.scenariosSetHandler)
9394
e.PUT("/api/scenarios/pause", di.scenariosPauseHandler)
9495
e.PUT("/api/scenarios/unpause", di.scenariosUnpauseHandler)
@@ -284,6 +285,11 @@ func (di *Dispatcher) scenariosResetHandler(c echo.Context) error {
284285
return c.JSON(http.StatusOK, ar)
285286
}
286287

288+
func (di *Dispatcher) scenariosListHandler(c echo.Context) error {
289+
scenarios := di.Scenario.List()
290+
return c.String(http.StatusOK, scenarios)
291+
}
292+
287293
func (di *Dispatcher) scenariosSetHandler(c echo.Context) error {
288294
di.Scenario.SetState(c.Param("scenario"), c.Param("state"))
289295
ar := &ActionResponse{

pkg/match/scenario_store.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package match
22

33
import (
4+
"encoding/json"
45
"strings"
56
)
67

@@ -11,6 +12,7 @@ type ScenearioStorer interface {
1112
ResetAll()
1213
SetPaused(newstate bool)
1314
GetPaused() bool
15+
List() string
1416
}
1517

1618
func NewInMemoryScenarioStore() *InMemoryScenarioStore {
@@ -23,6 +25,11 @@ type InMemoryScenarioStore struct {
2325
paused bool
2426
}
2527

28+
func (sm *InMemoryScenarioStore) List() string {
29+
json, _ := json.MarshalIndent(sm.status, "", " ")
30+
return string(json)
31+
}
32+
2633
func (sm *InMemoryScenarioStore) Reset(name string) bool {
2734
if _, f := sm.status[strings.ToLower(name)]; f {
2835
sm.status[strings.ToLower(name)] = "not_started"

0 commit comments

Comments
 (0)