mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-25 17:10:28 +00:00
48451a9924
Configurable custom commands and/or HTTP notifications on SFTP upload, download, delete or rename
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
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().BindPort == emptySFTPDConf.BindPort {
|
|
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)
|
|
}
|