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
b37fed4c
Commit
b37fed4c
authored
May 21, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Beginning some tests for the parser
parent
5397eef2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
7 deletions
+66
-7
config/parse/parsing.go
config/parse/parsing.go
+12
-7
config/parse/parsing_test.go
config/parse/parsing_test.go
+54
-0
No files found.
config/parse/parsing.go
View file @
b37fed4c
...
@@ -257,7 +257,7 @@ func (p *parser) closeCurlyBrace() error {
...
@@ -257,7 +257,7 @@ func (p *parser) closeCurlyBrace() error {
// standardAddress turns the accepted host and port patterns
// standardAddress turns the accepted host and port patterns
// into a format accepted by net.Dial.
// into a format accepted by net.Dial.
func
standardAddress
(
str
string
)
(
host
,
port
string
,
err
error
)
{
func
standardAddress
(
str
string
)
(
host
,
port
string
,
err
error
)
{
var
schemePort
string
var
schemePort
,
splitPort
string
if
strings
.
HasPrefix
(
str
,
"https://"
)
{
if
strings
.
HasPrefix
(
str
,
"https://"
)
{
schemePort
=
"https"
schemePort
=
"https"
...
@@ -267,14 +267,19 @@ func standardAddress(str string) (host, port string, err error) {
...
@@ -267,14 +267,19 @@ func standardAddress(str string) (host, port string, err error) {
str
=
str
[
7
:
]
str
=
str
[
7
:
]
}
}
host
,
p
ort
,
err
=
net
.
SplitHostPort
(
str
)
host
,
splitP
ort
,
err
=
net
.
SplitHostPort
(
str
)
if
err
!=
nil
&&
schemePort
==
""
{
if
err
!=
nil
{
host
,
p
ort
,
err
=
net
.
SplitHostPort
(
str
+
":"
)
// tack on empty port
host
,
splitP
ort
,
err
=
net
.
SplitHostPort
(
str
+
":"
)
// tack on empty port
}
}
if
err
!=
nil
&&
schemePort
!=
""
{
if
err
!=
nil
{
// ¯\_(ツ)_/¯
host
=
str
host
=
str
port
=
schemePort
// assume port from scheme
}
err
=
nil
if
splitPort
!=
""
{
port
=
splitPort
}
else
{
port
=
schemePort
}
}
return
return
...
...
config/parse/parsing_test.go
0 → 100644
View file @
b37fed4c
package
parse
import
"testing"
func
TestStandardAddress
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
[]
struct
{
input
string
host
,
port
string
shouldErr
bool
}{
{
`localhost`
,
"localhost"
,
""
,
false
},
{
`localhost:1234`
,
"localhost"
,
"1234"
,
false
},
{
`localhost:`
,
"localhost"
,
""
,
false
},
{
`0.0.0.0`
,
"0.0.0.0"
,
""
,
false
},
{
`127.0.0.1:1234`
,
"127.0.0.1"
,
"1234"
,
false
},
{
`:1234`
,
""
,
"1234"
,
false
},
{
`[::1]`
,
"::1"
,
""
,
false
},
{
`[::1]:1234`
,
"::1"
,
"1234"
,
false
},
{
`:`
,
""
,
""
,
false
},
{
`localhost:http`
,
"localhost"
,
"http"
,
false
},
{
`localhost:https`
,
"localhost"
,
"https"
,
false
},
{
`:http`
,
""
,
"http"
,
false
},
{
`:https`
,
""
,
"https"
,
false
},
{
`http://localhost`
,
"localhost"
,
"http"
,
false
},
{
`https://localhost`
,
"localhost"
,
"https"
,
false
},
{
`http://127.0.0.1`
,
"127.0.0.1"
,
"http"
,
false
},
{
`https://127.0.0.1`
,
"127.0.0.1"
,
"https"
,
false
},
{
`http://[::1]`
,
"::1"
,
"http"
,
false
},
{
`http://localhost:1234`
,
"localhost"
,
"1234"
,
false
},
{
`https://127.0.0.1:1234`
,
"127.0.0.1"
,
"1234"
,
false
},
{
`http://[::1]:1234`
,
"::1"
,
"1234"
,
false
},
{
``
,
""
,
""
,
false
},
{
`::1`
,
"::1"
,
""
,
true
},
{
`localhost::`
,
"localhost::"
,
""
,
true
},
{
`#$%@`
,
"#$%@"
,
""
,
true
},
}
{
host
,
port
,
err
:=
standardAddress
(
test
.
input
)
if
err
!=
nil
&&
!
test
.
shouldErr
{
t
.
Errorf
(
"Test %d: Expected no error, but had error: %v"
,
i
,
err
)
}
if
err
==
nil
&&
test
.
shouldErr
{
t
.
Errorf
(
"Test %d: Expected error, but had none"
,
i
)
}
if
host
!=
test
.
host
{
t
.
Errorf
(
"Test %d: Expected host '%s', got '%s'"
,
i
,
test
.
host
,
host
)
}
if
port
!=
test
.
port
{
t
.
Errorf
(
"Test %d: Expected port '%s', got '%s'"
,
i
,
test
.
port
,
port
)
}
}
}
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