cache: fix tests writing to empty path

This meant the tests were writing to the current directory instead of
a temporary directory.
This commit is contained in:
Nick Craig-Wood 2020-05-19 16:01:35 +01:00
parent eb6e9b194a
commit bdafbad61e

View file

@ -1009,6 +1009,15 @@ func (r *run) newCacheFs(t *testing.T, remote, id string, needRemote, purge bool
return nil, nil return nil, nil
} }
// Config to pass to NewFs
m := configmap.Simple{}
for k, v := range r.runDefaultCfgMap {
m.Set(k, v)
}
for k, v := range flags {
m.Set(k, v)
}
// if the remote doesn't exist, create a new one with a local one for it // if the remote doesn't exist, create a new one with a local one for it
// identify which is the cache remote (it can be wrapped by a crypt too) // identify which is the cache remote (it can be wrapped by a crypt too)
rootIsCrypt := false rootIsCrypt := false
@ -1017,8 +1026,8 @@ func (r *run) newCacheFs(t *testing.T, remote, id string, needRemote, purge bool
localRemote := remote + "-local" localRemote := remote + "-local"
config.FileSet(localRemote, "type", "local") config.FileSet(localRemote, "type", "local")
config.FileSet(localRemote, "nounc", "true") config.FileSet(localRemote, "nounc", "true")
config.FileSet(remote, "type", "cache") m.Set("type", "cache")
config.FileSet(remote, "remote", localRemote+":/var/tmp/"+localRemote) m.Set("remote", localRemote+":"+filepath.Join(os.TempDir(), localRemote))
} else { } else {
remoteType := config.FileGet(remote, "type", "") remoteType := config.FileGet(remote, "type", "")
if remoteType == "" { if remoteType == "" {
@ -1028,8 +1037,8 @@ func (r *run) newCacheFs(t *testing.T, remote, id string, needRemote, purge bool
if remoteType != "cache" { if remoteType != "cache" {
if remoteType == "crypt" { if remoteType == "crypt" {
rootIsCrypt = true rootIsCrypt = true
config.FileSet(remote, "password", cryptPassword1) m.Set("password", cryptPassword1)
config.FileSet(remote, "password2", cryptPassword2) m.Set("password2", cryptPassword2)
} }
remoteRemote := config.FileGet(remote, "remote", "") remoteRemote := config.FileGet(remote, "remote", "")
if remoteRemote == "" { if remoteRemote == "" {
@ -1055,14 +1064,6 @@ func (r *run) newCacheFs(t *testing.T, remote, id string, needRemote, purge bool
fs.Config.LowLevelRetries = 1 fs.Config.LowLevelRetries = 1
m := configmap.Simple{}
for k, v := range r.runDefaultCfgMap {
m.Set(k, v)
}
for k, v := range flags {
m.Set(k, v)
}
// Instantiate root // Instantiate root
if purge { if purge {
boltDb.PurgeTempUploads() boltDb.PurgeTempUploads()