Add a serve_stale option for plugin/cache (#3468)
Automatically submitted.
This commit is contained in:
parent
24176a97e6
commit
b4df2d0d4c
6 changed files with 166 additions and 15 deletions
37
plugin/cache/setup_test.go
vendored
37
plugin/cache/setup_test.go
vendored
|
@ -1,6 +1,7 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -113,3 +114,39 @@ func TestSetup(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeStale(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
shouldErr bool
|
||||
staleUpTo time.Duration
|
||||
}{
|
||||
{"serve_stale", false, 1 * time.Hour},
|
||||
{"serve_stale 20m", false, 20 * time.Minute},
|
||||
{"serve_stale 1h20m", false, 80 * time.Minute},
|
||||
{"serve_stale 0m", false, 0},
|
||||
{"serve_stale 0", false, 0},
|
||||
// fails
|
||||
{"serve_stale 20", true, 0},
|
||||
{"serve_stale -20m", true, 0},
|
||||
{"serve_stale aa", true, 0},
|
||||
{"serve_stale 1m nono", true, 0},
|
||||
}
|
||||
for i, test := range tests {
|
||||
c := caddy.NewTestController("dns", fmt.Sprintf("cache {\n%s\n}", test.input))
|
||||
ca, err := cacheParse(c)
|
||||
if test.shouldErr && err == nil {
|
||||
t.Errorf("Test %v: Expected error but found nil", i)
|
||||
continue
|
||||
} else if !test.shouldErr && err != nil {
|
||||
t.Errorf("Test %v: Expected no error but found error: %v", i, err)
|
||||
continue
|
||||
}
|
||||
if test.shouldErr && err != nil {
|
||||
continue
|
||||
}
|
||||
if ca.staleUpTo != test.staleUpTo {
|
||||
t.Errorf("Test %v: Expected stale %v but found: %v", i, test.staleUpTo, ca.staleUpTo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue