2024-09-09 10:53:00 +01:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rclone/rclone/cmd/mountlib"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
_ "github.com/rclone/rclone/backend/local"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestApplyOptions(t *testing.T) {
|
|
|
|
vol := &Volume{
|
|
|
|
Name: "testName",
|
|
|
|
MountPoint: "testPath",
|
|
|
|
drv: &Driver{
|
|
|
|
root: "testRoot",
|
|
|
|
},
|
|
|
|
mnt: &mountlib.MountPoint{
|
|
|
|
MountPoint: "testPath",
|
|
|
|
},
|
build: modernize Go usage
This commit modernizes Go usage. This was done with:
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
Then files needed to be `go fmt`ed and a few comments needed to be
restored.
The modernizations include replacing
- if/else conditional assignment by a call to the built-in min or max functions added in go1.21
- sort.Slice(x, func(i, j int) bool) { return s[i] < s[j] } by a call to slices.Sort(s), added in go1.21
- interface{} by the 'any' type added in go1.18
- append([]T(nil), s...) by slices.Clone(s) or slices.Concat(s), added in go1.21
- loop around an m[k]=v map update by a call to one of the Collect, Copy, Clone, or Insert functions from the maps package, added in go1.21
- []byte(fmt.Sprintf...) by fmt.Appendf(nil, ...), added in go1.19
- append(s[:i], s[i+1]...) by slices.Delete(s, i, i+1), added in go1.21
- a 3-clause for i := 0; i < n; i++ {} loop by for i := range n {}, added in go1.22
2025-02-26 21:08:12 +00:00
|
|
|
mountReqs: make(map[string]any),
|
2024-09-09 10:53:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Happy path
|
|
|
|
volOpt := VolOpts{
|
|
|
|
"remote": "/tmp/docker",
|
|
|
|
"persist": "FALSE",
|
|
|
|
"mount_type": "potato",
|
|
|
|
// backend options
|
|
|
|
"--local-case-sensitive": "true",
|
|
|
|
"local_no_check_updated": "1",
|
|
|
|
// mount options
|
|
|
|
"debug-fuse": "true",
|
|
|
|
"attr_timeout": "100s",
|
|
|
|
"--async-read": "TRUE",
|
|
|
|
// vfs options
|
|
|
|
"no-modtime": "1",
|
|
|
|
"no_checksum": "true",
|
|
|
|
"--no-seek": "true",
|
|
|
|
}
|
|
|
|
err := vol.applyOptions(volOpt)
|
|
|
|
require.NoError(t, err)
|
|
|
|
// normal options
|
|
|
|
assert.Equal(t, ":local,case_sensitive='true',no_check_updated='1':/tmp/docker", vol.fsString)
|
|
|
|
assert.Equal(t, false, vol.persist)
|
|
|
|
assert.Equal(t, "potato", vol.mountType)
|
|
|
|
// mount options
|
|
|
|
assert.Equal(t, true, vol.mnt.MountOpt.DebugFUSE)
|
|
|
|
assert.Equal(t, fs.Duration(100*time.Second), vol.mnt.MountOpt.AttrTimeout)
|
|
|
|
assert.Equal(t, true, vol.mnt.MountOpt.AsyncRead)
|
|
|
|
// vfs options
|
|
|
|
assert.Equal(t, true, vol.mnt.VFSOpt.NoModTime)
|
|
|
|
assert.Equal(t, true, vol.mnt.VFSOpt.NoChecksum)
|
|
|
|
assert.Equal(t, true, vol.mnt.VFSOpt.NoSeek)
|
|
|
|
|
|
|
|
// Check errors
|
|
|
|
err = vol.applyOptions(VolOpts{
|
|
|
|
"debug-fuse": "POTATO",
|
|
|
|
})
|
|
|
|
require.ErrorContains(t, err, "cannot parse mount options")
|
|
|
|
err = vol.applyOptions(VolOpts{
|
|
|
|
"no-modtime": "POTATO",
|
|
|
|
})
|
|
|
|
require.ErrorContains(t, err, "cannot parse vfs options")
|
|
|
|
err = vol.applyOptions(VolOpts{
|
|
|
|
"remote": "/tmp/docker",
|
|
|
|
"local_not_found": "POTATO",
|
|
|
|
})
|
|
|
|
require.ErrorContains(t, err, "unsupported backend option")
|
|
|
|
|
|
|
|
}
|