Commit 7044cbbd authored by Matt Holt's avatar Matt Holt

Merge pull request #161 from Karthic-Hackintosh/master

Modularizing config/setup/Websocket.go and test file for the same
parents 06a7f1d3 292c15cd
......@@ -7,6 +7,20 @@ import (
// WebSocket configures a new WebSockets middleware instance.
func WebSocket(c *Controller) (middleware.Middleware, error) {
websocks, err := websocketParse(c)
if err != nil {
return nil, err
}
websockets.GatewayInterface = c.AppName + "-CGI/1.1"
websockets.ServerSoftware = c.AppName + "/" + c.AppVersion
return func(next middleware.Handler) middleware.Handler {
return websockets.WebSockets{Next: next, Sockets: websocks}
}, nil
}
func websocketParse(c *Controller) ([]websockets.Config, error) {
var websocks []websockets.Config
var respawn bool
......@@ -68,10 +82,6 @@ func WebSocket(c *Controller) (middleware.Middleware, error) {
})
}
websockets.GatewayInterface = c.AppName + "-CGI/1.1"
websockets.ServerSoftware = c.AppName + "/" + c.AppVersion
return websocks, nil
return func(next middleware.Handler) middleware.Handler {
return websockets.WebSockets{Next: next, Sockets: websocks}
}, nil
}
package setup
import (
"github.com/mholt/caddy/middleware/websockets"
"testing"
)
func TestWebSocket(t *testing.T) {
c := NewTestController(`websocket cat`)
mid, err := WebSocket(c)
if err != nil {
t.Errorf("Expected no errors, got: %v", err)
}
if mid == nil {
t.Fatal("Expected middleware, was nil instead")
}
handler := mid(EmptyNext)
myHandler, ok := handler.(websockets.WebSockets)
if !ok {
t.Fatalf("Expected handler to be type WebSockets, got: %#v", handler)
}
if myHandler.Sockets[0].Path != "/" {
t.Errorf("Expected / as the default Path")
}
if myHandler.Sockets[0].Command != "cat" {
t.Errorf("Expected %s as the command", "cat")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment