mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
remove 'macro foo' syntax
This commit is contained in:
parent
3a969bc075
commit
dd4b3efa47
2 changed files with 25 additions and 35 deletions
|
@ -461,11 +461,7 @@ type ServerBlock struct {
|
||||||
|
|
||||||
func (p *parser) isMacro() (bool, string) {
|
func (p *parser) isMacro() (bool, string) {
|
||||||
keys := p.block.Keys
|
keys := p.block.Keys
|
||||||
// "macro foo {}" style
|
// A macro block is a single key with parens. Nothing else qualifies.
|
||||||
if len(keys) == 2 && keys[0] == "macro" {
|
|
||||||
return true, keys[1]
|
|
||||||
}
|
|
||||||
// (foo) style. What to do if more than one server key and some have ()?
|
|
||||||
if len(keys) == 1 && strings.HasPrefix(keys[0], "(") && strings.HasSuffix(keys[0], ")") {
|
if len(keys) == 1 && strings.HasPrefix(keys[0], "(") && strings.HasSuffix(keys[0], ")") {
|
||||||
return true, strings.TrimSuffix(keys[0][1:], ")")
|
return true, strings.TrimSuffix(keys[0][1:], ")")
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
package caddyfile
|
package caddyfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -517,41 +516,36 @@ func testParser(input string) parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMacro(t *testing.T) {
|
func TestMacro(t *testing.T) {
|
||||||
for _, tst := range []string{"(common)", "macro common"} {
|
p := testParser(`(common) {
|
||||||
t.Run(tst, func(t *testing.T) {
|
|
||||||
p := testParser(fmt.Sprintf(`
|
|
||||||
%s {
|
|
||||||
gzip foo
|
gzip foo
|
||||||
errors stderr
|
errors stderr
|
||||||
}
|
}
|
||||||
http://example.com {
|
http://example.com {
|
||||||
import common
|
import common
|
||||||
}
|
}
|
||||||
`, tst))
|
`)
|
||||||
blocks, err := p.parseAll()
|
blocks, err := p.parseAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
for _, b := range blocks {
|
for _, b := range blocks {
|
||||||
t.Log(b.Keys)
|
t.Log(b.Keys)
|
||||||
t.Log(b.Tokens)
|
t.Log(b.Tokens)
|
||||||
}
|
}
|
||||||
if len(blocks) != 1 {
|
if len(blocks) != 1 {
|
||||||
t.Fatalf("Expect exactly one server block. Got %d.", len(blocks))
|
t.Fatalf("Expect exactly one server block. Got %d.", len(blocks))
|
||||||
}
|
}
|
||||||
if actual, expected := blocks[0].Keys[0], "http://example.com"; expected != actual {
|
if actual, expected := blocks[0].Keys[0], "http://example.com"; expected != actual {
|
||||||
t.Errorf("Expected server name to be '%s' but was '%s'", expected, actual)
|
t.Errorf("Expected server name to be '%s' but was '%s'", expected, actual)
|
||||||
}
|
}
|
||||||
if len(blocks[0].Tokens) != 2 {
|
if len(blocks[0].Tokens) != 2 {
|
||||||
t.Fatalf("Server block should have tokens from import")
|
t.Fatalf("Server block should have tokens from import")
|
||||||
}
|
}
|
||||||
if actual, expected := blocks[0].Tokens["gzip"][0].Text, "gzip"; expected != actual {
|
if actual, expected := blocks[0].Tokens["gzip"][0].Text, "gzip"; expected != actual {
|
||||||
t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
|
t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
|
||||||
}
|
}
|
||||||
if actual, expected := blocks[0].Tokens["errors"][1].Text, "stderr"; expected != actual {
|
if actual, expected := blocks[0].Tokens["errors"][1].Text, "stderr"; expected != actual {
|
||||||
t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
|
t.Errorf("Expected argument to be '%s' but was '%s'", expected, actual)
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue