2017-11-20 11:16:05 +00:00
|
|
|
package touch
|
|
|
|
|
|
|
|
import (
|
2019-06-17 08:34:30 +00:00
|
|
|
"context"
|
2017-11-20 11:16:05 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
_ "github.com/rclone/rclone/backend/local"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fstest"
|
2017-11-20 11:16:05 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2018-02-02 13:46:56 +00:00
|
|
|
var (
|
|
|
|
t1 = fstest.Time("2017-02-03T04:05:06.499999999Z")
|
|
|
|
)
|
|
|
|
|
|
|
|
func checkFile(t *testing.T, r fs.Fs, path string, content string) {
|
2021-05-22 19:06:24 +00:00
|
|
|
timeAtrFromFlags, err := timeOfTouch()
|
2018-02-02 13:46:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
file1 := fstest.NewItem(path, content, timeAtrFromFlags)
|
|
|
|
fstest.CheckItems(t, r, file1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestMain drives the tests
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
fstest.TestMain(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTouchOneFile(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
2019-06-17 08:34:30 +00:00
|
|
|
err := Touch(context.Background(), r.Fremote, "newFile")
|
2017-11-20 11:16:05 +00:00
|
|
|
require.NoError(t, err)
|
2019-06-17 08:34:30 +00:00
|
|
|
_, err = r.Fremote.NewObject(context.Background(), "newFile")
|
2017-11-20 11:16:05 +00:00
|
|
|
require.NoError(t, err)
|
2018-02-02 13:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTouchWithNoCreateFlag(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
2017-11-20 11:16:05 +00:00
|
|
|
|
|
|
|
notCreateNewFile = true
|
2019-06-17 08:34:30 +00:00
|
|
|
err := Touch(context.Background(), r.Fremote, "newFile")
|
2017-11-20 11:16:05 +00:00
|
|
|
require.NoError(t, err)
|
2019-06-17 08:34:30 +00:00
|
|
|
_, err = r.Fremote.NewObject(context.Background(), "newFile")
|
2018-02-02 13:46:56 +00:00
|
|
|
require.Error(t, err)
|
2017-11-20 11:16:05 +00:00
|
|
|
notCreateNewFile = false
|
2018-02-02 13:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTouchWithTimestamp(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
2017-11-20 11:16:05 +00:00
|
|
|
|
|
|
|
timeAsArgument = "060102"
|
2018-02-02 13:46:56 +00:00
|
|
|
srcFileName := "oldFile"
|
2019-06-17 08:34:30 +00:00
|
|
|
err := Touch(context.Background(), r.Fremote, srcFileName)
|
2017-11-20 11:16:05 +00:00
|
|
|
require.NoError(t, err)
|
2018-02-02 13:46:56 +00:00
|
|
|
checkFile(t, r.Fremote, srcFileName, "")
|
|
|
|
}
|
|
|
|
|
Spelling fixes
Fix spelling of: above, already, anonymous, associated,
authentication, bandwidth, because, between, blocks, calculate,
candidates, cautious, changelog, cleaner, clipboard, command,
completely, concurrently, considered, constructs, corrupt, current,
daemon, dependencies, deprecated, directory, dispatcher, download,
eligible, ellipsis, encrypter, endpoint, entrieslist, essentially,
existing writers, existing, expires, filesystem, flushing, frequently,
hierarchy, however, implementation, implements, inaccurate,
individually, insensitive, longer, maximum, metadata, modified,
multipart, namedirfirst, nextcloud, obscured, opened, optional,
owncloud, pacific, passphrase, password, permanently, persimmon,
positive, potato, protocol, quota, receiving, recommends, referring,
requires, revisited, satisfied, satisfies, satisfy, semver,
serialized, session, storage, strategies, stringlist, successful,
supported, surprise, temporarily, temporary, transactions, unneeded,
update, uploads, wrapped
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-10-09 00:17:24 +00:00
|
|
|
func TestTouchWithLongerTimestamp(t *testing.T) {
|
2018-02-02 13:46:56 +00:00
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
2017-11-20 11:16:05 +00:00
|
|
|
|
|
|
|
timeAsArgument = "2006-01-02T15:04:05"
|
2018-02-02 13:46:56 +00:00
|
|
|
srcFileName := "oldFile"
|
2019-06-17 08:34:30 +00:00
|
|
|
err := Touch(context.Background(), r.Fremote, srcFileName)
|
2017-11-20 11:16:05 +00:00
|
|
|
require.NoError(t, err)
|
2018-02-02 13:46:56 +00:00
|
|
|
checkFile(t, r.Fremote, srcFileName, "")
|
|
|
|
}
|
2017-11-20 11:16:05 +00:00
|
|
|
|
2018-02-02 13:46:56 +00:00
|
|
|
func TestTouchUpdateTimestamp(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
srcFileName := "a"
|
|
|
|
content := "aaa"
|
2019-06-17 08:34:30 +00:00
|
|
|
file1 := r.WriteObject(context.Background(), srcFileName, content, t1)
|
2021-11-09 11:43:36 +00:00
|
|
|
r.CheckRemoteItems(t, file1)
|
2018-02-02 13:46:56 +00:00
|
|
|
|
|
|
|
timeAsArgument = "121212"
|
2019-06-17 08:34:30 +00:00
|
|
|
err := Touch(context.Background(), r.Fremote, "a")
|
2017-11-20 11:16:05 +00:00
|
|
|
require.NoError(t, err)
|
2018-02-02 13:46:56 +00:00
|
|
|
checkFile(t, r.Fremote, srcFileName, content)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTouchUpdateTimestampWithCFlag(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
srcFileName := "a"
|
|
|
|
content := "aaa"
|
2019-06-17 08:34:30 +00:00
|
|
|
file1 := r.WriteObject(context.Background(), srcFileName, content, t1)
|
2021-11-09 11:43:36 +00:00
|
|
|
r.CheckRemoteItems(t, file1)
|
2018-02-02 13:46:56 +00:00
|
|
|
|
|
|
|
notCreateNewFile = true
|
|
|
|
timeAsArgument = "121212"
|
2019-06-17 08:34:30 +00:00
|
|
|
err := Touch(context.Background(), r.Fremote, "a")
|
2017-11-20 11:16:05 +00:00
|
|
|
require.NoError(t, err)
|
2018-02-02 13:46:56 +00:00
|
|
|
checkFile(t, r.Fremote, srcFileName, content)
|
|
|
|
notCreateNewFile = false
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTouchCreateMultipleDirAndFile(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
longPath := "a/b/c.txt"
|
2019-06-17 08:34:30 +00:00
|
|
|
err := Touch(context.Background(), r.Fremote, longPath)
|
2017-11-20 11:16:05 +00:00
|
|
|
require.NoError(t, err)
|
2018-02-02 13:46:56 +00:00
|
|
|
file1 := fstest.NewItem("a/b/c.txt", "", t1)
|
|
|
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, []string{"a", "a/b"}, fs.ModTimeNotSupported)
|
2017-11-20 11:16:05 +00:00
|
|
|
}
|
2021-10-21 16:22:58 +00:00
|
|
|
|
|
|
|
func TestTouchEmptyDir(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
err := r.Fremote.Mkdir(context.Background(), "a")
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = Touch(context.Background(), r.Fremote, "a")
|
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{}, []string{"a"}, fs.ModTimeNotSupported)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTouchDirWithFiles(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
err := r.Fremote.Mkdir(context.Background(), "a")
|
|
|
|
require.NoError(t, err)
|
|
|
|
file1 := r.WriteObject(context.Background(), "a/f1", "111", t1)
|
|
|
|
file2 := r.WriteObject(context.Background(), "a/f2", "222", t1)
|
|
|
|
err = Touch(context.Background(), r.Fremote, "a")
|
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2}, []string{"a"}, fs.ModTimeNotSupported)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRecursiveTouchDirWithFiles(t *testing.T) {
|
|
|
|
r := fstest.NewRun(t)
|
|
|
|
defer r.Finalise()
|
|
|
|
|
|
|
|
err := r.Fremote.Mkdir(context.Background(), "a/b/c")
|
|
|
|
require.NoError(t, err)
|
|
|
|
file1 := r.WriteObject(context.Background(), "a/f1", "111", t1)
|
|
|
|
file2 := r.WriteObject(context.Background(), "a/b/f2", "222", t1)
|
|
|
|
file3 := r.WriteObject(context.Background(), "a/b/c/f3", "333", t1)
|
|
|
|
recursive = true
|
|
|
|
err = Touch(context.Background(), r.Fremote, "a")
|
|
|
|
recursive = false
|
|
|
|
require.NoError(t, err)
|
|
|
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1, file2, file3}, []string{"a", "a/b", "a/b/c"}, fs.ModTimeNotSupported)
|
|
|
|
}
|