37 lines
781 B
Go
37 lines
781 B
Go
|
package model
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"io/ioutil"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestReadConfig(t *testing.T) {
|
||
|
t.Run("should correctly read a configuration file", func(t *testing.T) {
|
||
|
f, err := ioutil.TempFile("", "birthdaybot-")
|
||
|
require.NoError(t, err)
|
||
|
defer os.Remove(f.Name())
|
||
|
|
||
|
io.WriteString(f, "---\nbirthday_file: birthday.csv")
|
||
|
f.Close()
|
||
|
|
||
|
config, err := ReadConfig(f.Name())
|
||
|
require.NoError(t, err)
|
||
|
require.Equal(t, "birthday.csv", config.BirthdayFile)
|
||
|
})
|
||
|
|
||
|
t.Run("should fail if the file doesn't exist", func(t *testing.T) {
|
||
|
f, err := ioutil.TempFile("", "birthdaybot-")
|
||
|
require.NoError(t, err)
|
||
|
f.Close()
|
||
|
os.Remove(f.Name())
|
||
|
|
||
|
config, err := ReadConfig(f.Name())
|
||
|
require.Error(t, err)
|
||
|
require.Nil(t, config)
|
||
|
})
|
||
|
}
|