mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-01 00:23:48 +03:00
Merge pull request #898 from abiosoft/master
Fix missed if_op refactor. Ensure with tests.
This commit is contained in:
commit
9ca87cd139
2 changed files with 23 additions and 2 deletions
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/mholt/caddy/caddyfile"
|
||||
)
|
||||
|
||||
// SetupIfMatcher parses `if` or `if_type` in the current dispenser block.
|
||||
// SetupIfMatcher parses `if` or `if_op` in the current dispenser block.
|
||||
// It returns a RequestMatcher and an error if any.
|
||||
func SetupIfMatcher(c caddyfile.Dispenser) (RequestMatcher, error) {
|
||||
var matcher IfMatcher
|
||||
|
@ -195,5 +195,5 @@ func (m IfMatcher) Or(r *http.Request) bool {
|
|||
|
||||
// IfMatcherKeyword returns if k is a keyword for 'if' config block.
|
||||
func IfMatcherKeyword(k string) bool {
|
||||
return k == "if" || k == "if_cond"
|
||||
return k == "if" || k == "if_op"
|
||||
}
|
||||
|
|
|
@ -263,3 +263,24 @@ func TestSetupIfMatcher(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIfMatcherKeyword(t *testing.T) {
|
||||
tests := []struct {
|
||||
keyword string
|
||||
expected bool
|
||||
}{
|
||||
{"if", true},
|
||||
{"ifs", false},
|
||||
{"tls", false},
|
||||
{"http", false},
|
||||
{"if_op", true},
|
||||
{"if_type", false},
|
||||
{"if_cond", false},
|
||||
}
|
||||
for i, test := range tests {
|
||||
valid := IfMatcherKeyword(test.keyword)
|
||||
if valid != test.expected {
|
||||
t.Errorf("Test %d: expected %v found %v", i, test.expected, valid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue