Improved test

This commit is contained in:
Francis Lavoie 2024-10-20 10:00:55 -04:00
parent c60341e51f
commit 8328e4b5e4
No known key found for this signature in database
GPG Key ID: 52BC55A211F19186
2 changed files with 18 additions and 3 deletions

View File

@ -289,6 +289,7 @@ var expressionTests = []struct {
wantErr bool
wantResult bool
clientCertificate []byte
expectedPath string
}{
{
name: "file error no args (MatchFile)",
@ -357,10 +358,11 @@ var expressionTests = []struct {
{
name: "file match long pattern foo.txt with try_policy (MatchFile)",
expression: &caddyhttp.MatchExpression{
Expr: `file({"try_policy": "most_recently_modified"})`,
Expr: `file({"root": "./testdata", "try_policy": "largest_size", "try_files": ["foo.txt", "large.txt"]})`,
},
urlTarget: "https://example.com/foo.txt",
wantResult: true,
urlTarget: "https://example.com/",
wantResult: true,
expectedPath: "/large.txt",
},
}
@ -390,6 +392,16 @@ func TestMatchExpressionMatch(t *testing.T) {
if tc.expression.Match(req) != tc.wantResult {
t.Errorf("MatchExpression.Match() expected to return '%t', for expression : '%s'", tc.wantResult, tc.expression.Expr)
}
if tc.expectedPath != "" {
path, ok := repl.Get("http.matchers.file.relative")
if !ok {
t.Errorf("MatchExpression.Match() expected to return path '%s', but got none", tc.expectedPath)
}
if path != tc.expectedPath {
t.Errorf("MatchExpression.Match() expected to return path '%s', but got '%s'", tc.expectedPath, path)
}
}
})
}
}

View File

@ -0,0 +1,3 @@
This is a file with more content than the other files in this directory
such that tests using the largest_size policy pick this file, or the
smallest_size policy avoids this file.