habbgo/config/config_test.go

40 lines
816 B
Go
Raw Normal View History

2021-09-06 01:07:49 +00:00
package config
import (
"io/ioutil"
"os"
"path"
"testing"
2022-01-08 22:29:51 +00:00
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
2021-09-06 01:07:49 +00:00
)
func TestLoadConfig(t *testing.T) {
2021-09-06 02:48:30 +00:00
home, err := ioutil.TempDir("", "")
require.NoError(t, err)
2021-09-06 01:07:49 +00:00
2021-09-06 02:48:30 +00:00
cfg := path.Join(home, "config.yaml")
LoadConfig(cfg)
_, err = os.Stat(cfg)
2021-09-06 01:07:49 +00:00
require.NoError(t, err)
}
func TestCreatesDefaultConfig(t *testing.T) {
home, err := ioutil.TempDir("", "")
require.NoError(t, err)
t.Log("Initializing default config file... ")
c := InitDefaultConfig()
bz, err := yaml.Marshal(c)
require.NoError(t, err)
cfg := path.Join(home, "config.yaml")
t.Logf("Writing default config file to %s", cfg)
require.NoError(t, os.WriteFile(cfg, bz, 0644))
t.Logf("Checking that config.yaml exists at %s... ", cfg)
_, err = os.Stat(cfg)
require.NoError(t, err)
}