Fix panic bug in snapshot inspect (#10091)
* Fix panic bug in snapshot inspect * Add changelog entry * Update .changelog/10091.txt * Undo bad GitHub UI merge * Undo bad GitHub UI merge
This commit is contained in:
parent
6924586874
commit
bbe0d6aa30
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:bug
|
||||||
|
cli: snapshot inspect command would panic on invalid input.
|
||||||
|
```
|
|
@ -139,6 +139,7 @@ func (c *cmd) Run(args []string) int {
|
||||||
readFile, meta, err = snapshot.Read(hclog.New(nil), f)
|
readFile, meta, err = snapshot.Read(hclog.New(nil), f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.UI.Error(fmt.Sprintf("Error reading snapshot: %s", err))
|
c.UI.Error(fmt.Sprintf("Error reading snapshot: %s", err))
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := readFile.Close(); err != nil {
|
if err := readFile.Close(); err != nil {
|
||||||
|
|
|
@ -153,10 +153,8 @@ func TestSnapshotInspectKVDetailsDepthFilterCommand(t *testing.T) {
|
||||||
// TestSnapshotInspectCommandRaw test reading a snaphost directly from a raft
|
// TestSnapshotInspectCommandRaw test reading a snaphost directly from a raft
|
||||||
// data dir.
|
// data dir.
|
||||||
func TestSnapshotInspectCommandRaw(t *testing.T) {
|
func TestSnapshotInspectCommandRaw(t *testing.T) {
|
||||||
|
|
||||||
filepath := "./testdata/raw/state.bin"
|
filepath := "./testdata/raw/state.bin"
|
||||||
|
|
||||||
// Inspect the snapshot
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
c := New(ui)
|
c := New(ui)
|
||||||
args := []string{filepath}
|
args := []string{filepath}
|
||||||
|
@ -169,3 +167,20 @@ func TestSnapshotInspectCommandRaw(t *testing.T) {
|
||||||
want := golden(t, t.Name(), ui.OutputWriter.String())
|
want := golden(t, t.Name(), ui.OutputWriter.String())
|
||||||
require.Equal(t, want, ui.OutputWriter.String())
|
require.Equal(t, want, ui.OutputWriter.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSnapshotInspectInvalidFile(t *testing.T) {
|
||||||
|
// Attempt to open a non-snapshot file.
|
||||||
|
filepath := "./testdata/TestSnapshotInspectCommand.golden"
|
||||||
|
|
||||||
|
// Inspect the snapshot
|
||||||
|
ui := cli.NewMockUi()
|
||||||
|
c := New(ui)
|
||||||
|
args := []string{filepath}
|
||||||
|
|
||||||
|
code := c.Run(args)
|
||||||
|
// Just check it was an error code returned and not a panic - originally this
|
||||||
|
// would panic.
|
||||||
|
if code == 0 {
|
||||||
|
t.Fatalf("should return an error code")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue