Skip to content

Commit

Permalink
Test multipart form headers
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Sep 11, 2024
1 parent bf0f4bc commit 827263c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions storage/file_persister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func TestRemoteFilePersister(t *testing.T) {
name string
path string
dataToUpload string
multipartFormFields map[string]string
wantPresignedURLBody string
wantPresignedHeaders map[string]string
wantPresignedURLMethod string
Expand All @@ -104,6 +105,10 @@ func TestRemoteFilePersister(t *testing.T) {
name: "upload_file",
path: "some/path/file.png",
dataToUpload: "here's some data",
multipartFormFields: map[string]string{
"fooKey": "foo",
"barKey": "bar",
},
wantPresignedURLBody: `{
"service":"aws_s3",
"operation": "upload_post",
Expand All @@ -121,6 +126,10 @@ func TestRemoteFilePersister(t *testing.T) {
name: "upload_file",
path: "some/path/file.png",
dataToUpload: "here's some data",
multipartFormFields: map[string]string{ // provide different form fields then the previous test
"bazKey": "baz",
"quxKey": "qux",
},
wantPresignedURLBody: `{
"service":"aws_s3",
"operation": "upload_post",
Expand Down Expand Up @@ -235,16 +244,27 @@ func TestRemoteFilePersister(t *testing.T) {
assert.Equal(t, v, r.Header[k][0])
}

var formFields string
for k, v := range tt.multipartFormFields {
formFields += fmt.Sprintf(`"%s":"%s",`, k, v)
}
formFields = strings.TrimRight(formFields, ",")

w.WriteHeader(tt.getPresignedURLResponse)
_, err = fmt.Fprintf(w, `{
"service": "aws_s3",
"urls": [{
"name": "%s",
"pre_signed_url": "%s",
"method": "%s",
"form_fields": {"key":"a", "value":"b", "key2":"c", "value2":"d"}
"form_fields": {%s}
}]
}`, basePath+"/"+tt.path, s.URL+uploadEndpoint, tt.wantPresignedURLMethod)
}`,
basePath+"/"+tt.path,
s.URL+uploadEndpoint,
tt.wantPresignedURLMethod,
formFields,
)

require.NoError(t, err)
},
Expand Down

0 comments on commit 827263c

Please sign in to comment.