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
0d8384a9
Commit
0d8384a9
authored
Jan 15, 2019
by
Adam Woodbeck
Committed by
Matt Holt
Jan 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
caddyfile: Support 'import' inside directives (#2428)
parent
e14328b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
caddyfile/parse.go
caddyfile/parse.go
+6
-0
caddyfile/parse_test.go
caddyfile/parse_test.go
+62
-0
No files found.
caddyfile/parse.go
View file @
0d8384a9
...
...
@@ -365,6 +365,12 @@ func (p *parser) directive() error {
nesting
--
}
else
if
p
.
Val
()
==
"}"
&&
nesting
==
0
{
return
p
.
Err
(
"Unexpected '}' because no matching opening brace"
)
}
else
if
p
.
Val
()
==
"import"
&&
p
.
isNewLine
()
{
if
err
:=
p
.
doImport
();
err
!=
nil
{
return
err
}
p
.
cursor
--
// cursor is advanced when we continue, so roll back one more
continue
}
p
.
tokens
[
p
.
cursor
]
.
Text
=
replaceEnvVars
(
p
.
tokens
[
p
.
cursor
]
.
Text
)
p
.
block
.
Tokens
[
dir
]
=
append
(
p
.
block
.
Tokens
[
dir
],
p
.
tokens
[
p
.
cursor
])
...
...
caddyfile/parse_test.go
View file @
0d8384a9
...
...
@@ -371,6 +371,68 @@ func TestRecursiveImport(t *testing.T) {
}
}
func
TestDirectiveImport
(
t
*
testing
.
T
)
{
testParseOne
:=
func
(
input
string
)
(
ServerBlock
,
error
)
{
p
:=
testParser
(
input
)
p
.
Next
()
// parseOne doesn't call Next() to start, so we must
err
:=
p
.
parseOne
()
return
p
.
block
,
err
}
isExpected
:=
func
(
got
ServerBlock
)
bool
{
if
len
(
got
.
Keys
)
!=
1
||
got
.
Keys
[
0
]
!=
"localhost"
{
t
.
Errorf
(
"got keys unexpected: expect localhost, got %v"
,
got
.
Keys
)
return
false
}
if
len
(
got
.
Tokens
)
!=
2
{
t
.
Errorf
(
"got wrong number of tokens: expect 2, got %d"
,
len
(
got
.
Tokens
))
return
false
}
if
len
(
got
.
Tokens
[
"dir1"
])
!=
1
||
len
(
got
.
Tokens
[
"proxy"
])
!=
8
{
t
.
Errorf
(
"got unexpect tokens: %v"
,
got
.
Tokens
)
return
false
}
return
true
}
directiveFile
,
err
:=
filepath
.
Abs
(
"testdata/directive_import_test"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
ioutil
.
WriteFile
(
directiveFile
,
[]
byte
(
`prop1 1
prop2 2`
),
0644
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
os
.
Remove
(
directiveFile
)
// import from existing file
result
,
err
:=
testParseOne
(
`localhost
dir1
proxy {
import testdata/directive_import_test
transparent
}`
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
isExpected
(
result
)
{
t
.
Error
(
"directive import failed"
)
}
// import from nonexisting file
_
,
err
=
testParseOne
(
`localhost
dir1
proxy {
import testdata/nonexistent_file
transparent
}`
)
if
err
==
nil
{
t
.
Fatal
(
"expected error when importing a nonexistent file"
)
}
}
func
TestParseAll
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
[]
struct
{
input
string
...
...
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