Commit cad9b3f6 authored by Abiola Ibrahim's avatar Abiola Ibrahim

Fix missed if_op refactor. Ensure with tests.

parent e585a741
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/mholt/caddy/caddyfile" "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. // It returns a RequestMatcher and an error if any.
func SetupIfMatcher(c caddyfile.Dispenser) (RequestMatcher, error) { func SetupIfMatcher(c caddyfile.Dispenser) (RequestMatcher, error) {
var matcher IfMatcher var matcher IfMatcher
...@@ -195,5 +195,5 @@ func (m IfMatcher) Or(r *http.Request) bool { ...@@ -195,5 +195,5 @@ func (m IfMatcher) Or(r *http.Request) bool {
// IfMatcherKeyword returns if k is a keyword for 'if' config block. // IfMatcherKeyword returns if k is a keyword for 'if' config block.
func IfMatcherKeyword(k string) bool { 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) { ...@@ -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)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment