catbase/config/config_test.go

36 lines
835 B
Go
Raw Normal View History

package config
import (
2021-12-21 19:08:20 +00:00
"io/ioutil"
"os"
"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())
2021-12-21 19:30:02 +00:00
cfg := ReadConfig(storeFile.Name())
expected := "value"
cfg.Set("test", expected)
2019-01-22 00:16:57 +00:00
actual := cfg.Get("test", "NOPE")
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())
2021-12-21 19:30:02 +00:00
cfg := ReadConfig(storeFile.Name())
expected := []string{"a", "b", "c"}
cfg.SetArray("test", expected)
2019-01-22 00:16:57 +00:00
actual := cfg.GetArray("test", []string{"NOPE"})
assert.Equal(t, expected, actual, "Config did not store values")
}