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
e166ebf6
Commit
e166ebf6
authored
Nov 14, 2015
by
Michael Banzon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test for environment replacement.
Added test for the fix of issue #304
parent
8774c907
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
caddy/parse/parsing_test.go
caddy/parse/parsing_test.go
+60
-0
No files found.
caddy/parse/parsing_test.go
View file @
e166ebf6
package
parse
import
(
"os"
"strings"
"testing"
)
...
...
@@ -364,6 +365,65 @@ func TestParseAll(t *testing.T) {
}
}
func
TestEnvironmentReplacement
(
t
*
testing
.
T
)
{
setupParseTests
()
os
.
Setenv
(
"MY_PORT"
,
"8080"
)
os
.
Setenv
(
"MY_ADDRESS"
,
"servername.com"
)
os
.
Setenv
(
"MY_ADDRESS2"
,
"127.0.0.1"
)
for
i
,
test
:=
range
[]
struct
{
input
string
addresses
[][]
address
// addresses per server block, in order
}{
{
`{$MY_ADDRESS}`
,
[][]
address
{
{{
"servername.com"
,
""
}},
}},
{
`{$MY_ADDRESS}:{$MY_PORT}`
,
[][]
address
{
[]
address
{{
"servername.com"
,
"8080"
}},
}},
{
`{$MY_ADDRESS2}:1234 {
}
localhost:{$MY_PORT} {
}`
,
[][]
address
{
[]
address
{{
"127.0.0.1"
,
"1234"
}},
[]
address
{{
"localhost"
,
"8080"
}},
}},
}
{
p
:=
testParser
(
test
.
input
)
blocks
,
err
:=
p
.
parseAll
()
if
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
len
(
block
.
Addresses
)
!=
len
(
test
.
addresses
[
j
])
{
t
.
Errorf
(
"Test %d: Expected %d addresses in block %d, got %d"
,
i
,
len
(
test
.
addresses
[
j
]),
j
,
len
(
block
.
Addresses
))
continue
}
for
k
,
addr
:=
range
block
.
Addresses
{
if
addr
.
Host
!=
test
.
addresses
[
j
][
k
]
.
Host
{
t
.
Errorf
(
"Test %d, block %d, address %d: Expected host to be '%s', but was '%s'"
,
i
,
j
,
k
,
test
.
addresses
[
j
][
k
]
.
Host
,
addr
.
Host
)
}
if
addr
.
Port
!=
test
.
addresses
[
j
][
k
]
.
Port
{
t
.
Errorf
(
"Test %d, block %d, address %d: Expected port to be '%s', but was '%s'"
,
i
,
j
,
k
,
test
.
addresses
[
j
][
k
]
.
Port
,
addr
.
Port
)
}
}
}
}
}
func
setupParseTests
()
{
// Set up some bogus directives for testing
ValidDirectives
=
map
[
string
]
struct
{}{
...
...
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