open-nomad/command/agent/fs_endpoint_test.go

87 lines
2.0 KiB
Go
Raw Normal View History

2016-01-13 19:19:45 +00:00
package agent
import (
"net/http"
"net/http/httptest"
"testing"
)
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
}
})
}
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:49:39 +00:00
})
}
func TestAllocDirFS_ReadAt_MissingParams(t *testing.T) {
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")
}
})
}