MCPcopy
hub / github.com/rclone/rclone / PutTestContentsMetadata

Function PutTestContentsMetadata

fstest/fstests/fstests.go:156–205  ·  view source on GitHub ↗

check interface PutTestContentsMetadata puts file with given contents to the remote and checks it but unlike TestPutLarge doesn't remove It uploads the object with the mimeType and metadata passed in if set. It returns the object which will have been checked if check is set

(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item, useFileHashes bool, contents string, check bool, mimeType string, metadata fs.Metadata, options ...fs.OpenOption)

Source from the content-addressed store, hash-verified

154//
155// It returns the object which will have been checked if check is set
156func PutTestContentsMetadata(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item, useFileHashes bool, contents string, check bool, mimeType string, metadata fs.Metadata, options ...fs.OpenOption) fs.Object {
157 var (
158 err error
159 obj fs.Object
160 uploadHash *hash.MultiHasher
161 )
162 retry(t, "Put", func() error {
163 buf := bytes.NewBufferString(contents)
164 uploadHash = hash.NewMultiHasher()
165 in := io.TeeReader(buf, uploadHash)
166
167 file.Size = int64(buf.Len())
168 // The caller explicitly indicates whether the hashes in the file parameter should be used. If hashes is nil,
169 // then NewStaticObjectInfo will calculate default hashes for use in the check.
170 hashes := file.Hashes
171 if !useFileHashes {
172 hashes = nil
173 }
174 obji := object.NewStaticObjectInfo(file.Path, file.ModTime, file.Size, true, hashes, nil)
175 if mimeType != "" || metadata != nil {
176 // force the --metadata flag on temporarily
177 if metadata != nil {
178 ci := fs.GetConfig(ctx)
179 previousMetadata := ci.Metadata
180 ci.Metadata = true
181 defer func() {
182 ci.Metadata = previousMetadata
183 }()
184 }
185 obji.WithMetadata(metadata).WithMimeType(mimeType)
186 }
187 obj, err = f.Put(ctx, in, obji, options...)
188 return err
189 })
190 file.Hashes = uploadHash.Sums()
191 if check {
192 // Overwrite time with that in metadata if it is already specified
193 mtime, ok := metadata["mtime"]
194 if ok {
195 modTime, err := time.Parse(time.RFC3339Nano, mtime)
196 require.NoError(t, err)
197 file.ModTime = modTime
198 }
199 file.Check(t, obj, f.Precision())
200 // Re-read the object and check again
201 obj = fstest.NewObject(ctx, t, f, file.Path)
202 file.Check(t, obj, f.Precision())
203 }
204 return obj
205}
206
207// PutTestContents puts file with given contents to the remote and checks it but unlike TestPutLarge doesn't remove
208func PutTestContents(ctx context.Context, t *testing.T, f fs.Fs, file *fstest.Item, contents string, check bool) fs.Object {

Callers 9

internalTestMetadataMethod · 0.92
InternalTestMetadataMethod · 0.92
InternalTestMetadataMethod · 0.92
putWithMetaMethod · 0.92
testGzipEncodingMethod · 0.92
testMetadataPathsMethod · 0.92
PutTestContentsFunction · 0.85
testPutMimeTypeFunction · 0.85
RunFunction · 0.85

Calls 12

WithMetadataMethod · 0.95
NewMultiHasherFunction · 0.92
NewStaticObjectInfoFunction · 0.92
GetConfigFunction · 0.92
NewObjectFunction · 0.92
SumsMethod · 0.80
retryFunction · 0.70
PutMethod · 0.65
PrecisionMethod · 0.65
LenMethod · 0.45
WithMimeTypeMethod · 0.45
CheckMethod · 0.45

Tested by 6

internalTestMetadataMethod · 0.74
InternalTestMetadataMethod · 0.74
InternalTestMetadataMethod · 0.74
putWithMetaMethod · 0.74
testGzipEncodingMethod · 0.74
testMetadataPathsMethod · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…