Skip to content

Commit a99424e

Browse files
committed
Add full parity for persistence of sections to keys.
1 parent 05e0f3a commit a99424e

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ go 1.22.0
44

55
require (
66
github.com/shimmeringbee/zcl v0.0.0-20240509210644-817a66d91348
7+
github.com/shimmeringbee/zigbee v0.0.0-20201027194100-4e53cafc0f7a
78
github.com/stretchr/testify v1.9.0
89
)
910

1011
require (
1112
github.com/davecgh/go-spew v1.1.1 // indirect
1213
github.com/pmezard/go-difflib v1.0.0 // indirect
1314
github.com/shimmeringbee/bytecodec v0.0.0-20201107142444-94bb5c0baaee // indirect
14-
github.com/shimmeringbee/zigbee v0.0.0-20201027194100-4e53cafc0f7a // indirect
1515
github.com/stretchr/objx v0.5.2 // indirect
1616
gopkg.in/yaml.v3 v3.0.1 // indirect
1717
)

impl/memory/memory.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ type memory struct {
1616
sections map[string]persistence.Section
1717
}
1818

19+
func (m *memory) SectionExists(key string) bool {
20+
m.m.RLock()
21+
defer m.m.RUnlock()
22+
23+
_, found := m.sections[key]
24+
25+
return found
26+
}
27+
1928
func (m *memory) Section(key ...string) persistence.Section {
2029
m.m.RLock()
2130
s, ok := m.sections[key[0]]
@@ -48,7 +57,7 @@ func (m *memory) SectionKeys() []string {
4857
return keys
4958
}
5059

51-
func (m *memory) DeleteSection(key string) bool {
60+
func (m *memory) SectionDelete(key string) bool {
5261
m.m.Lock()
5362
defer m.m.Unlock()
5463

impl/memory/memory_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func TestMemory_DeleteSection(t *testing.T) {
252252
s.Section("one")
253253
assert.Contains(t, s.SectionKeys(), "one")
254254

255-
s.DeleteSection("one")
255+
s.SectionDelete("one")
256256
assert.NotContains(t, s.SectionKeys(), "one")
257257
})
258258
}
@@ -267,6 +267,16 @@ func TestMemory_Exists(t *testing.T) {
267267
})
268268
}
269269

270+
func TestMemory_SectionExists(t *testing.T) {
271+
t.Run("returns if a section exists", func(t *testing.T) {
272+
s := New()
273+
274+
_ = s.Section("key")
275+
assert.True(t, s.SectionExists("key"))
276+
assert.False(t, s.SectionExists("otherKey"))
277+
})
278+
}
279+
270280
func TestMemory_SectionKeyNotClash(t *testing.T) {
271281
t.Run("ensure that keys and sections dont shared the same name space", func(t *testing.T) {
272282
s := New()

interface.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package persistence
33
type Section interface {
44
Section(key ...string) Section
55
SectionKeys() []string
6-
DeleteSection(key string) bool
6+
SectionExists(key string) bool
7+
SectionDelete(key string) bool
78

89
Keys() []string
910
Exists(key string) bool

0 commit comments

Comments
 (0)