|
@ -1,7 +1,9 @@ |
|
|
package main |
|
|
package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"encoding/base64" |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
|
|
|
"fmt" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/http/httptest" |
|
|
"net/http/httptest" |
|
|
"testing" |
|
|
"testing" |
|
@ -34,9 +36,9 @@ func TestEndpointRoute(t *testing.T) { |
|
|
router := mux.NewRouter() |
|
|
router := mux.NewRouter() |
|
|
fs := storage.GetMemoryStorageProvider() |
|
|
fs := storage.GetMemoryStorageProvider() |
|
|
|
|
|
|
|
|
RegisterPipelineRoutes(router, []pipelines.IPipeline{data}, fs) |
|
|
|
|
|
|
|
|
RegisterRoutes(router, []pipelines.IPipeline{data}, fs) |
|
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/"+data.Slug, nil) |
|
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/pipelines/"+data.Slug, nil) |
|
|
responseRecorder := httptest.NewRecorder() |
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
router.ServeHTTP(responseRecorder, request) |
|
@ -49,7 +51,7 @@ func TestEndpointRoute(t *testing.T) { |
|
|
t.Run("Unregistered pipelines return 404", func(t *testing.T) { |
|
|
t.Run("Unregistered pipelines return 404", func(t *testing.T) { |
|
|
router := mux.NewRouter() |
|
|
router := mux.NewRouter() |
|
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/"+data.Slug, nil) |
|
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/pipelines/"+data.Slug, nil) |
|
|
responseRecorder := httptest.NewRecorder() |
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
router.ServeHTTP(responseRecorder, request) |
|
@ -57,3 +59,61 @@ func TestEndpointRoute(t *testing.T) { |
|
|
assert.Equal(t, 404, responseRecorder.Code) |
|
|
assert.Equal(t, 404, responseRecorder.Code) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestUploadRoute(t *testing.T) { |
|
|
|
|
|
t.Run("Test uploads missing multipart boundary", func(t *testing.T) { |
|
|
|
|
|
router := mux.NewRouter() |
|
|
|
|
|
fs := storage.GetMemoryStorageProvider() |
|
|
|
|
|
|
|
|
|
|
|
RegisterRoutes(router, []pipelines.IPipeline{pipelines.Pipeline{ |
|
|
|
|
|
Name: "", |
|
|
|
|
|
Slug: "", |
|
|
|
|
|
Type: 0, |
|
|
|
|
|
RemoveMetadata: false, |
|
|
|
|
|
Steps: []pipelines.Step{}, |
|
|
|
|
|
Output: struct { |
|
|
|
|
|
Format string `json:"format"` |
|
|
|
|
|
Quality int `json:"quality"` |
|
|
|
|
|
}{"jpeg", 10}, |
|
|
|
|
|
}}, fs) |
|
|
|
|
|
|
|
|
|
|
|
request, _ := http.NewRequest("POST", "/upload", nil) |
|
|
|
|
|
request.Header["Content-Type"] = []string{"multipart/form-data"} |
|
|
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, 0x1A6, responseRecorder.Code) |
|
|
|
|
|
str, _ := base64.StdEncoding.DecodeString("eyJlcnJvciI6Im5" + |
|
|
|
|
|
"vIG11bHRpcGFydCBib3VuZGFyeSBwYXJhbSBpbiBDb250ZW50LVR5cGUifQ==") |
|
|
|
|
|
assert.JSONEq(t, string(str), responseRecorder.Body.String()) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("Test uploads missing multipart boundary", func(t *testing.T) { |
|
|
|
|
|
router := mux.NewRouter() |
|
|
|
|
|
fs := storage.GetMemoryStorageProvider() |
|
|
|
|
|
|
|
|
|
|
|
RegisterRoutes(router, []pipelines.IPipeline{pipelines.Pipeline{ |
|
|
|
|
|
Name: "", |
|
|
|
|
|
Slug: "", |
|
|
|
|
|
Type: 0, |
|
|
|
|
|
RemoveMetadata: false, |
|
|
|
|
|
Steps: []pipelines.Step{}, |
|
|
|
|
|
Output: struct { |
|
|
|
|
|
Format string `json:"format"` |
|
|
|
|
|
Quality int `json:"quality"` |
|
|
|
|
|
}{"jpeg", 10}, |
|
|
|
|
|
}}, fs) |
|
|
|
|
|
|
|
|
|
|
|
request, _ := http.NewRequest("POST", "/upload", nil) |
|
|
|
|
|
request.Header["Content-Type"] = []string{"multipart/form-data", "boundary=X-INSOMNIA-BOUNDARY"} |
|
|
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, 0x1A6, responseRecorder.Code) |
|
|
|
|
|
str, _ := base64.StdEncoding.DecodeString("eyJlcnJvciI6Im5vIG11bHRpcGFydCBib3VuZGFyeSBwYXJhbSBpbiBDb250ZW50LVR5cGUifQ==") |
|
|
|
|
|
assert.JSONEq(t, string(str), responseRecorder.Body.String()) |
|
|
|
|
|
fmt.Println(responseRecorder.Body.String()) |
|
|
|
|
|
}) |
|
|
|
|
|
} |