1
mirror of https://github.com/rclone/rclone synced 2024-11-30 09:10:05 +01:00
rclone/cmd/version/version_test.go
albertony 5d6b8141ec Replace deprecated ioutil
As of Go 1.16, the same functionality is now provided by package io or
package os, and those implementations should be preferred in new code.
2022-11-07 11:41:47 +00:00

47 lines
1.1 KiB
Go

package version
import (
"os"
"runtime"
"testing"
"github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs/config"
"github.com/stretchr/testify/assert"
)
func TestVersionWorksWithoutAccessibleConfigFile(t *testing.T) {
// create temp config file
tempFile, err := os.CreateTemp("", "unreadable_config.conf")
assert.NoError(t, err)
path := tempFile.Name()
defer func() {
err := os.Remove(path)
assert.NoError(t, err)
}()
assert.NoError(t, tempFile.Close())
if runtime.GOOS != "windows" {
assert.NoError(t, os.Chmod(path, 0000))
}
// re-wire
oldOsStdout := os.Stdout
oldConfigPath := config.GetConfigPath()
assert.NoError(t, config.SetConfigPath(path))
os.Stdout = nil
defer func() {
os.Stdout = oldOsStdout
assert.NoError(t, config.SetConfigPath(oldConfigPath))
}()
cmd.Root.SetArgs([]string{"version"})
assert.NotPanics(t, func() {
assert.NoError(t, cmd.Root.Execute())
})
// This causes rclone to exit and the tests to stop!
// cmd.Root.SetArgs([]string{"--version"})
// assert.NotPanics(t, func() {
// assert.NoError(t, cmd.Root.Execute())
// })
}