e2e: test 'physical' flag in compact cmd

This commit is contained in:
Gyu-Ho Lee 2016-06-27 11:50:50 -07:00
parent 76e2bf03b8
commit f63e6875bd
3 changed files with 18 additions and 6 deletions

View File

@ -20,10 +20,12 @@ import (
"testing" "testing"
) )
func TestCtlV3Compact(t *testing.T) { testCtl(t, compactTest) } func TestCtlV3Compact(t *testing.T) { testCtl(t, compactTest) }
func TestCtlV3CompactPhysical(t *testing.T) { testCtl(t, compactTest, withCompactPhysical()) }
func compactTest(cx ctlCtx) { func compactTest(cx ctlCtx) {
if err := ctlV3Compact(cx, 2); err != nil { compactPhysical := cx.compactPhysical
if err := ctlV3Compact(cx, 2, compactPhysical); err != nil {
if !strings.Contains(err.Error(), "required revision is a future revision") { if !strings.Contains(err.Error(), "required revision is a future revision") {
cx.t.Fatal(err) cx.t.Fatal(err)
} }
@ -42,7 +44,7 @@ func compactTest(cx ctlCtx) {
cx.t.Errorf("compactTest: ctlV3Get error (%v)", err) cx.t.Errorf("compactTest: ctlV3Get error (%v)", err)
} }
if err := ctlV3Compact(cx, 4); err != nil { if err := ctlV3Compact(cx, 4, compactPhysical); err != nil {
cx.t.Fatal(err) cx.t.Fatal(err)
} }
@ -54,7 +56,7 @@ func compactTest(cx ctlCtx) {
cx.t.Fatalf("expected '...has been compacted' error, got <nil>") cx.t.Fatalf("expected '...has been compacted' error, got <nil>")
} }
if err := ctlV3Compact(cx, 2); err != nil { if err := ctlV3Compact(cx, 2, compactPhysical); err != nil {
if !strings.Contains(err.Error(), "required revision has been compacted") { if !strings.Contains(err.Error(), "required revision has been compacted") {
cx.t.Fatal(err) cx.t.Fatal(err)
} }
@ -63,8 +65,11 @@ func compactTest(cx ctlCtx) {
} }
} }
func ctlV3Compact(cx ctlCtx, rev int64) error { func ctlV3Compact(cx ctlCtx, rev int64, physical bool) error {
rs := strconv.FormatInt(rev, 10) rs := strconv.FormatInt(rev, 10)
cmdArgs := append(cx.PrefixArgs(), "compact", rs) cmdArgs := append(cx.PrefixArgs(), "compact", rs)
if physical {
cmdArgs = append(cmdArgs, "--physical")
}
return spawnWithExpect(cmdArgs, "compacted revision "+rs) return spawnWithExpect(cmdArgs, "compacted revision "+rs)
} }

View File

@ -26,7 +26,7 @@ func defragTest(cx ctlCtx) {
} }
} }
if err := ctlV3Compact(cx, 4); err != nil { if err := ctlV3Compact(cx, 4, cx.compactPhysical); err != nil {
cx.t.Fatal(err) cx.t.Fatal(err)
} }

View File

@ -51,6 +51,9 @@ type ctlCtx struct {
user string user string
pass string pass string
// for compaction
compactPhysical bool
} }
type ctlOption func(*ctlCtx) type ctlOption func(*ctlCtx)
@ -81,6 +84,10 @@ func withQuota(b int64) ctlOption {
return func(cx *ctlCtx) { cx.quotaBackendBytes = b } return func(cx *ctlCtx) { cx.quotaBackendBytes = b }
} }
func withCompactPhysical() ctlOption {
return func(cx *ctlCtx) { cx.compactPhysical = true }
}
func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) { func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
defer testutil.AfterTest(t) defer testutil.AfterTest(t)