-
Notifications
You must be signed in to change notification settings - Fork 20
/
mock.go
49 lines (42 loc) · 910 Bytes
/
mock.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
package contactql
import (
"strings"
"github.com/nyaruka/goflow/assets"
)
type mockResolver struct {
fields []assets.Field
flows []assets.Flow
groups []assets.Group
}
// NewMockResolver creates a new mock resolver for fields and groups
func NewMockResolver(fields []assets.Field, flows []assets.Flow, groups []assets.Group) Resolver {
return &mockResolver{
fields: fields,
flows: flows,
groups: groups,
}
}
func (r *mockResolver) ResolveField(key string) assets.Field {
for _, f := range r.fields {
if f.Key() == key {
return f
}
}
return nil
}
func (r *mockResolver) ResolveGroup(name string) assets.Group {
for _, g := range r.groups {
if strings.EqualFold(g.Name(), name) {
return g
}
}
return nil
}
func (r *mockResolver) ResolveFlow(name string) assets.Flow {
for _, f := range r.flows {
if strings.EqualFold(f.Name(), name) {
return f
}
}
return nil
}