|
|
|
|
@@ -35,8 +35,29 @@ func TestFiles(t *testing.T) {
|
|
|
|
|
t.Logf("config: %+v", config.New())
|
|
|
|
|
handler := jsonHandler(storage.Graph{})
|
|
|
|
|
|
|
|
|
|
prefix := path.Join(config.New().FilePrefix, "col")
|
|
|
|
|
qparam := "namespace=col"
|
|
|
|
|
|
|
|
|
|
t.Run("bad qparam doesnt have namespace", func(t *testing.T) {
|
|
|
|
|
r := httptest.NewRequest(http.MethodGet, fmt.Sprintf("%s/fake", prefix), nil)
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
if w.Code != http.StatusBadRequest {
|
|
|
|
|
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("bad prefix doesnt have namespace", func(t *testing.T) {
|
|
|
|
|
r := httptest.NewRequest(http.MethodGet, fmt.Sprintf("%s/fake?%s", config.New().FilePrefix, qparam), nil)
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
if w.Code != http.StatusNotFound {
|
|
|
|
|
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("get fake file 404", func(t *testing.T) {
|
|
|
|
|
r := httptest.NewRequest(http.MethodGet, fmt.Sprintf("%s/fake", config.New().FilePrefix), nil)
|
|
|
|
|
r := httptest.NewRequest(http.MethodGet, fmt.Sprintf("%s/fake?%s", prefix, qparam), nil)
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
if w.Code != http.StatusNotFound {
|
|
|
|
|
@@ -61,7 +82,7 @@ func TestFiles(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
f.Write([]byte("hello, world"))
|
|
|
|
|
f.Close()
|
|
|
|
|
r := httptest.NewRequest(http.MethodGet, fmt.Sprintf("%s?direct=true", path.Join(config.New().FilePrefix, path.Base(f.Name()))), nil)
|
|
|
|
|
r := httptest.NewRequest(http.MethodGet, fmt.Sprintf("%s?direct=true&%s", path.Join(prefix, path.Base(f.Name())), qparam), nil)
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
t.Logf("URL = %q", r.URL.String())
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
@@ -92,14 +113,14 @@ func TestFiles(t *testing.T) {
|
|
|
|
|
}))
|
|
|
|
|
defer s.Close()
|
|
|
|
|
|
|
|
|
|
r := httptest.NewRequest(http.MethodPost, fmt.Sprintf("%s?direct=true", path.Join(config.New().FilePrefix, name)), strings.NewReader(s.URL))
|
|
|
|
|
r := httptest.NewRequest(http.MethodPost, fmt.Sprintf("%s?direct=true&%s", path.Join(prefix, name), qparam), strings.NewReader(s.URL))
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
if w.Code != http.StatusOK {
|
|
|
|
|
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r = httptest.NewRequest(http.MethodGet, path.Join(config.New().FilePrefix, name), nil)
|
|
|
|
|
r = httptest.NewRequest(http.MethodGet, path.Join(prefix, name)+"?"+qparam, nil)
|
|
|
|
|
w = httptest.NewRecorder()
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
if w.Code != http.StatusOK {
|
|
|
|
|
@@ -118,7 +139,7 @@ func TestFiles(t *testing.T) {
|
|
|
|
|
f.Write([]byte("hello, world"))
|
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
|
|
r := httptest.NewRequest(http.MethodPost, path.Join(config.New().FilePrefix, path.Base(f.Name())), strings.NewReader(`bad link teehee`))
|
|
|
|
|
r := httptest.NewRequest(http.MethodPost, path.Join(prefix, path.Base(f.Name()))+"?"+qparam, strings.NewReader(`bad link teehee`))
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
if w.Code == http.StatusOK {
|
|
|
|
|
@@ -139,7 +160,7 @@ func TestFiles(t *testing.T) {
|
|
|
|
|
w2.Write([]byte("hello, world"))
|
|
|
|
|
writer.Close()
|
|
|
|
|
|
|
|
|
|
r := httptest.NewRequest(http.MethodPost, path.Join(config.New().FilePrefix, name), b)
|
|
|
|
|
r := httptest.NewRequest(http.MethodPost, path.Join(prefix, name)+"?"+qparam, b)
|
|
|
|
|
r.Header.Set("Content-Type", writer.FormDataContentType())
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
@@ -147,7 +168,7 @@ func TestFiles(t *testing.T) {
|
|
|
|
|
t.Fatalf("%d: %s", w.Code, w.Body.Bytes())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r = httptest.NewRequest(http.MethodGet, path.Join(config.New().FilePrefix, name), nil)
|
|
|
|
|
r = httptest.NewRequest(http.MethodGet, path.Join(prefix, name)+"?"+qparam, nil)
|
|
|
|
|
w = httptest.NewRecorder()
|
|
|
|
|
handler.ServeHTTP(w, r)
|
|
|
|
|
if w.Code != http.StatusOK {
|
|
|
|
|
|