(t *testing.T, options []fs.Option, configFileName string)
| 30 | }} |
| 31 | |
| 32 | func 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 |
no test coverage detected
searching dependent graphs…