2020-02-26 17:50:28 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2020-06-22 15:16:26 +02:00
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
|
2020-02-26 17:50:28 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetFile(t *testing.T) {
|
|
|
|
t.Run("search for existing file", func(t *testing.T) {
|
2020-06-25 14:54:04 +02:00
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
GetFile(router)
|
2020-05-04 14:40:58 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/files/2cad9168fa6acc5c5c2965ddf6ec465ca42fd818")
|
|
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
2020-05-01 14:15:15 +02:00
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
val := gjson.Get(r.Body.String(), "Name")
|
2021-08-05 12:33:52 +02:00
|
|
|
assert.Equal(t, "2790/07/27900704_070228_D6D51B6C.jpg", val.String())
|
2020-02-26 17:50:28 +01:00
|
|
|
})
|
|
|
|
t.Run("search for not existing file", func(t *testing.T) {
|
2020-06-25 14:54:04 +02:00
|
|
|
app, router, _ := NewApiTest()
|
|
|
|
GetFile(router)
|
2020-05-04 14:40:58 +02:00
|
|
|
r := PerformRequest(app, "GET", "/api/v1/files/111")
|
|
|
|
assert.Equal(t, http.StatusNotFound, r.Code)
|
2020-02-26 17:50:28 +01:00
|
|
|
})
|
|
|
|
}
|