sftpgo/config/config_test.go

48 lines
1.2 KiB
Go
Raw Normal View History

2019-07-26 09:34:44 +00:00
package config_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/drakkan/sftpgo/api"
"github.com/drakkan/sftpgo/config"
"github.com/drakkan/sftpgo/dataprovider"
"github.com/drakkan/sftpgo/sftpd"
)
func TestLoadConfigTest(t *testing.T) {
configDir := ".."
confName := "sftpgo.conf"
configFilePath := filepath.Join(configDir, confName)
err := config.LoadConfig(configFilePath)
if err != nil {
t.Errorf("error loading config")
}
emptyHTTPDConf := api.HTTPDConf{}
if config.GetHTTPDConfig() == emptyHTTPDConf {
t.Errorf("error loading httpd conf")
}
emptyProviderConf := dataprovider.Config{}
if config.GetProviderConf() == emptyProviderConf {
t.Errorf("error loading provider conf")
}
emptySFTPDConf := sftpd.Configuration{}
if config.GetSFTPDConfig() == emptySFTPDConf {
t.Errorf("error loading SFTPD conf")
}
confName = "sftpgo.conf.missing"
configFilePath = filepath.Join(configDir, confName)
err = config.LoadConfig(configFilePath)
if err == nil {
t.Errorf("loading a non existent config file must fail")
}
ioutil.WriteFile(configFilePath, []byte("{invalid json}"), 0666)
err = config.LoadConfig(configFilePath)
if err == nil {
t.Errorf("loading an invalid config file must fail")
}
os.Remove(configFilePath)
}