(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestVersionWorksWithoutAccessibleConfigFile(t *testing.T) { |
| 14 | // create temp config file |
| 15 | tempFile, err := os.CreateTemp("", "unreadable_config.conf") |
| 16 | assert.NoError(t, err) |
| 17 | path := tempFile.Name() |
| 18 | defer func() { |
| 19 | err := os.Remove(path) |
| 20 | assert.NoError(t, err) |
| 21 | }() |
| 22 | assert.NoError(t, tempFile.Close()) |
| 23 | if runtime.GOOS != "windows" { |
| 24 | assert.NoError(t, os.Chmod(path, 0000)) |
| 25 | } |
| 26 | // re-wire |
| 27 | oldOsStdout := os.Stdout |
| 28 | oldConfigPath := config.GetConfigPath() |
| 29 | assert.NoError(t, config.SetConfigPath(path)) |
| 30 | os.Stdout = nil |
| 31 | defer func() { |
| 32 | os.Stdout = oldOsStdout |
| 33 | assert.NoError(t, config.SetConfigPath(oldConfigPath)) |
| 34 | }() |
| 35 | |
| 36 | cmd.Root.SetArgs([]string{"version"}) |
| 37 | assert.NotPanics(t, func() { |
| 38 | assert.NoError(t, cmd.Root.Execute()) |
| 39 | }) |
| 40 | |
| 41 | // This causes rclone to exit and the tests to stop! |
| 42 | // cmd.Root.SetArgs([]string{"--version"}) |
| 43 | // assert.NotPanics(t, func() { |
| 44 | // assert.NoError(t, cmd.Root.Execute()) |
| 45 | // }) |
| 46 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…