35 lines
916 B
Go
35 lines
916 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A terminal opened with a folder asks the agent to start there; a folder
|
|
// that is not an absolute path is left out (the shell starts at home).
|
|
func TestPanelOpenDir(t *testing.T) {
|
|
s, cookie := newTestServer(t)
|
|
for body, want := range map[string]string{
|
|
`{"dir":"/srv/my app"}`: "/srv/my app",
|
|
`{"dir":"relative"}`: "",
|
|
``: "",
|
|
} {
|
|
req := httptest.NewRequest(http.MethodPost, "/api/panel/term/x1/open", strings.NewReader(body))
|
|
req.AddCookie(cookie)
|
|
w := httptest.NewRecorder()
|
|
s.Handler().ServeHTTP(w, req)
|
|
if w.Code != 200 {
|
|
t.Fatalf("%s: code %d %s", body, w.Code, w.Body)
|
|
}
|
|
s.hub.mu.Lock()
|
|
jobs := s.hub.jobs["x1"]
|
|
s.hub.jobs["x1"] = nil
|
|
s.hub.mu.Unlock()
|
|
if len(jobs) != 1 || jobs[0].Dir != want {
|
|
t.Fatalf("%s: jobs %+v, want dir %q", body, jobs, want)
|
|
}
|
|
}
|
|
}
|