-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscenario.go
56 lines (44 loc) · 1.06 KB
/
scenario.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
package mocha
const (
_scenarioStateStarted = "STARTED"
)
type scenario struct {
Name string
State string
}
func newScenario(name string) scenario {
return scenario{Name: name, State: _scenarioStateStarted}
}
// HasStarted returns true when Scenario state is equal to "STARTED"
func (s scenario) HasStarted() bool {
return s.State == _scenarioStateStarted
}
type (
scenarioStore interface {
FetchByName(name string) (scenario, bool)
CreateNewIfNeeded(name string) scenario
Save(s scenario)
}
internalScenarioStore struct {
data map[string]scenario
}
)
func newScenarioStore() scenarioStore {
return &internalScenarioStore{data: make(map[string]scenario)}
}
func (store *internalScenarioStore) FetchByName(name string) (scenario, bool) {
s, ok := store.data[name]
return s, ok
}
func (store *internalScenarioStore) CreateNewIfNeeded(name string) scenario {
s, ok := store.FetchByName(name)
if !ok {
sc := newScenario(name)
store.Save(sc)
return sc
}
return s
}
func (store *internalScenarioStore) Save(s scenario) {
store.data[s.Name] = s
}