@@ -289,6 +289,7 @@ var expressionTests = []struct {
289289 wantErr bool
290290 wantResult bool
291291 clientCertificate []byte
292+ expectedPath string
292293}{
293294 {
294295 name : "file error no args (MatchFile)" ,
@@ -354,6 +355,15 @@ var expressionTests = []struct {
354355 urlTarget : "https://example.com/nopenope.txt" ,
355356 wantResult : false ,
356357 },
358+ {
359+ name : "file match long pattern foo.txt with try_policy (MatchFile)" ,
360+ expression : & caddyhttp.MatchExpression {
361+ Expr : `file({"root": "./testdata", "try_policy": "largest_size", "try_files": ["foo.txt", "large.txt"]})` ,
362+ },
363+ urlTarget : "https://example.com/" ,
364+ wantResult : true ,
365+ expectedPath : "/large.txt" ,
366+ },
357367}
358368
359369func TestMatchExpressionMatch (t * testing.T ) {
@@ -382,6 +392,16 @@ func TestMatchExpressionMatch(t *testing.T) {
382392 if tc .expression .Match (req ) != tc .wantResult {
383393 t .Errorf ("MatchExpression.Match() expected to return '%t', for expression : '%s'" , tc .wantResult , tc .expression .Expr )
384394 }
395+
396+ if tc .expectedPath != "" {
397+ path , ok := repl .Get ("http.matchers.file.relative" )
398+ if ! ok {
399+ t .Errorf ("MatchExpression.Match() expected to return path '%s', but got none" , tc .expectedPath )
400+ }
401+ if path != tc .expectedPath {
402+ t .Errorf ("MatchExpression.Match() expected to return path '%s', but got '%s'" , tc .expectedPath , path )
403+ }
404+ }
385405 })
386406 }
387407}
0 commit comments