From 440d0cd1797788c31d2c722f54c85c6f898a2441 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 17 Jul 2022 13:40:45 +0100 Subject: [PATCH] s3: fix --s3-no-head panic: reflect: Elem of invalid type s3.PutObjectInput In 22abd785eba35ca2 s3: implement reading and writing of metadata #111 The reading information of objects was refactored to use the s3.HeadObjectOutput structure. Unfortunately the code branch with `--s3-no-head` was not tested otherwise this panic would have been discovered. This shows that this is path is not integration tested, so this adds a new integration test. Fixes #6322 --- backend/s3/s3.go | 2 +- backend/s3/s3_internal_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/s3/s3.go b/backend/s3/s3.go index 448b7c08f..753e800f0 100644 --- a/backend/s3/s3.go +++ b/backend/s3/s3.go @@ -4570,7 +4570,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op // uploaded properly. If size < 0 then we need to do the HEAD. if o.fs.opt.NoHead && size >= 0 { var head s3.HeadObjectOutput - structs.SetFrom(&head, req) + structs.SetFrom(&head, &req) head.ETag = &md5sumHex // doesn't matter quotes are misssing head.ContentLength = &size // If we have done a single part PUT request then we can read these diff --git a/backend/s3/s3_internal_test.go b/backend/s3/s3_internal_test.go index 2568968d6..fcaf8915f 100644 --- a/backend/s3/s3_internal_test.go +++ b/backend/s3/s3_internal_test.go @@ -67,8 +67,26 @@ func (f *Fs) InternalTestMetadata(t *testing.T) { } } +func (f *Fs) InternalTestNoHead(t *testing.T) { + ctx := context.Background() + // Set NoHead for this test + f.opt.NoHead = true + defer func() { + f.opt.NoHead = false + }() + contents := random.String(1000) + item := fstest.NewItem("test-no-head", contents, fstest.Time("2001-05-06T04:05:06.499999999Z")) + obj := fstests.PutTestContents(ctx, t, f, &item, contents, true) + defer func() { + assert.NoError(t, obj.Remove(ctx)) + }() + // PutTestcontests checks the received object + +} + func (f *Fs) InternalTest(t *testing.T) { t.Run("Metadata", f.InternalTestMetadata) + t.Run("NoHead", f.InternalTestNoHead) } var _ fstests.InternalTester = (*Fs)(nil)