config: replace defaultConfig with a thread-safe in-memory implementation

This commit is contained in:
Chris Macklin
2021-05-03 14:01:06 -07:00
committed by Nick Craig-Wood
parent 6ef7178ee4
commit 732bc08ced
3 changed files with 132 additions and 37 deletions

View File

@@ -0,0 +1,42 @@
package config
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDefaultStorage(t *testing.T) {
a := assert.New(t)
ds := newDefaultStorage()
section := "test"
key := "key"
val := "something"
ds.SetValue(section, key, val)
ds.SetValue("some other section", key, val)
v, hasVal := ds.GetValue(section, key)
a.True(hasVal)
a.Equal(val, v)
a.ElementsMatch([]string{section, "some other section"}, ds.GetSectionList())
a.True(ds.HasSection(section))
a.False(ds.HasSection("nope"))
a.Equal([]string{key}, ds.GetKeyList(section))
_, err := ds.Serialize()
a.NoError(err)
a.True(ds.DeleteKey(section, key))
a.False(ds.DeleteKey(section, key))
a.False(ds.DeleteKey("not there", key))
_, hasVal = ds.GetValue(section, key)
a.False(hasVal)
ds.DeleteSection(section)
a.False(ds.HasSection(section))
}