/
mock.go
80 lines (64 loc) · 1.49 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package snapshot
import (
"time"
"github.com/lyft/goruntime/snapshot/entry"
)
// Mock provides a Snapshot implementation for testing
type Mock struct {
*Snapshot
}
// NewMock initializes a new Mock
func NewMock() (s *Mock) {
s = &Mock{
Snapshot: New(),
}
return
}
// SetEnabled overrides the entry for `key` to be enabled
func (m *Mock) SetEnabled(key string) *Mock {
m.Snapshot.entries[key] = &entry.Entry{
StringValue: key,
Uint64Value: 0,
Uint64Valid: true,
Modified: time.Now(),
}
return m
}
// SetDisabled overrides the entry for `key` to be disabled
func (m *Mock) SetDisabled(key string) *Mock {
m.Snapshot.entries[key] = &entry.Entry{
StringValue: key,
Uint64Value: 0,
Uint64Valid: false,
Modified: time.Now(),
}
return m
}
// Set set the entry for `key` to `val`
func (m *Mock) Set(key string, val string) *Mock {
m.Snapshot.entries[key] = &entry.Entry{
StringValue: val,
Uint64Value: 0,
Uint64Valid: false,
Modified: time.Now(),
}
return m
}
// SetUInt64 set the entry for `key` to `val` as a uint64
func (m *Mock) SetUInt64(key string, val uint64) *Mock {
m.Snapshot.entries[key] = &entry.Entry{
StringValue: "",
Uint64Value: val,
Uint64Valid: true,
Modified: time.Now(),
}
return m
}
// FeatureEnabled overrides the internal `Snapshot`s `FeatureEnabled`
func (m *Mock) FeatureEnabled(key string, defaultValue uint64) bool {
if e, ok := m.Snapshot.entries[key]; ok {
return e.Uint64Valid
}
return false
}
var _ IFace = &Mock{}