mirror of
https://github.com/caddyserver/caddy.git
synced 2025-04-19 18:58:50 +08:00
Improved test
This commit is contained in:
parent
c60341e51f
commit
8328e4b5e4
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
3
modules/caddyhttp/fileserver/testdata/large.txt
vendored
Normal file
3
modules/caddyhttp/fileserver/testdata/large.txt
vendored
Normal 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.
|
Loading…
x
Reference in New Issue
Block a user