diff --git a/go.mod b/go.mod index bf10d6e..eb9f5a5 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.22.0 require ( github.com/shimmeringbee/zcl v0.0.0-20240509210644-817a66d91348 + github.com/shimmeringbee/zigbee v0.0.0-20201027194100-4e53cafc0f7a github.com/stretchr/testify v1.9.0 ) @@ -11,7 +12,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/shimmeringbee/bytecodec v0.0.0-20201107142444-94bb5c0baaee // indirect - github.com/shimmeringbee/zigbee v0.0.0-20201027194100-4e53cafc0f7a // indirect github.com/stretchr/objx v0.5.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/impl/memory/memory.go b/impl/memory/memory.go index c8bdaf3..78ada46 100644 --- a/impl/memory/memory.go +++ b/impl/memory/memory.go @@ -16,6 +16,15 @@ type memory struct { sections map[string]persistence.Section } +func (m *memory) SectionExists(key string) bool { + m.m.RLock() + defer m.m.RUnlock() + + _, found := m.sections[key] + + return found +} + func (m *memory) Section(key ...string) persistence.Section { m.m.RLock() s, ok := m.sections[key[0]] @@ -48,7 +57,7 @@ func (m *memory) SectionKeys() []string { return keys } -func (m *memory) DeleteSection(key string) bool { +func (m *memory) SectionDelete(key string) bool { m.m.Lock() defer m.m.Unlock() diff --git a/impl/memory/memory_test.go b/impl/memory/memory_test.go index 97e2443..457d2ac 100644 --- a/impl/memory/memory_test.go +++ b/impl/memory/memory_test.go @@ -252,7 +252,7 @@ func TestMemory_DeleteSection(t *testing.T) { s.Section("one") assert.Contains(t, s.SectionKeys(), "one") - s.DeleteSection("one") + s.SectionDelete("one") assert.NotContains(t, s.SectionKeys(), "one") }) } @@ -267,6 +267,16 @@ func TestMemory_Exists(t *testing.T) { }) } +func TestMemory_SectionExists(t *testing.T) { + t.Run("returns if a section exists", func(t *testing.T) { + s := New() + + _ = s.Section("key") + assert.True(t, s.SectionExists("key")) + assert.False(t, s.SectionExists("otherKey")) + }) +} + func TestMemory_SectionKeyNotClash(t *testing.T) { t.Run("ensure that keys and sections dont shared the same name space", func(t *testing.T) { s := New() diff --git a/interface.go b/interface.go index ea7d366..7e0d5c1 100644 --- a/interface.go +++ b/interface.go @@ -3,7 +3,8 @@ package persistence type Section interface { Section(key ...string) Section SectionKeys() []string - DeleteSection(key string) bool + SectionExists(key string) bool + SectionDelete(key string) bool Keys() []string Exists(key string) bool