|
|
@ -3,11 +3,12 @@ package main |
|
|
|
import ( |
|
|
|
"encoding/base64" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"github.com/geplauder/lithium/controllers" |
|
|
|
"net/http" |
|
|
|
"net/http/httptest" |
|
|
|
"testing" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/geplauder/lithium/controllers" |
|
|
|
|
|
|
|
"github.com/bxcodec/faker/v3" |
|
|
|
"github.com/geplauder/lithium/pipelines" |
|
|
@ -139,6 +140,39 @@ func TestUploadRoute(t *testing.T) { |
|
|
|
assert.Equal(t, 0x1A6, responseRecorder.Code) |
|
|
|
str, _ := base64.StdEncoding.DecodeString("eyJlcnJvciI6Im5vIG11bHRpcGFydCBib3VuZGFyeSBwYXJhbSBpbiBDb250ZW50LVR5cGUifQ==") |
|
|
|
assert.JSONEq(t, string(str), responseRecorder.Body.String()) |
|
|
|
fmt.Println(responseRecorder.Body.String()) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
func TestFilesRoute(t *testing.T) { |
|
|
|
data := pipelines.Pipeline{} |
|
|
|
err := faker.FakeData(&data) |
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
t.Run("Files endpoint returns files", func(t *testing.T) { |
|
|
|
router := mux.NewRouter() |
|
|
|
fs := storage.GetMemoryStorageProvider() |
|
|
|
appSettings, _ := settings.LoadSettings(afero.NewMemMapFs()) |
|
|
|
|
|
|
|
RegisterRoutes(router, appSettings, []pipelines.IPipeline{data}, fs) |
|
|
|
|
|
|
|
request, _ := http.NewRequest("GET", "/files", nil) |
|
|
|
responseRecorder := httptest.NewRecorder() |
|
|
|
|
|
|
|
router.ServeHTTP(responseRecorder, request) |
|
|
|
|
|
|
|
type responseBody struct { |
|
|
|
Files []struct { |
|
|
|
Bucket string `json:"bucket"` |
|
|
|
FileName string `json:"file_name"` |
|
|
|
Size int `json:"size"` |
|
|
|
ModifiedAt time.Time `json:"modified_at"` |
|
|
|
} `json:"files"` |
|
|
|
} |
|
|
|
|
|
|
|
var res responseBody |
|
|
|
|
|
|
|
assert.Equal(t, 200, responseRecorder.Code) |
|
|
|
err := json.Unmarshal(responseRecorder.Body.Bytes(), &res) |
|
|
|
assert.Nil(t, err) |
|
|
|
}) |
|
|
|
} |