github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/cmd/version/version_test.go (about) 1 package version 2 3 import ( 4 "io/ioutil" 5 "os" 6 "runtime" 7 "testing" 8 9 "github.com/ncw/rclone/cmd" 10 "github.com/ncw/rclone/fs/config" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestVersionWorksWithoutAccessibleConfigFile(t *testing.T) { 15 // create temp config file 16 tempFile, err := ioutil.TempFile("", "unreadable_config.conf") 17 assert.NoError(t, err) 18 path := tempFile.Name() 19 defer func() { 20 err := os.Remove(path) 21 assert.NoError(t, err) 22 }() 23 assert.NoError(t, tempFile.Close()) 24 if runtime.GOOS != "windows" { 25 assert.NoError(t, os.Chmod(path, 0000)) 26 } 27 // re-wire 28 oldOsStdout := os.Stdout 29 oldConfigPath := config.ConfigPath 30 config.ConfigPath = path 31 os.Stdout = nil 32 defer func() { 33 os.Stdout = oldOsStdout 34 config.ConfigPath = oldConfigPath 35 }() 36 37 cmd.Root.SetArgs([]string{"version"}) 38 assert.NotPanics(t, func() { 39 assert.NoError(t, cmd.Root.Execute()) 40 }) 41 42 // This causes rclone to exit and the tests to stop! 43 // cmd.Root.SetArgs([]string{"--version"}) 44 // assert.NotPanics(t, func() { 45 // assert.NoError(t, cmd.Root.Execute()) 46 // }) 47 }