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
b10d8460
Commit
b10d8460
authored
May 21, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More parser tests
parent
11ddb5c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
9 deletions
+101
-9
config/parse/parsing_test.go
config/parse/parsing_test.go
+101
-9
No files found.
config/parse/parsing_test.go
View file @
b10d8460
package
parse
import
(
"reflect"
"strings"
"testing"
)
...
...
@@ -57,20 +58,15 @@ func TestStandardAddress(t *testing.T) {
}
func
TestParseOne
(
t
*
testing
.
T
)
{
testParseOne
:=
func
(
input
string
,
shouldErr
bool
)
(
multiServerBlock
,
error
)
{
setupParseTests
()
testParseOne
:=
func
(
input
string
)
(
multiServerBlock
,
error
)
{
p
:=
testParser
(
input
)
p
.
Next
()
err
:=
p
.
parseOne
()
return
p
.
block
,
err
}
// Set up some bogus directives for testing
ValidDirectives
=
map
[
string
]
struct
{}{
"dir1"
:
struct
{}{},
"dir2"
:
struct
{}{},
"dir3"
:
struct
{}{},
}
for
i
,
test
:=
range
[]
struct
{
input
string
shouldErr
bool
...
...
@@ -223,7 +219,7 @@ func TestParseOne(t *testing.T) {
{
``
,
false
,
[]
address
{},
map
[
string
]
int
{}},
}
{
result
,
err
:=
testParseOne
(
test
.
input
,
test
.
shouldErr
)
result
,
err
:=
testParseOne
(
test
.
input
)
if
test
.
shouldErr
&&
err
==
nil
{
t
.
Errorf
(
"Test %d: Expected an error, but didn't get one"
,
i
)
...
...
@@ -261,7 +257,103 @@ func TestParseOne(t *testing.T) {
}
}
}
}
func
TestParseAll
(
t
*
testing
.
T
)
{
setupParseTests
()
for
i
,
test
:=
range
[]
struct
{
input
string
shouldErr
bool
addresses
[]
address
// one per expected server block, in order
}{
{
`localhost`
,
false
,
[]
address
{
{
"localhost"
,
""
},
}},
{
`localhost:1234`
,
false
,
[]
address
{
{
"localhost"
,
"1234"
},
}},
{
`localhost:1234 {
}
localhost:2015 {
}`
,
false
,
[]
address
{
{
"localhost"
,
"1234"
},
{
"localhost"
,
"2015"
},
}},
{
`localhost:1234, http://host2`
,
false
,
[]
address
{
{
"localhost"
,
"1234"
},
{
"host2"
,
"http"
},
}},
{
`http://host1.com, http://host2.com {
}
https://host3.com, https://host4.com {
}`
,
false
,
[]
address
{
{
"host1.com"
,
"http"
},
{
"host2.com"
,
"http"
},
{
"host3.com"
,
"https"
},
{
"host4.com"
,
"https"
},
}},
}
{
p
:=
testParser
(
test
.
input
)
blocks
,
err
:=
p
.
parseAll
()
if
test
.
shouldErr
&&
err
==
nil
{
t
.
Errorf
(
"Test %d: Expected an error, but didn't get one"
,
i
)
}
if
!
test
.
shouldErr
&&
err
!=
nil
{
t
.
Errorf
(
"Test %d: Expected no error, but got: %v"
,
i
,
err
)
}
if
len
(
blocks
)
!=
len
(
test
.
addresses
)
{
t
.
Errorf
(
"Test %d: Expected %d server blocks, got %d"
,
i
,
len
(
test
.
addresses
),
len
(
blocks
))
continue
}
for
j
,
block
:=
range
blocks
{
if
block
.
Host
!=
test
.
addresses
[
j
]
.
host
{
t
.
Errorf
(
"Test %d, block %d: Expected host to be '%s', but was '%s'"
,
i
,
j
,
test
.
addresses
[
j
]
.
host
,
block
.
Host
)
}
if
block
.
Port
!=
test
.
addresses
[
j
]
.
port
{
t
.
Errorf
(
"Test %d, block %d: Expected port to be '%s', but was '%s'"
,
i
,
j
,
test
.
addresses
[
j
]
.
port
,
block
.
Port
)
}
}
}
// Exploding the server blocks that have more than one address should replicate/share tokens
p
:=
testParser
(
`host1 {
dir1 foo bar
}
host2, host3 {
dir2 foo bar
dir3 foo {
bar
}
}`
)
blocks
,
err
:=
p
.
parseAll
()
if
err
!=
nil
{
t
.
Fatal
(
"Expected there to not be an error, but there was: %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
blocks
[
1
]
.
Tokens
,
blocks
[
2
]
.
Tokens
)
{
t
.
Errorf
(
"Expected host2 and host3 to have same tokens, but they didn't.
\n
host2 Block: %v
\n
host3 Block: %v"
,
blocks
[
1
]
.
Tokens
,
blocks
[
2
]
.
Tokens
)
}
}
func
setupParseTests
()
{
// Set up some bogus directives for testing
ValidDirectives
=
map
[
string
]
struct
{}{
"dir1"
:
struct
{}{},
"dir2"
:
struct
{}{},
"dir3"
:
struct
{}{},
}
}
func
testParser
(
input
string
)
parser
{
...
...
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