mirror of https://github.com/velour/catbase.git
36 lines
835 B
Go
36 lines
835 B
Go
package config
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSetGet(t *testing.T) {
|
|
storeFile, err := ioutil.TempFile(os.TempDir(), "prefix-")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer os.Remove(storeFile.Name())
|
|
cfg := ReadConfig(storeFile.Name())
|
|
expected := "value"
|
|
cfg.Set("test", expected)
|
|
actual := cfg.Get("test", "NOPE")
|
|
assert.Equal(t, expected, actual, "Config did not store values")
|
|
}
|
|
|
|
func TestSetGetArray(t *testing.T) {
|
|
storeFile, err := ioutil.TempFile(os.TempDir(), "prefix-")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer os.Remove(storeFile.Name())
|
|
cfg := ReadConfig(storeFile.Name())
|
|
expected := []string{"a", "b", "c"}
|
|
cfg.SetArray("test", expected)
|
|
actual := cfg.GetArray("test", []string{"NOPE"})
|
|
assert.Equal(t, expected, actual, "Config did not store values")
|
|
}
|