2021-04-04 17:24:58 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-23 12:05:49 +00:00
|
|
|
"github.com/goccy/go-yaml"
|
2021-04-04 17:24:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTemplateConfig(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
require := require.New(t)
|
|
|
|
f, err := os.Open("../templates/config_template.yaml")
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
b, err := ioutil.ReadAll(f)
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
conf := &Root{}
|
|
|
|
err = yaml.Unmarshal(b, conf)
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
require.Equal(DefaultConfig(), conf)
|
|
|
|
}
|
2021-11-23 12:05:49 +00:00
|
|
|
|
|
|
|
func TestDefaults(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
r := &Root{}
|
|
|
|
dr := AddDefaults(r)
|
|
|
|
require.NotNil(dr)
|
2021-11-29 10:07:54 +00:00
|
|
|
|
|
|
|
// FUSE can be deactivated
|
|
|
|
require.Nil(dr.Fuse)
|
2021-11-23 12:05:49 +00:00
|
|
|
require.NotNil(dr.HTTPGlobal)
|
|
|
|
require.NotNil(dr.Log)
|
|
|
|
require.NotNil(dr.Torrent)
|
2021-11-29 10:07:54 +00:00
|
|
|
|
|
|
|
// Add defaults when fuse is set
|
|
|
|
r = &Root{
|
|
|
|
Fuse: &FuseGlobal{},
|
|
|
|
}
|
|
|
|
|
|
|
|
dr = AddDefaults(r)
|
|
|
|
require.NotNil(dr.Fuse)
|
|
|
|
require.Equal(mountFolder, dr.Fuse.Path)
|
|
|
|
|
2021-11-23 12:05:49 +00:00
|
|
|
}
|