2019-01-20 20:21:26 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2021-12-21 19:08:20 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2019-01-20 20:21:26 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetGet(t *testing.T) {
|
2021-12-21 19:08:20 +00:00
|
|
|
storeFile, err := ioutil.TempFile(os.TempDir(), "prefix-")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer os.Remove(storeFile.Name())
|
|
|
|
cfg := ReadConfig(":memory:", storeFile.Name())
|
2019-01-20 20:21:26 +00:00
|
|
|
expected := "value"
|
|
|
|
cfg.Set("test", expected)
|
2019-01-22 00:16:57 +00:00
|
|
|
actual := cfg.Get("test", "NOPE")
|
2019-01-20 20:21:26 +00:00
|
|
|
assert.Equal(t, expected, actual, "Config did not store values")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetGetArray(t *testing.T) {
|
2021-12-21 19:08:20 +00:00
|
|
|
storeFile, err := ioutil.TempFile(os.TempDir(), "prefix-")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer os.Remove(storeFile.Name())
|
|
|
|
cfg := ReadConfig(":memory:", storeFile.Name())
|
2019-01-20 20:21:26 +00:00
|
|
|
expected := []string{"a", "b", "c"}
|
|
|
|
cfg.SetArray("test", expected)
|
2019-01-22 00:16:57 +00:00
|
|
|
actual := cfg.GetArray("test", []string{"NOPE"})
|
2019-01-20 20:21:26 +00:00
|
|
|
assert.Equal(t, expected, actual, "Config did not store values")
|
|
|
|
}
|