-
Notifications
You must be signed in to change notification settings - Fork 80
/
scenario_store.go
61 lines (49 loc) · 1.17 KB
/
scenario_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package match
import (
"strings"
)
type ScenearioStorer interface {
SetState(name, status string)
GetState(name string) string
Reset(name string) bool
ResetAll()
SetPaused(newstate bool)
GetPaused() bool
}
func NewInMemoryScenarioStore() *InMemoryScenarioStore {
status := make(map[string]string)
return &InMemoryScenarioStore{status: status}
}
type InMemoryScenarioStore struct {
status map[string]string
paused bool
}
func (sm *InMemoryScenarioStore) Reset(name string) bool {
if _, f := sm.status[strings.ToLower(name)]; f {
sm.status[strings.ToLower(name)] = "not_started"
return true
}
return false
}
func (sm *InMemoryScenarioStore) ResetAll() {
sm.status = make(map[string]string)
sm.paused = false
}
func (sm *InMemoryScenarioStore) SetState(name, status string) {
if sm.paused {
return
}
sm.status[strings.ToLower(name)] = strings.ToLower(status)
}
func (sm *InMemoryScenarioStore) GetState(name string) string {
if v, f := sm.status[strings.ToLower(name)]; f {
return v
}
return "not_started"
}
func (sm *InMemoryScenarioStore) GetPaused() bool {
return sm.paused
}
func (sm *InMemoryScenarioStore) SetPaused(newstate bool) {
sm.paused = newstate
}