mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
- Add store of pipes in the app - Add pipe type, handling impedance mismatch, used in app and probe. - App <-> Probe pipes have their own websockets. - Add pipe websocket endpoint in app. - Pipe IDs are strings, lose the request/response IDs, and give the json encoder lowercase field names. - Add simple golang ws client, for testing. - Pipe lifecycle plumbing. - Ref count and timeout both ends of pipes in the app - Deal with POST /api/pipe/:pid?_method=delete - Add end-to-end unit test for pipes. - Add test for timing out pipes. - Update go-docker client to tomwilkie/go-dockerclient - Backend work for non-raw ttys - Close pipes when they close themselves in the probe - Ensure all http connections are done before returning from client.Stop()
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package app_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/weaveworks/scope/app"
|
|
"github.com/weaveworks/scope/xfer"
|
|
)
|
|
|
|
func TestControl(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
app.RegisterControlRoutes(router)
|
|
server := httptest.NewServer(router)
|
|
defer server.Close()
|
|
|
|
ip, port, err := net.SplitHostPort(strings.TrimPrefix(server.URL, "http://"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
probeConfig := xfer.ProbeConfig{
|
|
ProbeID: "foo",
|
|
}
|
|
controlHandler := xfer.ControlHandlerFunc(func(req xfer.Request) xfer.Response {
|
|
if req.NodeID != "nodeid" {
|
|
t.Fatalf("'%s' != 'nodeid'", req.NodeID)
|
|
}
|
|
|
|
if req.Control != "control" {
|
|
t.Fatalf("'%s' != 'control'", req.Control)
|
|
}
|
|
|
|
return xfer.Response{
|
|
Value: "foo",
|
|
}
|
|
})
|
|
client, err := xfer.NewAppClient(probeConfig, ip+":"+port, ip+":"+port, controlHandler)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
client.ControlConnection()
|
|
defer client.Stop()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
httpClient := http.Client{
|
|
Timeout: 1 * time.Second,
|
|
}
|
|
resp, err := httpClient.Post(server.URL+"/api/control/foo/nodeid/control", "", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var response xfer.Response
|
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if response.Value != "foo" {
|
|
t.Fatalf("'%s' != 'foo'", response.Value)
|
|
}
|
|
}
|