mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 11:57:02 +00:00
add a test example for upload files as requested at: #1516
Former-commit-id: afb2d3e9c0902cce6c46d26b5b6cfc51551c2373
This commit is contained in:
32
_examples/http_request/upload-files/main_test.go
Normal file
32
_examples/http_request/upload-files/main_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12/httptest"
|
||||
)
|
||||
|
||||
func TestUploadFiles(t *testing.T) {
|
||||
app := newApp()
|
||||
e := httptest.New(t, app)
|
||||
|
||||
// upload the file itself.
|
||||
fh, err := os.Open("main.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer fh.Close()
|
||||
|
||||
e.POST("/upload").WithMultipart().WithFile("files", "main.go", fh).
|
||||
Expect().Status(http.StatusOK)
|
||||
|
||||
f, err := os.Open("uploads/main.go")
|
||||
if err != nil {
|
||||
t.Fatalf("expected file to get actually uploaded on the system directory but: %v", err)
|
||||
}
|
||||
f.Close()
|
||||
|
||||
os.Remove(f.Name())
|
||||
}
|
||||
Reference in New Issue
Block a user