mirror of
https://github.com/rclone/rclone.git
synced 2024-11-29 12:04:11 +08:00
d0888edc0a
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>
120 lines
3.0 KiB
Go
120 lines
3.0 KiB
Go
package touch
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
_ "github.com/rclone/rclone/backend/local"
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/rclone/rclone/fstest"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var (
|
|
t1 = fstest.Time("2017-02-03T04:05:06.499999999Z")
|
|
)
|
|
|
|
func checkFile(t *testing.T, r fs.Fs, path string, content string) {
|
|
layout := defaultLayout
|
|
if len(timeAsArgument) == len(layoutDateWithTime) {
|
|
layout = layoutDateWithTime
|
|
}
|
|
timeAtrFromFlags, err := time.Parse(layout, timeAsArgument)
|
|
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()
|
|
|
|
err := Touch(context.Background(), r.Fremote, "newFile")
|
|
require.NoError(t, err)
|
|
_, err = r.Fremote.NewObject(context.Background(), "newFile")
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestTouchWithNoCreateFlag(t *testing.T) {
|
|
r := fstest.NewRun(t)
|
|
defer r.Finalise()
|
|
|
|
notCreateNewFile = true
|
|
err := Touch(context.Background(), r.Fremote, "newFile")
|
|
require.NoError(t, err)
|
|
_, err = r.Fremote.NewObject(context.Background(), "newFile")
|
|
require.Error(t, err)
|
|
notCreateNewFile = false
|
|
}
|
|
|
|
func TestTouchWithTimestamp(t *testing.T) {
|
|
r := fstest.NewRun(t)
|
|
defer r.Finalise()
|
|
|
|
timeAsArgument = "060102"
|
|
srcFileName := "oldFile"
|
|
err := Touch(context.Background(), r.Fremote, srcFileName)
|
|
require.NoError(t, err)
|
|
checkFile(t, r.Fremote, srcFileName, "")
|
|
}
|
|
|
|
func TestTouchWithLongerTimestamp(t *testing.T) {
|
|
r := fstest.NewRun(t)
|
|
defer r.Finalise()
|
|
|
|
timeAsArgument = "2006-01-02T15:04:05"
|
|
srcFileName := "oldFile"
|
|
err := Touch(context.Background(), r.Fremote, srcFileName)
|
|
require.NoError(t, err)
|
|
checkFile(t, r.Fremote, srcFileName, "")
|
|
}
|
|
|
|
func TestTouchUpdateTimestamp(t *testing.T) {
|
|
r := fstest.NewRun(t)
|
|
defer r.Finalise()
|
|
|
|
srcFileName := "a"
|
|
content := "aaa"
|
|
file1 := r.WriteObject(context.Background(), srcFileName, content, t1)
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
timeAsArgument = "121212"
|
|
err := Touch(context.Background(), r.Fremote, "a")
|
|
require.NoError(t, err)
|
|
checkFile(t, r.Fremote, srcFileName, content)
|
|
}
|
|
|
|
func TestTouchUpdateTimestampWithCFlag(t *testing.T) {
|
|
r := fstest.NewRun(t)
|
|
defer r.Finalise()
|
|
|
|
srcFileName := "a"
|
|
content := "aaa"
|
|
file1 := r.WriteObject(context.Background(), srcFileName, content, t1)
|
|
fstest.CheckItems(t, r.Fremote, file1)
|
|
|
|
notCreateNewFile = true
|
|
timeAsArgument = "121212"
|
|
err := Touch(context.Background(), r.Fremote, "a")
|
|
require.NoError(t, err)
|
|
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"
|
|
err := Touch(context.Background(), r.Fremote, longPath)
|
|
require.NoError(t, err)
|
|
file1 := fstest.NewItem("a/b/c.txt", "", t1)
|
|
fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, []string{"a", "a/b"}, fs.ModTimeNotSupported)
|
|
}
|