MCPcopy Index your code
hub / github.com/rclone/rclone / TestVersionWorksWithoutAccessibleConfigFile

Function TestVersionWorksWithoutAccessibleConfigFile

cmd/version/version_test.go:13–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func 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}

Callers

nothing calls this directly

Calls 6

GetConfigPathFunction · 0.92
SetConfigPathFunction · 0.92
NameMethod · 0.65
RemoveMethod · 0.65
CloseMethod · 0.65
ChmodMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…