github.com/artpar/rclone@v1.67.3/backend/ulozto/ulozto_test.go (about) 1 package ulozto 2 3 import ( 4 "context" 5 "errors" 6 "testing" 7 "time" 8 9 "github.com/artpar/rclone/backend/ulozto/api" 10 "github.com/artpar/rclone/fs" 11 "github.com/artpar/rclone/fs/hash" 12 "github.com/artpar/rclone/fs/operations" 13 "github.com/artpar/rclone/fstest" 14 "github.com/stretchr/testify/require" 15 16 "github.com/artpar/rclone/fstest/fstests" 17 ) 18 19 // TestIntegration runs integration tests against the remote 20 func TestIntegration(t *testing.T) { 21 fstests.Run(t, &fstests.Opt{ 22 RemoteName: "TestUlozto:", 23 NilObject: (*Object)(nil), 24 }) 25 } 26 27 // TestListWithoutMetadata verifies that basic operations can be performed even if the remote file wasn't written by 28 // rclone, or the serialized metadata can't be read. 29 func TestListWithoutMetadata(t *testing.T) { 30 const ( 31 remoteName = "TestUlozto:" 32 payload = "42foobar42" 33 sha256 = "d41f400003e93eb0891977f525e73ecedfa04272d2036f6137106168ecb196ab" 34 md5 = "8ad32cfeb3dc0f5092261268f335e0a5" 35 filesize = len(payload) 36 ) 37 ctx := context.Background() 38 fstest.Initialise() 39 subRemoteName, subRemoteLeaf, err := fstest.RandomRemoteName(remoteName) 40 require.NoError(t, err) 41 f, err := fs.NewFs(ctx, subRemoteName) 42 if errors.Is(err, fs.ErrorNotFoundInConfigFile) { 43 t.Logf("Didn't find %q in config file - skipping tests", remoteName) 44 return 45 } 46 require.NoError(t, err) 47 48 file := fstest.Item{ModTime: time.UnixMilli(123456789), Path: subRemoteLeaf, Size: int64(filesize), Hashes: map[hash.Type]string{ 49 hash.SHA256: sha256, 50 hash.MD5: md5, 51 }} 52 53 // Create a file with the given content and metadata 54 obj := fstests.PutTestContents(ctx, t, f, &file, payload, false) 55 56 // Verify the file has been uploaded 57 fstest.CheckListing(t, f, []fstest.Item{file}) 58 59 // Now delete the description metadata 60 uloztoObj := obj.(*Object) 61 err = uloztoObj.updateFileProperties(ctx, api.UpdateDescriptionRequest{ 62 Description: "", 63 }) 64 65 require.NoError(t, err) 66 67 // Listing the file should still succeed, although with estimated mtime and no hashes 68 fileWithoutDetails := fstest.Item{Path: subRemoteLeaf, Size: int64(filesize), ModTime: uloztoObj.remoteFsMtime, Hashes: map[hash.Type]string{ 69 hash.SHA256: "", 70 hash.MD5: "", 71 }} 72 fstest.CheckListing(t, f, []fstest.Item{fileWithoutDetails}) 73 74 mtime := time.UnixMilli(987654321) 75 76 // When we update the mtime it should be reflected but hashes should stay intact 77 require.NoError(t, obj.SetModTime(ctx, mtime)) 78 updatedMtimeFile := fstest.Item{Path: subRemoteLeaf, Size: int64(filesize), ModTime: mtime, Hashes: map[hash.Type]string{ 79 hash.SHA256: "", 80 hash.MD5: "", 81 }} 82 fstest.CheckListing(t, f, []fstest.Item{updatedMtimeFile}) 83 84 // Tear down 85 require.NoError(t, operations.Purge(ctx, f, "")) 86 }