Changed assets endpoint to multipart
This commit is contained in:
@@ -3,7 +3,9 @@ package api
|
||||
import (
|
||||
"TheAdversary/database"
|
||||
"TheAdversary/schema"
|
||||
"encoding/base64"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -31,6 +33,13 @@ func TestAssetsGet(t *testing.T) {
|
||||
checkTestInformation(t, server.URL, []testInformation{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Code: http.StatusUnauthorized,
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Cookie: map[string]string{
|
||||
"session_id": initSession(),
|
||||
},
|
||||
Query: map[string]interface{}{
|
||||
"q": "linux",
|
||||
},
|
||||
@@ -45,6 +54,9 @@ func TestAssetsGet(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Cookie: map[string]string{
|
||||
"session_id": initSession(),
|
||||
},
|
||||
Query: map[string]interface{}{
|
||||
"limit": 1,
|
||||
},
|
||||
@@ -59,6 +71,9 @@ func TestAssetsGet(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Cookie: map[string]string{
|
||||
"session_id": initSession(),
|
||||
},
|
||||
ResultBody: []schema.Asset{
|
||||
{
|
||||
Id: 1,
|
||||
@@ -81,27 +96,47 @@ func TestAssetsPost(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
mw := multipart.NewWriter(&buf)
|
||||
mw.SetBoundary("test")
|
||||
formFile, _ := mw.CreateFormFile("file", "srfwsr")
|
||||
formFile.Write([]byte("just a test file"))
|
||||
mw.WriteField("name", "test")
|
||||
mw.Close()
|
||||
|
||||
fmt.Println(buf.String())
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(assetsPost))
|
||||
checkTestInformation(t, server.URL, []testInformation{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Body: assetsPostPayload{
|
||||
Name: "test",
|
||||
Content: base64.StdEncoding.EncodeToString([]byte("test asset")),
|
||||
Code: http.StatusUnauthorized,
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Header: map[string]string{
|
||||
"Content-Type": "multipart/form-data; boundary=test",
|
||||
},
|
||||
Cookie: map[string]string{
|
||||
"session_id": initSession(),
|
||||
},
|
||||
Body: buf.Bytes(),
|
||||
ResultBody: schema.Asset{
|
||||
Id: 1,
|
||||
Name: "test",
|
||||
Link: "/assets/test",
|
||||
},
|
||||
Code: http.StatusOK,
|
||||
Code: http.StatusCreated,
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Body: assetsPostPayload{
|
||||
Name: "test",
|
||||
Content: base64.StdEncoding.EncodeToString([]byte("test asset")),
|
||||
Header: map[string]string{
|
||||
"Content-Type": "multipart/form-data; boundary=test",
|
||||
},
|
||||
Cookie: map[string]string{
|
||||
"session_id": initSession(),
|
||||
},
|
||||
Body: buf.Bytes(),
|
||||
Code: http.StatusConflict,
|
||||
},
|
||||
})
|
||||
@@ -122,6 +157,13 @@ func TestAssetsDelete(t *testing.T) {
|
||||
checkTestInformation(t, server.URL, []testInformation{
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Code: http.StatusUnauthorized,
|
||||
},
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Cookie: map[string]string{
|
||||
"session_id": initSession(),
|
||||
},
|
||||
Body: assetsDeletePayload{
|
||||
Id: 1,
|
||||
},
|
||||
@@ -129,6 +171,9 @@ func TestAssetsDelete(t *testing.T) {
|
||||
},
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Cookie: map[string]string{
|
||||
"session_id": initSession(),
|
||||
},
|
||||
Body: assetsDeletePayload{
|
||||
Id: 69,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user