Merge pull request #10363 from johncming/embed

embed: add test cases in TestAutoCompactionModeParse.
This commit is contained in:
Xiang Li 2019-01-03 10:49:51 -08:00 committed by GitHub
commit 3a5868a7b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ import (
"net/url"
"os"
"testing"
"time"
"go.etcd.io/etcd/pkg/transport"
@ -167,11 +168,35 @@ func TestAutoCompactionModeInvalid(t *testing.T) {
}
func TestAutoCompactionModeParse(t *testing.T) {
dur, err := parseCompactionRetention("revision", "1")
if err != nil {
t.Error(err)
tests := []struct {
mode string
retention string
werr bool
wdur time.Duration
}{
// revision
{"revision", "1", false, 1},
{"revision", "1h", false, time.Hour},
{"revision", "a", true, 0},
// periodic
{"periodic", "1", false, time.Hour},
{"periodic", "a", true, 0},
// err mode
{"errmode", "1", false, 0},
{"errmode", "1h", false, time.Hour},
}
if dur != 1 {
t.Fatalf("AutoCompactionRetention expected 1, got %d", dur)
hasErr := func(err error) bool {
return err != nil
}
for i, tt := range tests {
dur, err := parseCompactionRetention(tt.mode, tt.retention)
if hasErr(err) != tt.werr {
t.Errorf("#%d: err = %v, want %v", i, err, tt.werr)
}
if dur != tt.wdur {
t.Errorf("#%d: duration = %s, want %s", i, dur, tt.wdur)
}
}
}