@@ -289,6 +289,7 @@ var expressionTests = []struct {
289
289
wantErr bool
290
290
wantResult bool
291
291
clientCertificate []byte
292
+ expectedPath string
292
293
}{
293
294
{
294
295
name : "file error no args (MatchFile)" ,
@@ -354,6 +355,15 @@ var expressionTests = []struct {
354
355
urlTarget : "https://example.com/nopenope.txt" ,
355
356
wantResult : false ,
356
357
},
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
+ },
357
367
}
358
368
359
369
func TestMatchExpressionMatch (t * testing.T ) {
@@ -382,6 +392,16 @@ func TestMatchExpressionMatch(t *testing.T) {
382
392
if tc .expression .Match (req ) != tc .wantResult {
383
393
t .Errorf ("MatchExpression.Match() expected to return '%t', for expression : '%s'" , tc .wantResult , tc .expression .Expr )
384
394
}
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
+ }
385
405
})
386
406
}
387
407
}
0 commit comments