2016-01-13 19:19:45 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-01-14 23:07:24 +00:00
|
|
|
func TestAllocDirFS_List_MissingParams(t *testing.T) {
|
2016-01-13 19:19:45 +00:00
|
|
|
httpTest(t, nil, func(s *TestServer) {
|
2016-01-13 19:49:39 +00:00
|
|
|
req, err := http.NewRequest("GET", "/v1/client/fs/ls/", nil)
|
2016-01-13 19:19:45 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
respW := httptest.NewRecorder()
|
|
|
|
|
|
|
|
_, err = s.Server.DirectoryListRequest(respW, req)
|
2016-01-13 19:49:39 +00:00
|
|
|
if err != allocIDNotPresentErr {
|
|
|
|
t.Fatalf("expected err: %v, actual: %v", allocIDNotPresentErr, err)
|
2016-01-13 19:19:45 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-14 23:07:24 +00:00
|
|
|
func TestAllocDirFS_Stat_MissingParams(t *testing.T) {
|
2016-01-13 19:19:45 +00:00
|
|
|
httpTest(t, nil, func(s *TestServer) {
|
|
|
|
req, err := http.NewRequest("GET", "/v1/client/fs/stat/", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
respW := httptest.NewRecorder()
|
|
|
|
|
|
|
|
_, err = s.Server.FileStatRequest(respW, req)
|
2016-01-13 19:49:39 +00:00
|
|
|
if err != allocIDNotPresentErr {
|
|
|
|
t.Fatalf("expected err: %v, actual: %v", allocIDNotPresentErr, err)
|
2016-01-13 19:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
req, err = http.NewRequest("GET", "/v1/client/fs/stat/foo", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
respW = httptest.NewRecorder()
|
|
|
|
|
|
|
|
_, err = s.Server.FileStatRequest(respW, req)
|
2016-01-13 19:49:39 +00:00
|
|
|
if err != fileNameNotPresentErr {
|
|
|
|
t.Fatalf("expected err: %v, actual: %v", allocIDNotPresentErr, err)
|
2016-01-13 19:37:29 +00:00
|
|
|
}
|
2016-01-13 19:49:39 +00:00
|
|
|
|
2016-01-13 19:37:29 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-14 23:07:24 +00:00
|
|
|
func TestAllocDirFS_ReadAt_MissingParams(t *testing.T) {
|
2016-01-13 19:37:29 +00:00
|
|
|
httpTest(t, nil, func(s *TestServer) {
|
|
|
|
req, err := http.NewRequest("GET", "/v1/client/fs/readat/", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
respW := httptest.NewRecorder()
|
|
|
|
|
|
|
|
_, err = s.Server.FileReadAtRequest(respW, req)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err = http.NewRequest("GET", "/v1/client/fs/readat/foo", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
respW = httptest.NewRecorder()
|
|
|
|
|
|
|
|
_, err = s.Server.FileReadAtRequest(respW, req)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err = http.NewRequest("GET", "/v1/client/fs/readat/foo?path=/path/to/file", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
respW = httptest.NewRecorder()
|
|
|
|
|
|
|
|
_, err = s.Server.FileReadAtRequest(respW, req)
|
2016-01-13 19:19:45 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|