2021-03-11 16:20:31 +00:00
|
|
|
// These are in an external package because we need to import configfile
|
|
|
|
|
2021-03-10 15:40:34 +00:00
|
|
|
package config_test
|
2015-02-19 19:26:00 +00:00
|
|
|
|
2016-02-16 15:25:27 +00:00
|
|
|
import (
|
2019-06-19 12:51:19 +00:00
|
|
|
"bytes"
|
2020-11-05 16:59:59 +00:00
|
|
|
"context"
|
2017-06-25 06:55:54 +00:00
|
|
|
"io/ioutil"
|
2016-02-16 15:25:27 +00:00
|
|
|
"testing"
|
2016-06-29 16:59:31 +00:00
|
|
|
|
2021-03-10 15:40:34 +00:00
|
|
|
"github.com/rclone/rclone/fs/config"
|
|
|
|
"github.com/rclone/rclone/fs/config/configfile"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs/rc"
|
2016-06-29 16:59:31 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2016-02-16 15:25:27 +00:00
|
|
|
)
|
2015-02-19 19:26:00 +00:00
|
|
|
|
2016-02-16 15:25:27 +00:00
|
|
|
func TestConfigLoad(t *testing.T) {
|
2021-03-10 15:40:34 +00:00
|
|
|
oldConfigPath := config.ConfigPath
|
|
|
|
config.ConfigPath = "./testdata/plain.conf"
|
2016-02-29 21:43:37 +00:00
|
|
|
defer func() {
|
2021-03-10 15:40:34 +00:00
|
|
|
config.ConfigPath = oldConfigPath
|
2016-02-29 21:43:37 +00:00
|
|
|
}()
|
2021-03-10 15:40:34 +00:00
|
|
|
config.ClearConfigPassword()
|
|
|
|
configfile.LoadConfig(context.Background())
|
|
|
|
sections := config.Data.GetSectionList()
|
2016-02-16 15:25:27 +00:00
|
|
|
var expect = []string{"RCLONE_ENCRYPT_V0", "nounc", "unc"}
|
2016-06-29 16:59:31 +00:00
|
|
|
assert.Equal(t, expect, sections)
|
2016-02-16 15:25:27 +00:00
|
|
|
|
2021-03-10 15:40:34 +00:00
|
|
|
keys := config.Data.GetKeyList("nounc")
|
2016-02-16 15:25:27 +00:00
|
|
|
expect = []string{"type", "nounc"}
|
2016-06-29 16:59:31 +00:00
|
|
|
assert.Equal(t, expect, keys)
|
2016-02-16 15:25:27 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 12:51:19 +00:00
|
|
|
func TestFileRefresh(t *testing.T) {
|
2020-11-05 18:02:26 +00:00
|
|
|
ctx := context.Background()
|
2019-06-19 12:51:19 +00:00
|
|
|
defer testConfigFile(t, "refresh.conf")()
|
2021-03-10 15:40:34 +00:00
|
|
|
require.NoError(t, config.CreateRemote(ctx, "refresh_test", "config_test_remote", rc.Params{
|
2019-06-19 12:51:19 +00:00
|
|
|
"bool": true,
|
2020-05-12 13:24:53 +00:00
|
|
|
}, false, false))
|
2021-03-10 15:40:34 +00:00
|
|
|
b, err := ioutil.ReadFile(config.ConfigPath)
|
2019-06-19 12:51:19 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
b = bytes.Replace(b, []byte("refresh_test"), []byte("refreshed_test"), 1)
|
2021-03-10 15:40:34 +00:00
|
|
|
err = ioutil.WriteFile(config.ConfigPath, b, 0644)
|
2019-06-19 12:51:19 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-03-10 15:40:34 +00:00
|
|
|
assert.NotEqual(t, []string{"refreshed_test"}, config.Data.GetSectionList())
|
|
|
|
err = config.FileRefresh()
|
2019-06-19 12:51:19 +00:00
|
|
|
assert.NoError(t, err)
|
2021-03-10 15:40:34 +00:00
|
|
|
assert.Equal(t, []string{"refreshed_test"}, config.Data.GetSectionList())
|
2019-06-19 12:51:19 +00:00
|
|
|
}
|