Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
1
Merge Requests
1
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
gitlab-workhorse
Commits
fc9a8a29
Commit
fc9a8a29
authored
Aug 15, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for mustParseAddress
parent
10191b81
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
3 deletions
+43
-3
internal/badgateway/roundtripper.go
internal/badgateway/roundtripper.go
+7
-3
internal/badgateway/roundtripper_test.go
internal/badgateway/roundtripper_test.go
+36
-0
No files found.
internal/badgateway/roundtripper.go
View file @
fc9a8a29
...
...
@@ -53,16 +53,20 @@ func NewRoundTripper(backend *url.URL, socket string, proxyHeadersTimeout time.D
}
func
mustParseAddress
(
address
,
scheme
string
)
string
{
if
host
,
port
,
err
:=
net
.
SplitHostPort
(
address
);
err
==
nil
{
if
scheme
==
"https"
{
panic
(
"TLS is not supported for backend connections"
)
}
if
host
,
port
,
err
:=
net
.
SplitHostPort
(
address
);
err
==
nil
&&
host
!=
""
&&
port
!=
""
{
return
host
+
":"
+
port
}
address
=
address
+
":"
+
scheme
if
host
,
port
,
err
:=
net
.
SplitHostPort
(
address
);
err
==
nil
{
if
host
,
port
,
err
:=
net
.
SplitHostPort
(
address
);
err
==
nil
&&
host
!=
""
&&
port
!=
""
{
return
host
+
":"
+
port
}
panic
(
"could not parse host
/port from addres /
scheme"
)
panic
(
"could not parse host
:port from address and
scheme"
)
}
func
(
t
*
RoundTripper
)
RoundTrip
(
r
*
http
.
Request
)
(
res
*
http
.
Response
,
err
error
)
{
...
...
internal/badgateway/roundtripper_test.go
0 → 100644
View file @
fc9a8a29
package
badgateway
import
(
"log"
"testing"
)
func
TestMustParseAddress
(
t
*
testing
.
T
)
{
successExamples
:=
[]
struct
{
address
,
scheme
,
expected
string
}{
{
"1.2.3.4:56"
,
"http"
,
"1.2.3.4:56"
},
{
"[::1]:23"
,
"http"
,
"::1:23"
},
{
"4.5.6.7"
,
"http"
,
"4.5.6.7:http"
},
}
for
_
,
example
:=
range
successExamples
{
result
:=
mustParseAddress
(
example
.
address
,
example
.
scheme
)
if
example
.
expected
!=
result
{
t
.
Errorf
(
"expected %q, got %q"
,
example
.
expected
,
result
)
}
}
panicExamples
:=
[]
struct
{
address
,
scheme
string
}{
{
"1.2.3.4"
,
""
},
{
"1.2.3.4"
,
"https"
},
}
for
_
,
panicExample
:=
range
panicExamples
{
func
()
{
defer
func
()
{
if
r
:=
recover
();
r
==
nil
{
t
.
Errorf
(
"expected panic for %v but none occurred"
,
panicExample
)
}
}()
log
.
Print
(
mustParseAddress
(
panicExample
.
address
,
panicExample
.
scheme
))
}()
}
}
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