Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
a78cea7d
Commit
a78cea7d
authored
Jun 24, 2015
by
Karthic Rao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test for webSocketParse function in config/setup
parent
7044cbbd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
2 deletions
+51
-2
config/setup/websocket.go
config/setup/websocket.go
+2
-2
config/setup/websocket_test.go
config/setup/websocket_test.go
+49
-0
No files found.
config/setup/websocket.go
View file @
a78cea7d
...
...
@@ -8,7 +8,7 @@ import (
// WebSocket configures a new WebSockets middleware instance.
func
WebSocket
(
c
*
Controller
)
(
middleware
.
Middleware
,
error
)
{
websocks
,
err
:=
web
s
ocketParse
(
c
)
websocks
,
err
:=
web
S
ocketParse
(
c
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -20,7 +20,7 @@ func WebSocket(c *Controller) (middleware.Middleware, error) {
},
nil
}
func
web
s
ocketParse
(
c
*
Controller
)
([]
websockets
.
Config
,
error
)
{
func
web
S
ocketParse
(
c
*
Controller
)
([]
websockets
.
Config
,
error
)
{
var
websocks
[]
websockets
.
Config
var
respawn
bool
...
...
config/setup/websocket_test.go
View file @
a78cea7d
...
...
@@ -34,3 +34,52 @@ func TestWebSocket(t *testing.T) {
}
}
func
TestWebSocketParse
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
inputWebSocketConfig
string
shouldErr
bool
expectedWebSocketConfig
[]
websockets
.
Config
}{
{
`websocket /api1 cat`
,
false
,
[]
websockets
.
Config
{{
Path
:
"/api1"
,
Command
:
"cat"
,
}}},
{
`websocket /api3 cat
websocket /api4 cat `
,
false
,
[]
websockets
.
Config
{{
Path
:
"/api3"
,
Command
:
"cat"
,
},
{
Path
:
"/api4"
,
Command
:
"cat"
,
}}},
}
for
i
,
test
:=
range
tests
{
c
:=
NewTestController
(
test
.
inputWebSocketConfig
)
actualWebSocketConfigs
,
err
:=
webSocketParse
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
t
.
Errorf
(
"Test %d didn't error, but it should have"
,
i
)
}
else
if
err
!=
nil
&&
!
test
.
shouldErr
{
t
.
Errorf
(
"Test %d errored, but it shouldn't have; got '%v'"
,
i
,
err
)
}
if
len
(
actualWebSocketConfigs
)
!=
len
(
test
.
expectedWebSocketConfig
)
{
t
.
Fatalf
(
"Test %d expected %d no of WebSocket configs, but got %d "
,
i
,
len
(
test
.
expectedWebSocketConfig
),
len
(
actualWebSocketConfigs
))
}
for
j
,
actualWebSocketConfig
:=
range
actualWebSocketConfigs
{
if
actualWebSocketConfig
.
Path
!=
test
.
expectedWebSocketConfig
[
j
]
.
Path
{
t
.
Errorf
(
"Test %d expected %dth WebSocket Config Path to be %s , but got %s"
,
i
,
j
,
test
.
expectedWebSocketConfig
[
j
]
.
Path
,
actualWebSocketConfig
.
Path
)
}
if
actualWebSocketConfig
.
Command
!=
test
.
expectedWebSocketConfig
[
j
]
.
Command
{
t
.
Errorf
(
"Test %d expected %dth WebSocket Config Command to be %s , but got %s"
,
i
,
j
,
test
.
expectedWebSocketConfig
[
j
]
.
Command
,
actualWebSocketConfig
.
Command
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment