MCPcopy
hub / github.com/rclone/rclone / testConfigFile

Function testConfigFile

fs/config/ui_test.go:32–84  ·  view source on GitHub ↗
(t *testing.T, options []fs.Option, configFileName string)

Source from the content-addressed store, hash-verified

30}}
31
32func testConfigFile(t *testing.T, options []fs.Option, configFileName string) func() {
33 ctx := context.Background()
34 ci := fs.GetConfig(ctx)
35 config.ClearConfigPassword()
36 _ = os.Unsetenv("_RCLONE_CONFIG_KEY_FILE")
37 _ = os.Unsetenv("RCLONE_CONFIG_PASS")
38 // create temp config file
39 tempFile, err := os.CreateTemp("", configFileName)
40 assert.NoError(t, err)
41 path := tempFile.Name()
42 assert.NoError(t, tempFile.Close())
43
44 // temporarily adapt configuration
45 oldOsStdout := os.Stdout
46 oldConfigPath := config.GetConfigPath()
47 oldConfig := *ci
48 oldConfigFile := config.Data()
49 oldReadLine := config.ReadLine
50 oldPassword := config.Password
51 os.Stdout = nil
52 assert.NoError(t, config.SetConfigPath(path))
53 ci = &fs.ConfigInfo{}
54
55 configfile.Install()
56 assert.Equal(t, []string{}, config.Data().GetSectionList())
57
58 // Fake a filesystem/backend
59 backendName := "config_test_remote"
60 if regInfo, _ := fs.Find(backendName); regInfo != nil {
61 regInfo.Options = options
62 } else {
63 fs.Register(&fs.RegInfo{
64 Name: backendName,
65 Options: options,
66 })
67 }
68
69 // Undo the above (except registered backend, unfortunately)
70 return func() {
71 err := os.Remove(path)
72 assert.NoError(t, err)
73
74 os.Stdout = oldOsStdout
75 assert.NoError(t, config.SetConfigPath(oldConfigPath))
76 config.ReadLine = oldReadLine
77 config.Password = oldPassword
78 *ci = oldConfig
79 config.SetData(oldConfigFile)
80
81 _ = os.Unsetenv("_RCLONE_CONFIG_KEY_FILE")
82 _ = os.Unsetenv("RCLONE_CONFIG_PASS")
83 }
84}
85
86// makeReadLine makes a simple readLine which returns a fixed list of
87// strings

Callers 8

TestCRUDFunction · 0.85
TestChooseOptionFunction · 0.85
TestNewRemoteNameFunction · 0.85
TestDefaultRequiredFunction · 0.85
TestMultipleChoiceFunction · 0.85

Calls 14

GetConfigFunction · 0.92
ClearConfigPasswordFunction · 0.92
GetConfigPathFunction · 0.92
DataFunction · 0.92
SetConfigPathFunction · 0.92
InstallFunction · 0.92
FindFunction · 0.92
RegisterFunction · 0.92
SetDataFunction · 0.92
NameMethod · 0.65
CloseMethod · 0.65
GetSectionListMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…