diff --git a/command/snapshot/inspect/formatter_test.go b/command/snapshot/inspect/formatter_test.go index ec02a21a25..428995a27c 100644 --- a/command/snapshot/inspect/formatter_test.go +++ b/command/snapshot/inspect/formatter_test.go @@ -31,7 +31,6 @@ func TestFormat(t *testing.T) { TotalSize: 1, TotalSizeKV: 1, } - detailed := false formatters := map[string]Formatter{ "pretty": newPrettyFormatter(), @@ -41,7 +40,7 @@ func TestFormat(t *testing.T) { for fmtName, formatter := range formatters { t.Run(fmtName, func(t *testing.T) { - actual, err := formatter.Format(&info, detailed) + actual, err := formatter.Format(&info) require.NoError(t, err) gName := fmt.Sprintf("%s", fmtName) diff --git a/command/snapshot/inspect/snapshot_inspect_test.go b/command/snapshot/inspect/snapshot_inspect_test.go index 5e5c745533..db23dc9de5 100644 --- a/command/snapshot/inspect/snapshot_inspect_test.go +++ b/command/snapshot/inspect/snapshot_inspect_test.go @@ -96,14 +96,14 @@ func TestSnapshotInspectCommand(t *testing.T) { require.Equal(t, want, ui.OutputWriter.String()) } -func TestSnapshotInspectDetailedCommand(t *testing.T) { +func TestSnapshotInspectKVDetailsCommand(t *testing.T) { - filepath := "./testdata/backup-with-kv.snap" + filepath := "./testdata/backupWithKV.snap" // Inspect the snapshot ui := cli.NewMockUi() c := New(ui) - args := []string{"-detailed", filepath} + args := []string{"-kvdetails", filepath} code := c.Run(args) if code != 0 { @@ -114,14 +114,14 @@ func TestSnapshotInspectDetailedCommand(t *testing.T) { require.Equal(t, want, ui.OutputWriter.String()) } -func TestSnapshotInspectDetailedDepthCommand(t *testing.T) { +func TestSnapshotInspectKVDetailsDepthCommand(t *testing.T) { - filepath := "./testdata/backup-with-kv.snap" + filepath := "./testdata/backupWithKV.snap" // Inspect the snapshot ui := cli.NewMockUi() c := New(ui) - args := []string{"-detailed", "-depth", "3", filepath} + args := []string{"-kvdetails", "-kvdepth", "3", filepath} code := c.Run(args) if code != 0 { @@ -132,14 +132,32 @@ func TestSnapshotInspectDetailedDepthCommand(t *testing.T) { require.Equal(t, want, ui.OutputWriter.String()) } -func TestSnapshotInspectDetailedDepthFilterCommand(t *testing.T) { +func TestSnapshotInspectKVDetailsDepthFilterCommand(t *testing.T) { - filepath := "./testdata/backup-with-kv.snap" + filepath := "./testdata/backupWithKV.snap" // Inspect the snapshot ui := cli.NewMockUi() c := New(ui) - args := []string{"-detailed", "-depth", "3", "-filter", "vault/logical", filepath} + args := []string{"-kvdetails", "-kvdepth", "3", "-kvfilter", "vault/logical", filepath} + + code := c.Run(args) + if code != 0 { + t.Fatalf("bad: %d. %#v", code, ui.ErrorWriter.String()) + } + + want := golden(t, t.Name(), ui.OutputWriter.String()) + require.Equal(t, want, ui.OutputWriter.String()) +} + +func TestSnapshotInspectKVDetailsCommandNoDetailsFlag(t *testing.T) { + + filepath := "./testdata/backupWithKV.snap" + + // Inspect the snapshot + ui := cli.NewMockUi() + c := New(ui) + args := []string{"-kvdepth", "3", filepath} code := c.Run(args) if code != 0 { diff --git a/command/snapshot/inspect/testdata/TestSnapshotInspectDetailedCommand.golden b/command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsCommand.golden similarity index 100% rename from command/snapshot/inspect/testdata/TestSnapshotInspectDetailedCommand.golden rename to command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsCommand.golden diff --git a/command/snapshot/inspect/testdata/TestSnapshotInspectDetailedDepthCommand.golden b/command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsCommandNoDetailsFlag.golden similarity index 100% rename from command/snapshot/inspect/testdata/TestSnapshotInspectDetailedDepthCommand.golden rename to command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsCommandNoDetailsFlag.golden index 61e9108535..a962bd27bb 100644 --- a/command/snapshot/inspect/testdata/TestSnapshotInspectDetailedDepthCommand.golden +++ b/command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsCommandNoDetailsFlag.golden @@ -9,8 +9,8 @@ KVS 27 12.3KB Register 5 3.4KB Index 11 285B - Session 1 199B Autopilot 1 199B + Session 1 199B CoordinateBatchUpdate 1 166B Tombstone 2 146B FederationState 1 139B diff --git a/command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsDepthCommand.golden b/command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsDepthCommand.golden new file mode 100644 index 0000000000..a962bd27bb --- /dev/null +++ b/command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsDepthCommand.golden @@ -0,0 +1,44 @@ + ID 2-12426-1604593650375 + Size 17228 + Index 12426 + Term 2 + Version 1 + + Type Count Size + ---- ---- ---- + KVS 27 12.3KB + Register 5 3.4KB + Index 11 285B + Autopilot 1 199B + Session 1 199B + CoordinateBatchUpdate 1 166B + Tombstone 2 146B + FederationState 1 139B + ChunkingState 1 12B + ---- ---- ---- + Total 16.8KB + + Key Name Count Size + ---- ---- ---- + vault/sys/policy 3 3.3KB + vault/logical/0989e79e-06cd-5374-c8c0-4c6d675bc1c9 3 1.8KB + vault/core/leader 1 1.6KB + vault/sys/token 3 1KB + vault/core/mounts 1 675B + vault/core/wrapping 1 633B + vault/core/local-mounts 1 450B + vault/core/auth 1 423B + vault/core/cluster 2 388B + vault/core/keyring 1 320B + vault/core/master 1 237B + vault/core/seal-config 1 211B + vault/logical/5c018b68-3573-41d3-0c33-04bce60cd6b0 1 210B + vault/core/hsm 1 189B + vault/core/local-audit 1 185B + vault/core/local-auth 1 183B + vault/core/audit 1 179B + vault/core/lock 1 170B + vault/core/shamir-kek 1 159B + vault/sys/counters 1 155B + ---- ---- ---- + Total 12.3KB diff --git a/command/snapshot/inspect/testdata/TestSnapshotInspectDetailedDepthFilterCommand.golden b/command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsDepthFilterCommand.golden similarity index 100% rename from command/snapshot/inspect/testdata/TestSnapshotInspectDetailedDepthFilterCommand.golden rename to command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsDepthFilterCommand.golden index a72fb99b52..881a10cfcd 100644 --- a/command/snapshot/inspect/testdata/TestSnapshotInspectDetailedDepthFilterCommand.golden +++ b/command/snapshot/inspect/testdata/TestSnapshotInspectKVDetailsDepthFilterCommand.golden @@ -9,8 +9,8 @@ KVS 27 12.3KB Register 5 3.4KB Index 11 285B - Session 1 199B Autopilot 1 199B + Session 1 199B CoordinateBatchUpdate 1 166B Tombstone 2 146B FederationState 1 139B diff --git a/command/snapshot/inspect/testdata/backup-with-kv.snap b/command/snapshot/inspect/testdata/backupWithKV.snap similarity index 100% rename from command/snapshot/inspect/testdata/backup-with-kv.snap rename to command/snapshot/inspect/testdata/backupWithKV.snap diff --git a/command/snapshot/inspect/testdata/json.golden b/command/snapshot/inspect/testdata/json.golden index 42c3ba40b4..261d3d8b27 100644 --- a/command/snapshot/inspect/testdata/json.golden +++ b/command/snapshot/inspect/testdata/json.golden @@ -13,5 +13,13 @@ "Count": 2 } ], - "TotalSize": 1 + "StatsKV": [ + { + "Name": "msgKV", + "Sum": 1, + "Count": 2 + } + ], + "TotalSize": 1, + "TotalSizeKV": 1 } \ No newline at end of file diff --git a/command/snapshot/inspect/testdata/pretty.golden b/command/snapshot/inspect/testdata/pretty.golden index 7a2c5749b3..2a8d028ff4 100644 --- a/command/snapshot/inspect/testdata/pretty.golden +++ b/command/snapshot/inspect/testdata/pretty.golden @@ -8,4 +8,10 @@ ---- ---- ---- msg 2 1B ---- ---- ---- - Total 1B \ No newline at end of file + Total 1B + + Key Name Count Size + ---- ---- ---- + msgKV 2 1B + ---- ---- ---- + Total 1B \ No newline at end of file