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)
|
2018-02-02 13:46:56 +00:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
|
|
|
|
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)
|
2018-02-02 13:46:56 +00:00
|
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
|
|
|
|
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
|
|
|
}
|