Commit 085e5087 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Minor fixed and improvements for build artifacts implementation

parent 5ae1356e
......@@ -6,6 +6,7 @@ import (
"archive/zip"
"encoding/base64"
"errors"
"fmt"
"io"
"mime"
"net/http"
......@@ -89,7 +90,7 @@ func DownloadArtifact(myAPI *api.API) http.Handler {
http.NotFound(w, r)
return
} else if err != nil {
helper.Fail500(w, err)
helper.Fail500(w, fmt.Errorf("DownloadArtifact: %v", err))
}
}, "")
}
......@@ -29,7 +29,7 @@ func testArtifactDownloadServer(t *testing.T, archive string, entry string) *htt
Entry: base64.StdEncoding.EncodeToString([]byte(entry)),
})
if err != nil {
t.Fatal("Expected to marshal")
t.Fatal(err)
}
w.Write(data)
})
......@@ -69,7 +69,14 @@ func TestDownloadingFromValidArchive(t *testing.T) {
response := testDownloadArtifact(t, ts)
testhelper.AssertResponseCode(t, response, 200)
testhelper.AssertResponseHeader(t, response, "Content-Type", "text/plain; charset=utf-8")
testhelper.AssertResponseHeader(t, response,
"Content-Type",
"text/plain; charset=utf-8")
testhelper.AssertResponseHeader(t, response,
"Content-Disposition",
"attachment; filename=\"test.txt\"")
testhelper.AssertResponseBody(t, response, "testtest")
}
......
......@@ -12,18 +12,19 @@ import (
"os"
)
// The artifactsFormFilter allows to pass only the `file` as file in body
type artifactsUploadProcessor struct {
TempPath string
metadataFile string
}
func (a *artifactsUploadProcessor) ProcessFile(formName, fileName string, writer *multipart.Writer) error {
// ProcessFile for artifacts requires file form-data field name to eq `file`
if formName != "file" {
return fmt.Errorf("Invalid form field: %q", formName)
}
if a.metadataFile != "" {
return fmt.Errorf("Multiple files")
return fmt.Errorf("Artifacts request contains more than one file!")
}
// Create temporary file for metadata and store it's path
......
......@@ -71,7 +71,7 @@ func testArtifactsUploadServer(t *testing.T, tempPath string) *httptest.Server {
w.WriteHeader(404)
return
}
if !bytes.Contains(metadata, []byte(metadataHeader)) {
if !bytes.HasPrefix(metadata[4:], []byte(metadataHeader)) {
w.WriteHeader(400)
return
}
......
......@@ -75,11 +75,8 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
file.Close()
if filter != nil {
err = filter.ProcessFile(name, file.Name(), writer)
if err != nil {
return cleanup, err
}
if err := filter.ProcessFile(name, file.Name(), writer); err != nil {
return cleanup, err
}
} else {
np, err := writer.CreatePart(p.Header)
......@@ -92,11 +89,8 @@ func rewriteFormFilesFromMultipart(r *http.Request, writer *multipart.Writer, te
return cleanup, err
}
if filter != nil {
err = filter.ProcessField(name, writer)
if err != nil {
return cleanup, err
}
if err := filter.ProcessField(name, writer); err != nil {
return cleanup, err
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment